@zyro-sec/schema 0.0.0-stage → 1.0.1

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 (137) hide show
  1. package/AGENTS.md +95 -0
  2. package/package.json +31 -4
  3. package/script/build.ts +9 -0
  4. package/script/config-schema.ts +86 -0
  5. package/script/config-v1.json +1312 -0
  6. package/script/pack.ts +5 -0
  7. package/src/agent.ts +68 -0
  8. package/src/artifact.ts +81 -0
  9. package/src/automation.ts +224 -0
  10. package/src/blob-store.ts +25 -0
  11. package/src/command.ts +18 -0
  12. package/src/config/agent.ts +26 -0
  13. package/src/config/command.ts +14 -0
  14. package/src/config/compaction.ts +27 -0
  15. package/src/config/experimental.ts +72 -0
  16. package/src/config/flag.ts +39 -0
  17. package/src/config/formatter.ts +13 -0
  18. package/src/config/lsp.ts +19 -0
  19. package/src/config/mcp.ts +22 -0
  20. package/src/config/media.ts +15 -0
  21. package/src/config/model.ts +37 -0
  22. package/src/config/plugin.ts +14 -0
  23. package/src/config/policy.ts +57 -0
  24. package/src/config/provider.ts +122 -0
  25. package/src/config/reference.ts +23 -0
  26. package/src/config/shell.ts +10 -0
  27. package/src/config/tool-output.ts +9 -0
  28. package/src/config/warming.ts +21 -0
  29. package/src/config/watcher.ts +8 -0
  30. package/src/config/websearch.ts +17 -0
  31. package/src/config/worktree.ts +10 -0
  32. package/src/config.ts +149 -0
  33. package/src/connection.ts +38 -0
  34. package/src/credential-legacy.ts +29 -0
  35. package/src/credential.ts +78 -0
  36. package/src/durable-event-manifest.ts +7 -0
  37. package/src/event-log.ts +21 -0
  38. package/src/event-manifest.ts +108 -0
  39. package/src/event.ts +205 -0
  40. package/src/file-diff.ts +25 -0
  41. package/src/filesystem-v1.ts +1 -0
  42. package/src/filesystem.ts +48 -0
  43. package/src/form.ts +177 -0
  44. package/src/generate.ts +292 -0
  45. package/src/goal.ts +46 -0
  46. package/src/identifier.ts +32 -0
  47. package/src/index.ts +51 -0
  48. package/src/installation-event.ts +20 -0
  49. package/src/instruction-entry.ts +40 -0
  50. package/src/instruction.ts +25 -0
  51. package/src/integration-id.ts +13 -0
  52. package/src/integration.ts +129 -0
  53. package/src/job.ts +79 -0
  54. package/src/legacy-event.ts +1 -0
  55. package/src/llm.ts +6 -0
  56. package/src/location-event.ts +8 -0
  57. package/src/location.ts +36 -0
  58. package/src/lsp-event.ts +7 -0
  59. package/src/mcp-event.ts +63 -0
  60. package/src/mcp.ts +171 -0
  61. package/src/model-compatibility.ts +55 -0
  62. package/src/model.ts +176 -0
  63. package/src/models-dev.ts +9 -0
  64. package/src/money.ts +18 -0
  65. package/src/permission-saved.ts +25 -0
  66. package/src/permission-v1.ts +1 -0
  67. package/src/permission.ts +67 -0
  68. package/src/persistent-pty.ts +73 -0
  69. package/src/plugin.ts +62 -0
  70. package/src/project-id.ts +9 -0
  71. package/src/project.ts +62 -0
  72. package/src/prompt-input.ts +33 -0
  73. package/src/prompt.ts +117 -0
  74. package/src/provider.ts +136 -0
  75. package/src/pty-ticket.ts +10 -0
  76. package/src/pty.ts +61 -0
  77. package/src/push.ts +86 -0
  78. package/src/question.ts +22 -0
  79. package/src/reference.ts +40 -0
  80. package/src/rpc.ts +167 -0
  81. package/src/schema.ts +41 -0
  82. package/src/server-event.ts +8 -0
  83. package/src/session-error.ts +14 -0
  84. package/src/session-event.ts +739 -0
  85. package/src/session-fork.ts +10 -0
  86. package/src/session-id.ts +12 -0
  87. package/src/session-inbox.ts +102 -0
  88. package/src/session-legacy.ts +117 -0
  89. package/src/session-message.ts +352 -0
  90. package/src/session-metadata.ts +11 -0
  91. package/src/session-revert.ts +86 -0
  92. package/src/session-stats.ts +68 -0
  93. package/src/session-status-event.ts +53 -0
  94. package/src/session-transfer.ts +11 -0
  95. package/src/session-v1.ts +1 -0
  96. package/src/session.ts +147 -0
  97. package/src/shell.ts +90 -0
  98. package/src/skill.ts +68 -0
  99. package/src/snapshot.ts +6 -0
  100. package/src/token-usage.ts +18 -0
  101. package/src/tool.ts +143 -0
  102. package/src/tui-event.ts +59 -0
  103. package/src/usage-limits.ts +76 -0
  104. package/src/v1/filesystem.ts +11 -0
  105. package/src/v1/legacy-event.ts +18 -0
  106. package/src/v1/permission.ts +66 -0
  107. package/src/v1/session.ts +667 -0
  108. package/src/vcs-event.ts +14 -0
  109. package/src/vcs.ts +41 -0
  110. package/src/websearch.ts +44 -0
  111. package/src/workspace-event.ts +32 -0
  112. package/src/workspace-id.ts +19 -0
  113. package/src/workspace.ts +20 -0
  114. package/src/worktree-event.ts +22 -0
  115. package/src/worktree.ts +109 -0
  116. package/test/agent.test.ts +10 -0
  117. package/test/automation.test.ts +48 -0
  118. package/test/compatibility.test.ts +10 -0
  119. package/test/config.test.ts +194 -0
  120. package/test/contract-hygiene.test.ts +352 -0
  121. package/test/credential-legacy.test.ts +55 -0
  122. package/test/event-manifest.test.ts +228 -0
  123. package/test/event.test.ts +52 -0
  124. package/test/legacy-event.test.ts +46 -0
  125. package/test/mcp.test.ts +37 -0
  126. package/test/model.test.ts +104 -0
  127. package/test/session-cursor.test.ts +16 -0
  128. package/test/session-error.test.ts +51 -0
  129. package/test/session-legacy.test.ts +178 -0
  130. package/test/session-terminal.test.ts +50 -0
  131. package/test/token-usage.test.ts +18 -0
  132. package/test/v1-isolation.test.ts +26 -0
  133. package/test/vcs.test.ts +23 -0
  134. package/test/worktree.test.ts +45 -0
  135. package/tsconfig.build.json +11 -0
  136. package/tsconfig.json +14 -0
  137. package/README.md +0 -3
