refactor(core): replace bash tool with shell tool
This commit is contained in:
parent
595c6bd4a7
commit
5ae93092aa
37 changed files with 2260 additions and 901 deletions
|
|
@ -21,6 +21,7 @@ import { Question } from "./question"
|
|||
import { QuestionV1 } from "./question-v1"
|
||||
import { Reference } from "./reference"
|
||||
import { ServerEvent } from "./server-event"
|
||||
import { Shell } from "./shell"
|
||||
import { SessionCompactionEvent } from "./session-compaction-event"
|
||||
import { SessionEvent } from "./session-event"
|
||||
import { SessionStatusEvent } from "./session-status-event"
|
||||
|
|
@ -51,6 +52,7 @@ const featureDefinitions = Event.inventory(
|
|||
...ProjectDirectories.Event.Definitions,
|
||||
...FileSystemWatcher.Event.Definitions,
|
||||
...Pty.Event.Definitions,
|
||||
...Shell.Event.Definitions,
|
||||
...Question.Event.Definitions,
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ export { Revert } from "./revert"
|
|||
export { Session } from "./session"
|
||||
export { SessionInput } from "./session-input"
|
||||
export { SessionMessage } from "./session-message"
|
||||
export { Shell } from "./shell"
|
||||
export { Skill } from "./skill"
|
||||
export { Pty } from "./pty"
|
||||
export { PtyTicket } from "./pty-ticket"
|
||||
|
|
|
|||
79
packages/schema/src/shell.ts
Normal file
79
packages/schema/src/shell.ts
Normal file
|
|
@ -0,0 +1,79 @@
|
|||
export * as Shell from "./shell"
|
||||
|
||||
import { Schema } from "effect"
|
||||
import { optional } from "./schema"
|
||||
import { define, inventory } from "./event"
|
||||
import { ascending } from "./identifier"
|
||||
import { NonNegativeInt, statics } from "./schema"
|
||||
|
||||
const IDSchema = Schema.String.check(Schema.isStartsWith("sh_")).pipe(Schema.brand("ShellID"))
|
||||
|
||||
export const ID = IDSchema.pipe(
|
||||
statics((schema: typeof IDSchema) => {
|
||||
const create = () => schema.make("sh_" + ascending())
|
||||
return {
|
||||
create,
|
||||
ascending: (id?: string) => (id === undefined ? create() : schema.make(id)),
|
||||
}
|
||||
}),
|
||||
)
|
||||
export type ID = typeof ID.Type
|
||||
|
||||
export const Status = Schema.Literals(["running", "exited", "timeout", "killed"])
|
||||
export type Status = typeof Status.Type
|
||||
|
||||
export const Time = Schema.Struct({
|
||||
started: Schema.Number,
|
||||
completed: optional(Schema.Number),
|
||||
})
|
||||
export interface Time extends Schema.Schema.Type<typeof Time> {}
|
||||
|
||||
// Opaque caller-supplied tags echoed back on Info and events. The Shell service never interprets
|
||||
// these; callers (e.g. ShellTool stores the originating session ID) use them to filter or correlate.
|
||||
export const Metadata = Schema.Record(Schema.String, Schema.Unknown)
|
||||
export type Metadata = typeof Metadata.Type
|
||||
|
||||
export const Info = Schema.Struct({
|
||||
id: ID,
|
||||
status: Status,
|
||||
command: Schema.String,
|
||||
cwd: Schema.String,
|
||||
shell: Schema.String,
|
||||
// Absolute path of the file capturing combined stdout/stderr. Page through it via `output`.
|
||||
file: Schema.String,
|
||||
pid: optional(NonNegativeInt),
|
||||
exit: optional(Schema.Number),
|
||||
// Always present; defaults to an empty object when the creator supplies no metadata.
|
||||
metadata: Metadata,
|
||||
time: Time,
|
||||
}).annotate({ identifier: "Shell" })
|
||||
export interface Info extends Schema.Schema.Type<typeof Info> {}
|
||||
|
||||
const Created = define({ type: "shell.created", schema: { info: Info } })
|
||||
const Exited = define({ type: "shell.exited", schema: { id: ID, exit: optional(Schema.Number), status: Status } })
|
||||
const Deleted = define({ type: "shell.deleted", schema: { id: ID } })
|
||||
export const Event = { Created, Exited, Deleted, Definitions: inventory(Created, Exited, Deleted) }
|
||||
|
||||
export const CreateInput = Schema.Struct({
|
||||
command: Schema.String,
|
||||
cwd: optional(Schema.String),
|
||||
timeout: optional(NonNegativeInt),
|
||||
metadata: optional(Metadata),
|
||||
})
|
||||
export interface CreateInput extends Schema.Schema.Type<typeof CreateInput> {}
|
||||
|
||||
export const OutputInput = Schema.Struct({
|
||||
cursor: optional(NonNegativeInt),
|
||||
limit: optional(NonNegativeInt),
|
||||
})
|
||||
export interface OutputInput extends Schema.Schema.Type<typeof OutputInput> {}
|
||||
|
||||
export const Output = Schema.Struct({
|
||||
output: Schema.String,
|
||||
// Absolute cursor after this page. Equals `size` once fully caught up.
|
||||
cursor: NonNegativeInt,
|
||||
// Total bytes captured so far. A consumer has more to page while `cursor < size`.
|
||||
size: NonNegativeInt,
|
||||
truncated: Schema.Boolean,
|
||||
})
|
||||
export interface Output extends Schema.Schema.Type<typeof Output> {}
|
||||
Loading…
Add table
Add a link
Reference in a new issue