@zyro-sec/schema 1.0.1 → 1.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (136) hide show
  1. package/AGENTS.md +95 -95
  2. package/package.json +5 -1
  3. package/script/build.ts +9 -9
  4. package/script/config-schema.ts +86 -86
  5. package/script/config-v1.json +1311 -1311
  6. package/script/pack.ts +5 -5
  7. package/src/agent.ts +68 -68
  8. package/src/artifact.ts +81 -81
  9. package/src/automation.ts +224 -224
  10. package/src/blob-store.ts +25 -25
  11. package/src/command.ts +18 -18
  12. package/src/config/agent.ts +26 -26
  13. package/src/config/command.ts +14 -14
  14. package/src/config/compaction.ts +27 -27
  15. package/src/config/experimental.ts +72 -72
  16. package/src/config/flag.ts +39 -39
  17. package/src/config/formatter.ts +13 -13
  18. package/src/config/lsp.ts +19 -19
  19. package/src/config/mcp.ts +22 -22
  20. package/src/config/media.ts +15 -15
  21. package/src/config/model.ts +37 -37
  22. package/src/config/plugin.ts +14 -14
  23. package/src/config/policy.ts +57 -57
  24. package/src/config/provider.ts +122 -122
  25. package/src/config/reference.ts +23 -23
  26. package/src/config/shell.ts +10 -10
  27. package/src/config/tool-output.ts +9 -9
  28. package/src/config/warming.ts +21 -21
  29. package/src/config/watcher.ts +8 -8
  30. package/src/config/websearch.ts +17 -17
  31. package/src/config/worktree.ts +10 -10
  32. package/src/config.ts +149 -149
  33. package/src/connection.ts +38 -38
  34. package/src/credential-legacy.ts +29 -29
  35. package/src/credential.ts +78 -78
  36. package/src/durable-event-manifest.ts +7 -7
  37. package/src/event-log.ts +21 -21
  38. package/src/event-manifest.ts +108 -108
  39. package/src/event.ts +205 -205
  40. package/src/file-diff.ts +25 -25
  41. package/src/filesystem-v1.ts +1 -1
  42. package/src/filesystem.ts +48 -48
  43. package/src/form.ts +177 -177
  44. package/src/generate.ts +292 -292
  45. package/src/goal.ts +46 -46
  46. package/src/identifier.ts +32 -32
  47. package/src/index.ts +51 -51
  48. package/src/installation-event.ts +20 -20
  49. package/src/instruction-entry.ts +40 -40
  50. package/src/instruction.ts +25 -25
  51. package/src/integration-id.ts +13 -13
  52. package/src/integration.ts +129 -129
  53. package/src/job.ts +79 -79
  54. package/src/legacy-event.ts +1 -1
  55. package/src/llm.ts +6 -6
  56. package/src/location-event.ts +8 -8
  57. package/src/location.ts +36 -36
  58. package/src/lsp-event.ts +7 -7
  59. package/src/mcp-event.ts +63 -63
  60. package/src/mcp.ts +171 -171
  61. package/src/model-compatibility.ts +55 -55
  62. package/src/model.ts +176 -176
  63. package/src/models-dev.ts +9 -9
  64. package/src/money.ts +18 -18
  65. package/src/permission-saved.ts +25 -25
  66. package/src/permission-v1.ts +1 -1
  67. package/src/permission.ts +67 -67
  68. package/src/persistent-pty.ts +73 -73
  69. package/src/plugin.ts +62 -62
  70. package/src/project-id.ts +9 -9
  71. package/src/project.ts +62 -62
  72. package/src/prompt-input.ts +33 -33
  73. package/src/prompt.ts +117 -117
  74. package/src/provider.ts +136 -136
  75. package/src/pty-ticket.ts +10 -10
  76. package/src/pty.ts +61 -61
  77. package/src/push.ts +86 -86
  78. package/src/question.ts +22 -22
  79. package/src/reference.ts +40 -40
  80. package/src/rpc.ts +167 -167
  81. package/src/schema.ts +41 -41
  82. package/src/server-event.ts +8 -8
  83. package/src/session-error.ts +14 -14
  84. package/src/session-event.ts +739 -739
  85. package/src/session-fork.ts +10 -10
  86. package/src/session-id.ts +12 -12
  87. package/src/session-inbox.ts +102 -102
  88. package/src/session-legacy.ts +117 -117
  89. package/src/session-message.ts +352 -352
  90. package/src/session-metadata.ts +11 -11
  91. package/src/session-revert.ts +86 -86
  92. package/src/session-stats.ts +68 -68
  93. package/src/session-status-event.ts +53 -53
  94. package/src/session-transfer.ts +11 -11
  95. package/src/session-v1.ts +1 -1
  96. package/src/session.ts +147 -147
  97. package/src/shell.ts +90 -90
  98. package/src/skill.ts +68 -68
  99. package/src/snapshot.ts +6 -6
  100. package/src/token-usage.ts +18 -18
  101. package/src/tool.ts +143 -143
  102. package/src/tui-event.ts +59 -59
  103. package/src/usage-limits.ts +76 -76
  104. package/src/v1/filesystem.ts +11 -11
  105. package/src/v1/legacy-event.ts +18 -18
  106. package/src/v1/permission.ts +66 -66
  107. package/src/v1/session.ts +667 -667
  108. package/src/vcs-event.ts +14 -14
  109. package/src/vcs.ts +41 -41
  110. package/src/websearch.ts +44 -44
  111. package/src/workspace-event.ts +32 -32
  112. package/src/workspace-id.ts +19 -19
  113. package/src/workspace.ts +20 -20
  114. package/src/worktree-event.ts +22 -22
  115. package/src/worktree.ts +109 -109
  116. package/tsconfig.build.json +11 -11
  117. package/tsconfig.json +14 -14
  118. package/test/agent.test.ts +0 -10
  119. package/test/automation.test.ts +0 -48
  120. package/test/compatibility.test.ts +0 -10
  121. package/test/config.test.ts +0 -194
  122. package/test/contract-hygiene.test.ts +0 -352
  123. package/test/credential-legacy.test.ts +0 -55
  124. package/test/event-manifest.test.ts +0 -228
  125. package/test/event.test.ts +0 -52
  126. package/test/legacy-event.test.ts +0 -46
  127. package/test/mcp.test.ts +0 -37
  128. package/test/model.test.ts +0 -104
  129. package/test/session-cursor.test.ts +0 -16
  130. package/test/session-error.test.ts +0 -51
  131. package/test/session-legacy.test.ts +0 -178
  132. package/test/session-terminal.test.ts +0 -50
  133. package/test/token-usage.test.ts +0 -18
  134. package/test/v1-isolation.test.ts +0 -26
  135. package/test/vcs.test.ts +0 -23
  136. package/test/worktree.test.ts +0 -45