@@ -0,0 +1,86 @@
1
+ import { Schema, SchemaTransformation } from "effect"
2
+ import { FileDiff } from "./file-diff.js"
3
+ import { optional } from "./schema.js"
4
+ import { SessionMessage } from "./session-message.js"
5
+ import { Snapshot } from "./snapshot.js"
6
+
7
+ export interface Revert extends Schema.Schema.Type<typeof Revert> {}
8
+ export const Revert = Schema.Struct({
9
+ messageID: SessionMessage.ID,
10
+ /** Legacy V1 compatibility state. */
11
+ partID: Schema.String.pipe(optional),
12
+ snapshot: Snapshot.ID.pipe(optional),
13
+ files: Schema.Array(FileDiff.Info).pipe(optional),
14
+ }).annotate({ identifier: "Session.Revert" })
15
+
16
+ const FileDiffV1 = Schema.Struct({
17
+ path: Schema.String,
18
+ status: Schema.Literals(["added", "modified", "deleted"]),
19
+ additions: Schema.Finite,
20
+ deletions: Schema.Finite,
21
+ patch: Schema.String,
22
+ })
23
+
24
+ export interface RevertV1 extends Schema.Schema.Type<typeof RevertV1> {}
25
+ export const RevertV1 = Schema.Struct({
26
+ messageID: SessionMessage.ID,
27
+ partID: Schema.String.pipe(optional),
28
+ snapshot: Schema.String.pipe(optional),
29
+ diff: Schema.String.pipe(optional),
30
+ files: Schema.Array(FileDiffV1).pipe(optional),
31
+ }).annotate({ identifier: "Session.RevertV1" })
32
+
33
+ const PersistedCurrent = Revert.pipe(
34
+ Schema.decodeTo(
35
+ Schema.Struct({ source: Schema.tag("current"), revert: Schema.toType(Revert) }),
36
+ SchemaTransformation.transform({
37
+ decode: (revert): { readonly source: "current"; readonly revert: Revert } => ({
38
+ source: "current",
39
+ revert,
40
+ }),
41
+ encode: (value) => value.revert,
42
+ }),
43
+ ),
44
+ )
45
+ const PersistedLegacy = RevertV1.pipe(
46
+ Schema.decodeTo(
47
+ Schema.Struct({ source: Schema.tag("legacy"), revert: Schema.toType(RevertV1) }),
48
+ SchemaTransformation.transform({
49
+ decode: (revert): { readonly source: "legacy"; readonly revert: RevertV1 } => ({
50
+ source: "legacy",
51
+ revert,
52
+ }),
53
+ encode: (value) => value.revert,
54
+ }),
55
+ ),
56
+ )
57
+
58
+ /** Storage decoder for revert state written before FileDiff became canonical. */
59
+ export const PersistedRevert = Schema.Union([PersistedCurrent, PersistedLegacy]).pipe(
60
+ Schema.toTaggedUnion("source"),
61
+ Schema.decodeTo(
62
+ Schema.toType(Revert),
63
+ SchemaTransformation.transform({
64
+ decode: (persisted): Revert => {
65
+ if (persisted.source === "current") return persisted.revert
66
+ return Revert.make({
67
+ messageID: persisted.revert.messageID,
68
+ partID: persisted.revert.partID,
69
+ snapshot: persisted.revert.snapshot ? Snapshot.ID.make(persisted.revert.snapshot) : undefined,
70
+ files: persisted.revert.files?.map((file) => ({
71
+ file: file.path,
72
+ status: file.status,
73
+ additions: file.additions,
74
+ deletions: file.deletions,
75
+ patch: file.patch,
76
+ })),
77
+ })
78
+ },
79
+ encode: (revert): { readonly source: "current"; readonly revert: Revert } => ({
80
+ source: "current",
81
+ revert,
82
+ }),
83
+ }),
84
+ ),
85
+ Schema.annotate({ identifier: "Session.Revert.Persisted" }),
86
+ )
@@ -0,0 +1,68 @@
1
+ export * as SessionStats from "./session-stats.js"
2
+
3
+ import { Schema } from "effect"
4
+ import { Model } from "./model.js"
5
+ import { Money } from "./money.js"
6
+ import { DateTimeUtcFromMillis, NonNegativeInt, optional } from "./schema.js"
7
+ import { TokenUsage } from "./token-usage.js"
8
+
9
+ export const Activity = Schema.Struct({
10
+ date: Schema.String,
11
+ steps: NonNegativeInt,
12
+ }).annotate({ identifier: "SessionStats.Activity" })
13
+ export type Activity = typeof Activity.Type
14
+
15
+ export const ModelUsage = Schema.Struct({
16
+ model: Model.Ref,
17
+ steps: NonNegativeInt,
18
+ tokens: TokenUsage.Info,
19
+ cost: Money.USD,
20
+ }).annotate({ identifier: "SessionStats.ModelUsage" })
21
+ export type ModelUsage = typeof ModelUsage.Type
22
+
23
+ export const ToolUsage = Schema.Struct({
24
+ name: Schema.String,
25
+ calls: NonNegativeInt,
26
+ succeeded: NonNegativeInt,
27
+ failed: NonNegativeInt,
28
+ unfinished: NonNegativeInt,
29
+ durationP50: Schema.Finite.pipe(optional),
30
+ }).annotate({ identifier: "SessionStats.ToolUsage" })
31
+ export type ToolUsage = typeof ToolUsage.Type
32
+
33
+ export const ToolMode = Schema.Literals(["none", "summary", "detail"])
34
+ export type ToolMode = typeof ToolMode.Type
35
+
36
+ export const ToolTotals = Schema.Struct({
37
+ calls: NonNegativeInt,
38
+ succeeded: NonNegativeInt,
39
+ failed: NonNegativeInt,
40
+ unfinished: NonNegativeInt,
41
+ }).annotate({ identifier: "SessionStats.ToolTotals" })
42
+ export type ToolTotals = typeof ToolTotals.Type
43
+
44
+ export const Tools = Schema.Union([
45
+ Schema.Struct({ mode: Schema.Literal("none") }),
46
+ Schema.Struct({ mode: Schema.Literal("summary"), totals: ToolTotals }),
47
+ Schema.Struct({ mode: Schema.Literal("detail"), totals: ToolTotals, usage: Schema.Array(ToolUsage) }),
48
+ ]).annotate({ identifier: "SessionStats.Tools" })
49
+ export type Tools = typeof Tools.Type
50
+
51
+ export const Info = Schema.Struct({
52
+ range: Schema.Struct({
53
+ from: DateTimeUtcFromMillis,
54
+ to: DateTimeUtcFromMillis,
55
+ }),
56
+ sessions: NonNegativeInt,
57
+ subagents: NonNegativeInt,
58
+ prompts: NonNegativeInt,
59
+ steps: NonNegativeInt,
60
+ tokens: TokenUsage.Info,
61
+ cost: Money.USD,
62
+ tools: Tools,
63
+ activeDays: NonNegativeInt,
64
+ streak: NonNegativeInt,
65
+ activity: Schema.Array(Activity),
66
+ models: Schema.Array(ModelUsage),
67
+ }).annotate({ identifier: "SessionStats.Info" })
68
+ export type Info = typeof Info.Type
@@ -0,0 +1,53 @@
1
+ export * as SessionStatusEvent from "./session-status-event.js"
2
+
3
+ import { Schema } from "effect"
4
+ import { optional } from "./schema.js"
5
+ import { Event } from "./event.js"
6
+ import { NonNegativeInt } from "./schema.js"
7
+ import { SessionID } from "./session-id.js"
8
+
9
+ export const Info = Schema.Union([
10
+ Schema.Struct({
11
+ type: Schema.Literal("idle"),
12
+ }),
13
+ Schema.Struct({
14
+ type: Schema.Literal("retry"),
15
+ attempt: NonNegativeInt,
16
+ message: Schema.String,
17
+ action: optional(
18
+ Schema.Struct({
19
+ reason: Schema.String,
20
+ provider: Schema.String,
21
+ title: Schema.String,
22
+ message: Schema.String,
23
+ label: Schema.String,
24
+ link: optional(Schema.String),
25
+ }),
26
+ ),
27
+ next: NonNegativeInt,
28
+ }),
29
+ Schema.Struct({
30
+ type: Schema.Literal("busy"),
31
+ }),
32
+ ]).annotate({ identifier: "SessionStatus" })
33
+ export type Info = Schema.Schema.Type<typeof Info>
34
+
35
+ export const Status = Event.ephemeral({
36
+ type: "session.status",
37
+ // The bare SessionStatus identifier belongs to the status union above.
38
+ identifier: "SessionStatusUpdated",
39
+ schema: {
40
+ sessionID: SessionID,
41
+ status: Info,
42
+ },
43
+ })
44
+
45
+ // deprecated
46
+ export const Idle = Event.ephemeral({
47
+ type: "session.idle",
48
+ schema: {
49
+ sessionID: SessionID,
50
+ },
51
+ })
52
+
53
+ export const Definitions = Event.inventory(Status, Idle)
@@ -0,0 +1,11 @@
1
+ export * as SessionTransfer from "./session-transfer.js"
2
+
3
+ import { Schema } from "effect"
4
+ import { Session } from "./session.js"
5
+ import { SessionMessage } from "./session-message.js"
6
+
7
+ export interface Data extends Schema.Schema.Type<typeof Data> {}
8
+ export const Data = Schema.Struct({
9
+ info: Session.Info,
10
+ messages: Schema.Array(SessionMessage.Info),
11
+ }).annotate({ identifier: "SessionTransfer.Data" })
@@ -0,0 +1 @@
1
+ export * from "./v1/session.js"
package/src/session.ts ADDED
@@ -0,0 +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
package/src/shell.ts ADDED
@@ -0,0 +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> {}
package/src/skill.ts ADDED
@@ -0,0 +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
+ )
@@ -0,0 +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
@@ -0,0 +1,18 @@
1
+ export * as TokenUsage from "./token-usage.js"
2
+
3
+ import { Schema } from "effect"
4
+
5
+ export interface Info extends Schema.Schema.Type<typeof Info> {}
6
+ export const Info = Schema.Struct({
7
+ input: Schema.Finite,
8
+ output: Schema.Finite,
9
+ reasoning: Schema.Finite,
10
+ cache: Schema.Struct({
11
+ read: Schema.Finite,
12
+ write: Schema.Finite,
13
+ }),
14
+ }).annotate({ identifier: "TokenUsage.Info" })
15
+
16
+ export function total(tokens: Info) {
17
+ return tokens.input + tokens.output + tokens.reasoning + tokens.cache.read + tokens.cache.write
18
+ }