package/src/session.ts CHANGED
@@ -1,147 +1,147 @@
1
- export * as Session from "./session.js"
2
-
3
- import { Effect, Result, Schema, SchemaGetter, SchemaParser } from "effect"
4
- import { Base64Url } from "effect/encoding"
5
- import { Agent } from "./agent.js"
6
- import { Location } from "./location.js"
7
- import { Model } from "./model.js"
8
- import { Project } from "./project.js"
9
- import { AbsolutePath, DateTimeUtcFromMillis, optional, RelativePath, statics } from "./schema.js"
10
- import { SessionEvent } from "./session-event.js"
11
- import { SessionID } from "./session-id.js"
12
- import { SessionMetadata } from "./session-metadata.js"
13
- import { Money } from "./money.js"
14
- import { Permission } from "./permission.js"
15
- import { TokenUsage } from "./token-usage.js"
16
- import { Revert } from "./session-revert.js"
17
- import { SessionFork } from "./session-fork.js"
18
-
19
- export const ID = SessionID
20
- export type ID = SessionID
21
-
22
- export const Metadata = SessionMetadata
23
- export type Metadata = SessionMetadata
24
-
25
- export const Event = SessionEvent
26
-
27
- export { Revert }
28
- export const ForkBoundary = SessionFork.Boundary
29
- export type ForkBoundary = SessionFork.Boundary
30
-
31
- export interface Info extends Schema.Schema.Type<typeof Info> {}
32
- export const Info = Schema.Struct({
33
- id: ID,
34
- parentID: ID.pipe(optional),
35
- fork: Schema.Struct({
36
- sessionID: ID,
37
- boundary: ForkBoundary,
38
- }).pipe(optional),
39
- projectID: Project.ID,
40
- agent: Agent.ID.pipe(optional),
41
- model: Model.Ref.pipe(optional),
42
- cost: Money.USD,
43
- tokens: TokenUsage.Info,
44
- /** Outcome of the last completed execution, recorded at `time.idle`. Absent until a run reaches a terminal transition. */
45
- outcome: Schema.Literals(["succeeded", "failed", "interrupted"]).pipe(optional),
46
- time: Schema.Struct({
47
- created: DateTimeUtcFromMillis,
48
- updated: DateTimeUtcFromMillis,
49
- /** Start of the most recent execution. While it runs, `idle` still holds the previous execution's end. Resuming after a restart starts a new execution. */
50
- busy: DateTimeUtcFromMillis.pipe(optional),
51
- /** End of the most recent completed execution. */
52
- idle: DateTimeUtcFromMillis.pipe(optional),
53
- viewed: DateTimeUtcFromMillis.pipe(optional),
54
- archived: DateTimeUtcFromMillis.pipe(optional),
55
- }),
56
- title: Schema.String.pipe(optional),
57
- location: Location.Ref,
58
- subpath: RelativePath.pipe(optional),
59
- metadata: Metadata.pipe(optional),
60
- /** Evaluated after the agent's rules; the last matching rule wins. */
61
- permissions: Permission.Ruleset.pipe(optional),
62
- revert: Revert.pipe(optional),
63
- }).annotate({ identifier: "Session.Info" })
64
-
65
- export const ListAnchor = Schema.Struct({
66
- id: ID,
67
- time: Schema.Finite,
68
- direction: Schema.Literals(["previous", "next"]),
69
- }).annotate({ identifier: "Session.ListAnchor" })
70
- export interface ListAnchor extends Schema.Schema.Type<typeof ListAnchor> {}
71
-
72
- // These fields are also the session.list HTTP query parameters. Raw Schema.optional keeps that
73
- // endpoint's OpenAPI parameters unchanged.
74
- const ListFilterFields = {
75
- order: Schema.Literals(["asc", "desc"]).pipe(Schema.optional).annotate({
76
- description: "Session order for the first page. Use desc for newest first or asc for oldest first.",
77
- }),
78
- search: Schema.String.pipe(Schema.optional),
79
- parentID: Schema.Union([
80
- ID,
81
- Schema.Null.pipe(
82
- Schema.encodeTo(Schema.Literal("null"), {
83
- decode: SchemaGetter.transform(() => null),
84
- encode: SchemaGetter.transform(() => "null" as const),
85
- }),
86
- ),
87
- ])
88
- .annotate({ description: "Filter by parent session. Use null to return only root sessions." })
89
- .pipe(Schema.optional),
90
- archived: Schema.Literals(["true", "false"])
91
- .pipe(
92
- Schema.decodeTo(Schema.Boolean, {
93
- decode: SchemaGetter.transform((value) => value === "true"),
94
- encode: SchemaGetter.transform((value): "true" | "false" => (value ? "true" : "false")),
95
- }),
96
- )
97
- .annotate({
98
- description:
99
- "Filter by archive state. Use true to return only archived sessions or false to exclude them. Omit to include both.",
100
- })
101
- .pipe(Schema.optional),
102
- }
103
-
104
- export const ListFilter = Schema.Struct({
105
- ...ListFilterFields,
106
- directory: AbsolutePath.pipe(Schema.optional),
107
- project: Project.ID.pipe(Schema.optional),
108
- subpath: RelativePath.pipe(Schema.optional),
109
- }).annotate({ identifier: "Session.ListFilter" })
110
- export interface ListFilter extends Schema.Schema.Type<typeof ListFilter> {}
111
-
112
- const ListCursorInput = Schema.Union([
113
- Schema.Struct({ ...ListFilterFields, directory: AbsolutePath, anchor: ListAnchor }),
114
- Schema.Struct({
115
- ...ListFilterFields,
116
- project: Project.ID,
117
- subpath: RelativePath.pipe(Schema.optional),
118
- anchor: ListAnchor,
119
- }),
120
- Schema.Struct({ ...ListFilterFields, anchor: ListAnchor }),
121
- ])
122
- const ListCursorJson = Schema.fromJsonString(ListCursorInput)
123
- const encodeListCursor = Schema.encodeSync(ListCursorJson)
124
- const decodeListCursor = Schema.decodeUnknownEffect(ListCursorJson)
125
-
126
- export const ListCursor = Schema.String.pipe(
127
- Schema.brand("SessionsCursor"),
128
- Schema.annotate({
129
- identifier: "SessionsCursor",
130
- description: "Opaque pagination cursor returned as cursor.previous or cursor.next in the previous response.",
131
- }),
132
- statics((schema) => {
133
- // Read the default constructor without caching it on the schema, so `make` can be replaced.
134
- const make = SchemaParser.make(schema)
135
- return {
136
- make: (input: typeof ListCursorInput.Type) => make(Base64Url.encode(encodeListCursor(input))),
137
- parse: (input: string) =>
138
- Effect.suspend(() => {
139
- const result = Base64Url.decodeString(input)
140
- return Result.isFailure(result)
141
- ? Effect.fail("Invalid cursor" as const)
142
- : decodeListCursor(result.success).pipe(Effect.mapError(() => "Invalid cursor" as const))
143
- }),
144
- }
145
- }),
146
- )
147
- export type ListCursor = typeof ListCursor.Type
1
+ export * as Session from "./session.js"
2
+
3
+ import { Effect, Result, Schema, SchemaGetter, SchemaParser } from "effect"
4
+ import { Base64Url } from "effect/encoding"
5
+ import { Agent } from "./agent.js"
6
+ import { Location } from "./location.js"
7
+ import { Model } from "./model.js"
8
+ import { Project } from "./project.js"
9
+ import { AbsolutePath, DateTimeUtcFromMillis, optional, RelativePath, statics } from "./schema.js"
10
+ import { SessionEvent } from "./session-event.js"
11
+ import { SessionID } from "./session-id.js"
12
+ import { SessionMetadata } from "./session-metadata.js"
13
+ import { Money } from "./money.js"
14
+ import { Permission } from "./permission.js"
15
+ import { TokenUsage } from "./token-usage.js"
16
+ import { Revert } from "./session-revert.js"
17
+ import { SessionFork } from "./session-fork.js"
18
+
19
+ export const ID = SessionID
20
+ export type ID = SessionID
21
+
22
+ export const Metadata = SessionMetadata
23
+ export type Metadata = SessionMetadata
24
+
25
+ export const Event = SessionEvent
26
+
27
+ export { Revert }
28
+ export const ForkBoundary = SessionFork.Boundary
29
+ export type ForkBoundary = SessionFork.Boundary
30
+
31
+ export interface Info extends Schema.Schema.Type<typeof Info> {}
32
+ export const Info = Schema.Struct({
33
+ id: ID,
34
+ parentID: ID.pipe(optional),
35
+ fork: Schema.Struct({
36
+ sessionID: ID,
37
+ boundary: ForkBoundary,
38
+ }).pipe(optional),
39
+ projectID: Project.ID,
40
+ agent: Agent.ID.pipe(optional),
41
+ model: Model.Ref.pipe(optional),
42
+ cost: Money.USD,
43
+ tokens: TokenUsage.Info,
44
+ /** Outcome of the last completed execution, recorded at `time.idle`. Absent until a run reaches a terminal transition. */
45
+ outcome: Schema.Literals(["succeeded", "failed", "interrupted"]).pipe(optional),
46
+ time: Schema.Struct({
47
+ created: DateTimeUtcFromMillis,
48
+ updated: DateTimeUtcFromMillis,
49
+ /** Start of the most recent execution. While it runs, `idle` still holds the previous execution's end. Resuming after a restart starts a new execution. */
50
+ busy: DateTimeUtcFromMillis.pipe(optional),
51
+ /** End of the most recent completed execution. */
52
+ idle: DateTimeUtcFromMillis.pipe(optional),
53
+ viewed: DateTimeUtcFromMillis.pipe(optional),
54
+ archived: DateTimeUtcFromMillis.pipe(optional),
55
+ }),
56
+ title: Schema.String.pipe(optional),
57
+ location: Location.Ref,
58
+ subpath: RelativePath.pipe(optional),
59
+ metadata: Metadata.pipe(optional),
60
+ /** Evaluated after the agent's rules; the last matching rule wins. */
61
+ permissions: Permission.Ruleset.pipe(optional),
62
+ revert: Revert.pipe(optional),
63
+ }).annotate({ identifier: "Session.Info" })
64
+
65
+ export const ListAnchor = Schema.Struct({
66
+ id: ID,
67
+ time: Schema.Finite,
68
+ direction: Schema.Literals(["previous", "next"]),
69
+ }).annotate({ identifier: "Session.ListAnchor" })
70
+ export interface ListAnchor extends Schema.Schema.Type<typeof ListAnchor> {}
71
+
72
+ // These fields are also the session.list HTTP query parameters. Raw Schema.optional keeps that
73
+ // endpoint's OpenAPI parameters unchanged.
74
+ const ListFilterFields = {
75
+ order: Schema.Literals(["asc", "desc"]).pipe(Schema.optional).annotate({
76
+ description: "Session order for the first page. Use desc for newest first or asc for oldest first.",
77
+ }),
78
+ search: Schema.String.pipe(Schema.optional),
79
+ parentID: Schema.Union([
80
+ ID,
81
+ Schema.Null.pipe(
82
+ Schema.encodeTo(Schema.Literal("null"), {
83
+ decode: SchemaGetter.transform(() => null),
84
+ encode: SchemaGetter.transform(() => "null" as const),
85
+ }),
86
+ ),
87
+ ])
88
+ .annotate({ description: "Filter by parent session. Use null to return only root sessions." })
89
+ .pipe(Schema.optional),
90
+ archived: Schema.Literals(["true", "false"])
91
+ .pipe(
92
+ Schema.decodeTo(Schema.Boolean, {
93
+ decode: SchemaGetter.transform((value) => value === "true"),
94
+ encode: SchemaGetter.transform((value): "true" | "false" => (value ? "true" : "false")),
95
+ }),
96
+ )
97
+ .annotate({
98
+ description:
99
+ "Filter by archive state. Use true to return only archived sessions or false to exclude them. Omit to include both.",
100
+ })
101
+ .pipe(Schema.optional),
102
+ }
103
+
104
+ export const ListFilter = Schema.Struct({
105
+ ...ListFilterFields,
106
+ directory: AbsolutePath.pipe(Schema.optional),
107
+ project: Project.ID.pipe(Schema.optional),
108
+ subpath: RelativePath.pipe(Schema.optional),
109
+ }).annotate({ identifier: "Session.ListFilter" })
110
+ export interface ListFilter extends Schema.Schema.Type<typeof ListFilter> {}
111
+
112
+ const ListCursorInput = Schema.Union([
113
+ Schema.Struct({ ...ListFilterFields, directory: AbsolutePath, anchor: ListAnchor }),
114
+ Schema.Struct({
115
+ ...ListFilterFields,
116
+ project: Project.ID,
117
+ subpath: RelativePath.pipe(Schema.optional),
118
+ anchor: ListAnchor,
119
+ }),
120
+ Schema.Struct({ ...ListFilterFields, anchor: ListAnchor }),
121
+ ])
122
+ const ListCursorJson = Schema.fromJsonString(ListCursorInput)
123
+ const encodeListCursor = Schema.encodeSync(ListCursorJson)
124
+ const decodeListCursor = Schema.decodeUnknownEffect(ListCursorJson)
125
+
126
+ export const ListCursor = Schema.String.pipe(
127
+ Schema.brand("SessionsCursor"),
128
+ Schema.annotate({
129
+ identifier: "SessionsCursor",
130
+ description: "Opaque pagination cursor returned as cursor.previous or cursor.next in the previous response.",
131
+ }),
132
+ statics((schema) => {
133
+ // Read the default constructor without caching it on the schema, so `make` can be replaced.
134
+ const make = SchemaParser.make(schema)
135
+ return {
136
+ make: (input: typeof ListCursorInput.Type) => make(Base64Url.encode(encodeListCursor(input))),
137
+ parse: (input: string) =>
138
+ Effect.suspend(() => {
139
+ const result = Base64Url.decodeString(input)
140
+ return Result.isFailure(result)
141
+ ? Effect.fail("Invalid cursor" as const)
142
+ : decodeListCursor(result.success).pipe(Effect.mapError(() => "Invalid cursor" as const))
143
+ }),
144
+ }
145
+ }),
146
+ )
147
+ export type ListCursor = typeof ListCursor.Type
package/src/shell.ts CHANGED
@@ -1,90 +1,90 @@
1
- export * as Shell from "./shell.js"
2
-
3
- import { Schema } from "effect"
4
- import { optional } from "./schema.js"
5
- import { ephemeral, inventory } from "./event.js"
6
- import { ascending } from "./identifier.js"
7
- import { NonNegativeInt, statics } from "./schema.js"
8
-
9
- const IDSchema = Schema.String.check(Schema.isStartingWith("sh_")).pipe(
10
- Schema.brand("Shell.ID"),
11
- Schema.annotate({ identifier: "Shell.ID" }),
12
- )
13
-
14
- export const ID = IDSchema.pipe(
15
- statics((schema: typeof IDSchema) => {
16
- const create = () => schema.make("sh_" + ascending())
17
- return {
18
- create,
19
- ascending: (id?: string) => (id === undefined ? create() : schema.make(id)),
20
- }
21
- }),
22
- )
23
- export type ID = typeof ID.Type
24
-
25
- export const Status = Schema.Literals(["running", "exited", "timeout", "killed"])
26
- export type Status = typeof Status.Type
27
-
28
- export const Time = Schema.Struct({
29
- started: Schema.Finite.annotate({ description: "Start time in milliseconds since the Unix epoch" }),
30
- completed: optional(Schema.Finite).annotate({
31
- description: "Completion time in milliseconds since the Unix epoch",
32
- }),
33
- })
34
- export interface Time extends Schema.Schema.Type<typeof Time> {}
35
-
36
- // Opaque caller-supplied tags echoed back on Info and events. The Shell service never interprets
37
- // these; callers (e.g. ShellTool stores the originating session ID) use them to filter or correlate.
38
- export const Metadata = Schema.Record(Schema.String, Schema.Unknown)
39
- export type Metadata = typeof Metadata.Type
40
-
41
- export const Info = Schema.Struct({
42
- id: ID,
43
- status: Status,
44
- command: Schema.String,
45
- cwd: Schema.String,
46
- shell: Schema.String,
47
- // Absolute path of the file capturing combined stdout/stderr. Page through it via `output`.
48
- file: Schema.String,
49
- pid: optional(NonNegativeInt),
50
- exit: optional(Schema.Finite),
51
- signal: optional(Schema.String),
52
- // Always present; defaults to an empty object when the creator supplies no metadata.
53
- metadata: Metadata,
54
- time: Time,
55
- }).annotate({ identifier: "Shell.Info" })
56
- export interface Info extends Schema.Schema.Type<typeof Info> {}
57
-
58
- const Created = ephemeral({ type: "shell.created", schema: { info: Info } })
59
- const Exited = ephemeral({ type: "shell.exited", schema: { id: ID, exit: optional(Schema.Finite), status: Status } })
60
- const Deleted = ephemeral({ type: "shell.deleted", schema: { id: ID } })
61
- export const Event = { Created, Exited, Deleted, Definitions: inventory(Created, Exited, Deleted) }
62
-
63
- export const CreateInput = Schema.Struct({
64
- command: Schema.String,
65
- cwd: optional(Schema.String),
66
- timeout: optional(NonNegativeInt),
67
- metadata: optional(Metadata),
68
- })
69
- export interface CreateInput extends Schema.Schema.Type<typeof CreateInput> {}
70
-
71
- // Descriptions sit on the inner schema because the query string codec drops annotations on `optional` itself.
72
- export const OutputInput = Schema.Struct({
73
- cursor: optional(
74
- NonNegativeInt.annotateKey({
75
- description: "Byte offset to read from, such as the cursor of the previous page. Defaults to 0.",
76
- }),
77
- ),
78
- limit: optional(NonNegativeInt.annotateKey({ description: "Maximum number of bytes to return. Defaults to 65536." })),
79
- })
80
- export interface OutputInput extends Schema.Schema.Type<typeof OutputInput> {}
81
-
82
- export const Output = Schema.Struct({
83
- output: Schema.String,
84
- // Absolute cursor after this page. Equals `size` once fully caught up.
85
- cursor: NonNegativeInt,
86
- // Total bytes captured so far. A consumer has more to page while `cursor < size`.
87
- size: NonNegativeInt,
88
- truncated: Schema.Boolean,
89
- })
90
- export interface Output extends Schema.Schema.Type<typeof Output> {}
1
+ export * as Shell from "./shell.js"
2
+
3
+ import { Schema } from "effect"
4
+ import { optional } from "./schema.js"
5
+ import { ephemeral, inventory } from "./event.js"
6
+ import { ascending } from "./identifier.js"
7
+ import { NonNegativeInt, statics } from "./schema.js"
8
+
9
+ const IDSchema = Schema.String.check(Schema.isStartingWith("sh_")).pipe(
10
+ Schema.brand("Shell.ID"),
11
+ Schema.annotate({ identifier: "Shell.ID" }),
12
+ )
13
+
14
+ export const ID = IDSchema.pipe(
15
+ statics((schema: typeof IDSchema) => {
16
+ const create = () => schema.make("sh_" + ascending())
17
+ return {
18
+ create,
19
+ ascending: (id?: string) => (id === undefined ? create() : schema.make(id)),
20
+ }
21
+ }),
22
+ )
23
+ export type ID = typeof ID.Type
24
+
25
+ export const Status = Schema.Literals(["running", "exited", "timeout", "killed"])
26
+ export type Status = typeof Status.Type
27
+
28
+ export const Time = Schema.Struct({
29
+ started: Schema.Finite.annotate({ description: "Start time in milliseconds since the Unix epoch" }),
30
+ completed: optional(Schema.Finite).annotate({
31
+ description: "Completion time in milliseconds since the Unix epoch",
32
+ }),
33
+ })
34
+ export interface Time extends Schema.Schema.Type<typeof Time> {}
35
+
36
+ // Opaque caller-supplied tags echoed back on Info and events. The Shell service never interprets
37
+ // these; callers (e.g. ShellTool stores the originating session ID) use them to filter or correlate.
38
+ export const Metadata = Schema.Record(Schema.String, Schema.Unknown)
39
+ export type Metadata = typeof Metadata.Type
40
+
41
+ export const Info = Schema.Struct({
42
+ id: ID,
43
+ status: Status,
44
+ command: Schema.String,
45
+ cwd: Schema.String,
46
+ shell: Schema.String,
47
+ // Absolute path of the file capturing combined stdout/stderr. Page through it via `output`.
48
+ file: Schema.String,
49
+ pid: optional(NonNegativeInt),
50
+ exit: optional(Schema.Finite),
51
+ signal: optional(Schema.String),
52
+ // Always present; defaults to an empty object when the creator supplies no metadata.
53
+ metadata: Metadata,
54
+ time: Time,
55
+ }).annotate({ identifier: "Shell.Info" })
56
+ export interface Info extends Schema.Schema.Type<typeof Info> {}
57
+
58
+ const Created = ephemeral({ type: "shell.created", schema: { info: Info } })
59
+ const Exited = ephemeral({ type: "shell.exited", schema: { id: ID, exit: optional(Schema.Finite), status: Status } })
60
+ const Deleted = ephemeral({ type: "shell.deleted", schema: { id: ID } })
61
+ export const Event = { Created, Exited, Deleted, Definitions: inventory(Created, Exited, Deleted) }
62
+
63
+ export const CreateInput = Schema.Struct({
64
+ command: Schema.String,
65
+ cwd: optional(Schema.String),
66
+ timeout: optional(NonNegativeInt),
67
+ metadata: optional(Metadata),
68
+ })
69
+ export interface CreateInput extends Schema.Schema.Type<typeof CreateInput> {}
70
+
71
+ // Descriptions sit on the inner schema because the query string codec drops annotations on `optional` itself.
72
+ export const OutputInput = Schema.Struct({
73
+ cursor: optional(
74
+ NonNegativeInt.annotateKey({
75
+ description: "Byte offset to read from, such as the cursor of the previous page. Defaults to 0.",
76
+ }),
77
+ ),
78
+ limit: optional(NonNegativeInt.annotateKey({ description: "Maximum number of bytes to return. Defaults to 65536." })),
79
+ })
80
+ export interface OutputInput extends Schema.Schema.Type<typeof OutputInput> {}
81
+
82
+ export const Output = Schema.Struct({
83
+ output: Schema.String,
84
+ // Absolute cursor after this page. Equals `size` once fully caught up.
85
+ cursor: NonNegativeInt,
86
+ // Total bytes captured so far. A consumer has more to page while `cursor < size`.
87
+ size: NonNegativeInt,
88
+ truncated: Schema.Boolean,
89
+ })
90
+ export interface Output extends Schema.Schema.Type<typeof Output> {}
package/src/skill.ts CHANGED
@@ -1,68 +1,68 @@
1
- export * as Skill from "./skill.js"
2
-
3
- import { Schema } from "effect"
4
- import { optional } from "./schema.js"
5
- import { AbsolutePath } from "./schema.js"
6
- import { ephemeral, inventory } from "./event.js"
7
-
8
- export const ID = Schema.String.pipe(Schema.brand("Skill.ID"), Schema.annotate({ identifier: "Skill.ID" }))
9
- export type ID = typeof ID.Type
10
-
11
- export const Name = Schema.String.pipe(Schema.brand("Skill.Name"), Schema.annotate({ identifier: "Skill.Name" }))
12
- export type Name = typeof Name.Type
13
-
14
- export interface DirectorySource extends Schema.Schema.Type<typeof DirectorySource> {}
15
- export const DirectorySource = Schema.Struct({
16
- type: Schema.tag("directory"),
17
- path: AbsolutePath,
18
- }).annotate({ identifier: "Skill.DirectorySource" })
19
-
20
- export interface UrlSource extends Schema.Schema.Type<typeof UrlSource> {}
21
- export const UrlSource = Schema.Struct({
22
- type: Schema.tag("url"),
23
- url: Schema.String,
24
- }).annotate({ identifier: "Skill.UrlSource" })
25
-
26
- export interface Info extends Schema.Schema.Type<typeof Info> {}
27
- export const Info = Schema.Struct({
28
- id: ID,
29
- name: Name,
30
- description: Schema.String.pipe(optional),
31
- autoinvoke: Schema.Boolean.pipe(optional),
32
- path: AbsolutePath,
33
- content: Schema.String.annotate({
34
- description: "The SKILL.md body. Empty for a skill whose body loads on demand, such as an MCP skill.",
35
- }),
36
- }).annotate({ identifier: "Skill.Info" })
37
-
38
- const Updated = ephemeral({ type: "skill.updated", schema: {} })
39
- export const Event = { Updated, Definitions: inventory(Updated) }
40
-
41
- export interface EmbeddedSource extends Schema.Schema.Type<typeof EmbeddedSource> {}
42
- export const EmbeddedSource = Schema.Struct({
43
- type: Schema.tag("embedded"),
44
- skill: Schema.suspend(() => Info),
45
- }).annotate({ identifier: "Skill.EmbeddedSource" })
46
-
47
- export type Source = DirectorySource | UrlSource | EmbeddedSource
48
- export const Source = Object.assign(
49
- Schema.Union([DirectorySource, UrlSource, EmbeddedSource]).pipe(
50
- Schema.toTaggedUnion("type"),
51
- Schema.annotate({ identifier: "Skill.Source" }),
52
- ),
53
- {
54
- equals: (a: Source, b: Source) => {
55
- if (a.type !== b.type) return false
56
- if (a.type === "directory" && b.type === "directory") return a.path === b.path
57
- if (a.type === "url" && b.type === "url") return a.url === b.url
58
- if (a.type === "embedded" && b.type === "embedded") return a.skill.id === b.skill.id
59
- return false
60
- },
61
- key: (source: Source) =>
62
- source.type === "directory"
63
- ? `directory:${source.path}`
64
- : source.type === "url"
65
- ? `url:${source.url}`
66
- : `embedded:${source.skill.id}`,
67
- },
68
- )
1
+ export * as Skill from "./skill.js"
2
+
3
+ import { Schema } from "effect"
4
+ import { optional } from "./schema.js"
5
+ import { AbsolutePath } from "./schema.js"
6
+ import { ephemeral, inventory } from "./event.js"
7
+
8
+ export const ID = Schema.String.pipe(Schema.brand("Skill.ID"), Schema.annotate({ identifier: "Skill.ID" }))
9
+ export type ID = typeof ID.Type
10
+
11
+ export const Name = Schema.String.pipe(Schema.brand("Skill.Name"), Schema.annotate({ identifier: "Skill.Name" }))
12
+ export type Name = typeof Name.Type
13
+
14
+ export interface DirectorySource extends Schema.Schema.Type<typeof DirectorySource> {}
15
+ export const DirectorySource = Schema.Struct({
16
+ type: Schema.tag("directory"),
17
+ path: AbsolutePath,
18
+ }).annotate({ identifier: "Skill.DirectorySource" })
19
+
20
+ export interface UrlSource extends Schema.Schema.Type<typeof UrlSource> {}
21
+ export const UrlSource = Schema.Struct({
22
+ type: Schema.tag("url"),
23
+ url: Schema.String,
24
+ }).annotate({ identifier: "Skill.UrlSource" })
25
+
26
+ export interface Info extends Schema.Schema.Type<typeof Info> {}
27
+ export const Info = Schema.Struct({
28
+ id: ID,
29
+ name: Name,
30
+ description: Schema.String.pipe(optional),
31
+ autoinvoke: Schema.Boolean.pipe(optional),
32
+ path: AbsolutePath,
33
+ content: Schema.String.annotate({
34
+ description: "The SKILL.md body. Empty for a skill whose body loads on demand, such as an MCP skill.",
35
+ }),
36
+ }).annotate({ identifier: "Skill.Info" })
37
+
38
+ const Updated = ephemeral({ type: "skill.updated", schema: {} })
39
+ export const Event = { Updated, Definitions: inventory(Updated) }
40
+
41
+ export interface EmbeddedSource extends Schema.Schema.Type<typeof EmbeddedSource> {}
42
+ export const EmbeddedSource = Schema.Struct({
43
+ type: Schema.tag("embedded"),
44
+ skill: Schema.suspend(() => Info),
45
+ }).annotate({ identifier: "Skill.EmbeddedSource" })
46
+
47
+ export type Source = DirectorySource | UrlSource | EmbeddedSource
48
+ export const Source = Object.assign(
49
+ Schema.Union([DirectorySource, UrlSource, EmbeddedSource]).pipe(
50
+ Schema.toTaggedUnion("type"),
51
+ Schema.annotate({ identifier: "Skill.Source" }),
52
+ ),
53
+ {
54
+ equals: (a: Source, b: Source) => {
55
+ if (a.type !== b.type) return false
56
+ if (a.type === "directory" && b.type === "directory") return a.path === b.path
57
+ if (a.type === "url" && b.type === "url") return a.url === b.url
58
+ if (a.type === "embedded" && b.type === "embedded") return a.skill.id === b.skill.id
59
+ return false
60
+ },
61
+ key: (source: Source) =>
62
+ source.type === "directory"
63
+ ? `directory:${source.path}`
64
+ : source.type === "url"
65
+ ? `url:${source.url}`
66
+ : `embedded:${source.skill.id}`,
67
+ },
68
+ )
package/src/snapshot.ts CHANGED
@@ -1,6 +1,6 @@
1
- export * as Snapshot from "./snapshot.js"
2
-
3
- import { Schema } from "effect"
4
-
5
- export const ID = Schema.String.pipe(Schema.brand("Snapshot.ID"), Schema.annotate({ identifier: "Snapshot.ID" }))
6
- export type ID = typeof ID.Type
1
+ export * as Snapshot from "./snapshot.js"
2
+
3
+ import { Schema } from "effect"
4
+
5
+ export const ID = Schema.String.pipe(Schema.brand("Snapshot.ID"), Schema.annotate({ identifier: "Snapshot.ID" }))
6
+ export type ID = typeof ID.Type