@margay/ccl-core 1.5.0-alpha.0 → 1.5.1-alpha.2

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 (94) hide show
  1. package/README.md +1 -1
  2. package/dist/cli.js +95197 -74935
  3. package/dist/sdk/background.d.ts +48 -0
  4. package/dist/sdk/background.js +87 -0
  5. package/dist/sdk/backgroundRunTypes.d.ts +101 -0
  6. package/dist/sdk/backgroundRunTypes.js +1 -0
  7. package/dist/sdk/commandAdapter.d.ts +77 -0
  8. package/dist/sdk/commandAdapter.js +180 -0
  9. package/dist/sdk/commandProcess.d.ts +27 -0
  10. package/dist/sdk/commandProcess.js +130 -0
  11. package/dist/sdk/executionGuidance.d.ts +7 -0
  12. package/dist/sdk/executionGuidance.js +37 -0
  13. package/dist/sdk/index.d.ts +16 -1
  14. package/dist/sdk/index.js +10 -0
  15. package/dist/sdk/inputProvenance.d.ts +13 -0
  16. package/dist/sdk/inputProvenance.js +26 -0
  17. package/dist/sdk/mcpServer.d.ts +9 -5
  18. package/dist/sdk/mcpServer.js +51 -9
  19. package/dist/sdk/operations/command.d.ts +24 -0
  20. package/dist/sdk/operations/command.js +48 -0
  21. package/dist/sdk/operations/host.d.ts +3 -0
  22. package/dist/sdk/operations/host.js +376 -0
  23. package/dist/sdk/operations/json.d.ts +6 -0
  24. package/dist/sdk/operations/json.js +24 -0
  25. package/dist/sdk/operations/reference.d.ts +15 -0
  26. package/dist/sdk/operations/reference.js +19 -0
  27. package/dist/sdk/operations/store.d.ts +26 -0
  28. package/dist/sdk/operations/store.js +300 -0
  29. package/dist/sdk/operations/types.d.ts +171 -0
  30. package/dist/sdk/operations/types.js +8 -0
  31. package/dist/sdk/pendingApprovalIdentity.d.ts +35 -0
  32. package/dist/sdk/pendingApprovalIdentity.js +27 -0
  33. package/dist/sdk/permissionDelegation.d.ts +19 -0
  34. package/dist/sdk/permissionDelegation.js +11 -0
  35. package/dist/sdk/query.d.ts +4 -2
  36. package/dist/sdk/query.js +236 -56
  37. package/dist/sdk/queryInput.js +7 -0
  38. package/dist/sdk/queryLifecycle.d.ts +19 -0
  39. package/dist/sdk/queryLifecycle.js +93 -0
  40. package/dist/sdk/queryLifecycleTypes.d.ts +160 -0
  41. package/dist/sdk/queryLifecycleTypes.js +47 -0
  42. package/dist/sdk/runtimeResources.d.ts +197 -0
  43. package/dist/sdk/runtimeResources.js +36 -0
  44. package/dist/sdk/scheduledOccurrenceTypes.d.ts +103 -0
  45. package/dist/sdk/scheduledOccurrenceTypes.js +12 -0
  46. package/dist/sdk/session.d.ts +4 -3
  47. package/dist/sdk/session.js +19 -14
  48. package/dist/sdk/types.d.ts +21 -2
  49. package/docs/README.md +5 -0
  50. package/docs/background-runs.md +229 -0
  51. package/docs/ccl-duo-agent.md +1 -4
  52. package/docs/ccl-ide-usage.md +7 -70
  53. package/docs/cli-installation.md +37 -0
  54. package/docs/command-tool-recovery.md +62 -0
  55. package/docs/dev-quickstart.md +29 -7
  56. package/docs/error-recovery-usage.md +30 -2
  57. package/docs/features/business-facts.md +2 -4
  58. package/docs/hook-input-provenance.md +120 -0
  59. package/docs/index.md +30 -96
  60. package/docs/local-analytics-quickstart.md +11 -28
  61. package/docs/mcp-tool-recovery.md +82 -0
  62. package/docs/operations-client-integration.md +1 -7
  63. package/docs/peer-development-review.md +0 -1
  64. package/docs/releases/1.5.0-alpha.3.md +17 -0
  65. package/docs/releases/1.5.0-alpha.4.md +16 -0
  66. package/docs/releases/1.5.0-alpha.5.md +26 -0
  67. package/docs/releases/1.5.0-alpha.6.md +15 -0
  68. package/docs/releases/1.5.1-alpha.1.md +11 -0
  69. package/docs/releases/1.5.1-alpha.2.md +17 -0
  70. package/docs/releases/1.5.1-alpha.md +22 -0
  71. package/docs/runtime-resources.md +137 -0
  72. package/docs/self-hosted-product-events.md +6 -35
  73. package/docs/shared-skill-resources.md +50 -0
  74. package/examples/background-runs/agents/background-reviewer.md +6 -0
  75. package/examples/background-runs/agents/background-worker.md +6 -0
  76. package/examples/background-runs/worker-reviewer.mjs +42 -0
  77. package/examples/command-recovery/durable-server.mjs +44 -0
  78. package/examples/command-recovery/receipt-command.mjs +40 -0
  79. package/examples/runtime-resources/catalog.ts +68 -0
  80. package/package.json +25 -14
  81. package/sdk/API.md +236 -1
  82. package/sdk/README.md +6 -0
  83. package/docs/agent-owned-error-recovery-ux-2026-10-04.md +0 -146
  84. package/docs/analytics-capabilities-2026-10-08.md +0 -223
  85. package/docs/releases/1.4.5-rc.1.md +0 -39
  86. package/docs/releases/1.4.5-rc.10.md +0 -50
  87. package/docs/releases/1.4.5-rc.2.md +0 -26
  88. package/docs/releases/1.4.5-rc.3.md +0 -9
  89. package/docs/releases/1.4.5-rc.6.md +0 -11
  90. package/docs/releases/1.4.5-rc.7.md +0 -14
  91. package/docs/releases/1.4.5-rc.8.md +0 -18
  92. package/docs/releases/1.4.5-rc.9.md +0 -22
  93. package/docs/releases/1.4.6-beta.0.md +0 -54
  94. package/docs/releases/1.5.0-alpha.0.md +0 -44
@@ -0,0 +1,160 @@
1
+ import { z } from 'zod/v4';
2
+ /** Host observations of one query loop. Neither an authorization nor a business result. */
3
+ export declare const QueryLifecycleSchema: z.ZodObject<{
4
+ version: z.ZodLiteral<1>;
5
+ event_id: z.ZodString;
6
+ query_id: z.ZodString;
7
+ session_id: z.ZodString;
8
+ sequence: z.ZodNumber;
9
+ timestamp: z.ZodString;
10
+ scope: z.ZodEnum<{
11
+ main: "main";
12
+ subagent: "subagent";
13
+ auxiliary: "auxiliary";
14
+ }>;
15
+ agent_id: z.ZodNullable<z.ZodString>;
16
+ phase: z.ZodEnum<{
17
+ start: "start";
18
+ stop_attempt: "stop_attempt";
19
+ stop_failure: "stop_failure";
20
+ terminal: "terminal";
21
+ }>;
22
+ attempt: z.ZodNumber;
23
+ accepted_inputs: z.ZodArray<z.ZodObject<{
24
+ message_id: z.ZodString;
25
+ origin: z.ZodString;
26
+ provenance: z.ZodOptional<z.ZodObject<{
27
+ version: z.ZodLiteral<1>;
28
+ actor: z.ZodEnum<{
29
+ unknown: "unknown";
30
+ agent: "agent";
31
+ human: "human";
32
+ host: "host";
33
+ }>;
34
+ source: z.ZodString;
35
+ session_id: z.ZodOptional<z.ZodString>;
36
+ request_id: z.ZodOptional<z.ZodString>;
37
+ }, z.core.$strip>>;
38
+ }, z.core.$strip>>;
39
+ input_message_ids: z.ZodArray<z.ZodString>;
40
+ input_association: z.ZodEnum<{
41
+ unknown: "unknown";
42
+ known: "known";
43
+ }>;
44
+ last_assistant_message_id: z.ZodNullable<z.ZodString>;
45
+ status: z.ZodNullable<z.ZodEnum<{
46
+ completed: "completed";
47
+ failed: "failed";
48
+ cancelled: "cancelled";
49
+ interrupted: "interrupted";
50
+ stopped: "stopped";
51
+ }>>;
52
+ terminal_reason: z.ZodNullable<z.ZodString>;
53
+ }, z.core.$strip>;
54
+ export type QueryLifecycleRecord = z.infer<typeof QueryLifecycleSchema>;
55
+ export type QueryLifecycleWrite = {
56
+ state: 'saved';
57
+ } | {
58
+ state: 'unavailable';
59
+ reason: 'persistence_disabled' | 'no_transcript';
60
+ } | {
61
+ state: 'failed';
62
+ reason: 'write_failed';
63
+ } | {
64
+ state: 'unknown';
65
+ reason: 'write_timeout';
66
+ };
67
+ export declare const QueryLifecycleWriteSchema: z.ZodUnion<readonly [z.ZodObject<{
68
+ state: z.ZodLiteral<"saved">;
69
+ }, z.core.$strip>, z.ZodObject<{
70
+ state: z.ZodLiteral<"unavailable">;
71
+ reason: z.ZodEnum<{
72
+ persistence_disabled: "persistence_disabled";
73
+ no_transcript: "no_transcript";
74
+ }>;
75
+ }, z.core.$strip>, z.ZodObject<{
76
+ state: z.ZodLiteral<"failed">;
77
+ reason: z.ZodLiteral<"write_failed">;
78
+ }, z.core.$strip>, z.ZodObject<{
79
+ state: z.ZodLiteral<"unknown">;
80
+ reason: z.ZodLiteral<"write_timeout">;
81
+ }, z.core.$strip>]>;
82
+ export type QueryLifecycleObservation = {
83
+ record: QueryLifecycleRecord;
84
+ persistence: QueryLifecycleWrite;
85
+ transcript_path: string | null;
86
+ };
87
+ export declare const QueryLifecycleObservationSchema: z.ZodObject<{
88
+ record: z.ZodObject<{
89
+ version: z.ZodLiteral<1>;
90
+ event_id: z.ZodString;
91
+ query_id: z.ZodString;
92
+ session_id: z.ZodString;
93
+ sequence: z.ZodNumber;
94
+ timestamp: z.ZodString;
95
+ scope: z.ZodEnum<{
96
+ main: "main";
97
+ subagent: "subagent";
98
+ auxiliary: "auxiliary";
99
+ }>;
100
+ agent_id: z.ZodNullable<z.ZodString>;
101
+ phase: z.ZodEnum<{
102
+ start: "start";
103
+ stop_attempt: "stop_attempt";
104
+ stop_failure: "stop_failure";
105
+ terminal: "terminal";
106
+ }>;
107
+ attempt: z.ZodNumber;
108
+ accepted_inputs: z.ZodArray<z.ZodObject<{
109
+ message_id: z.ZodString;
110
+ origin: z.ZodString;
111
+ provenance: z.ZodOptional<z.ZodObject<{
112
+ version: z.ZodLiteral<1>;
113
+ actor: z.ZodEnum<{
114
+ unknown: "unknown";
115
+ agent: "agent";
116
+ human: "human";
117
+ host: "host";
118
+ }>;
119
+ source: z.ZodString;
120
+ session_id: z.ZodOptional<z.ZodString>;
121
+ request_id: z.ZodOptional<z.ZodString>;
122
+ }, z.core.$strip>>;
123
+ }, z.core.$strip>>;
124
+ input_message_ids: z.ZodArray<z.ZodString>;
125
+ input_association: z.ZodEnum<{
126
+ unknown: "unknown";
127
+ known: "known";
128
+ }>;
129
+ last_assistant_message_id: z.ZodNullable<z.ZodString>;
130
+ status: z.ZodNullable<z.ZodEnum<{
131
+ completed: "completed";
132
+ failed: "failed";
133
+ cancelled: "cancelled";
134
+ interrupted: "interrupted";
135
+ stopped: "stopped";
136
+ }>>;
137
+ terminal_reason: z.ZodNullable<z.ZodString>;
138
+ }, z.core.$strip>;
139
+ persistence: z.ZodUnion<readonly [z.ZodObject<{
140
+ state: z.ZodLiteral<"saved">;
141
+ }, z.core.$strip>, z.ZodObject<{
142
+ state: z.ZodLiteral<"unavailable">;
143
+ reason: z.ZodEnum<{
144
+ persistence_disabled: "persistence_disabled";
145
+ no_transcript: "no_transcript";
146
+ }>;
147
+ }, z.core.$strip>, z.ZodObject<{
148
+ state: z.ZodLiteral<"failed">;
149
+ reason: z.ZodLiteral<"write_failed">;
150
+ }, z.core.$strip>, z.ZodObject<{
151
+ state: z.ZodLiteral<"unknown">;
152
+ reason: z.ZodLiteral<"write_timeout">;
153
+ }, z.core.$strip>]>;
154
+ transcript_path: z.ZodNullable<z.ZodString>;
155
+ }, z.core.$strip>;
156
+ /** Metadata entry deliberately has no conversation uuid/parentUuid chain fields. */
157
+ export type QueryLifecycleEntry = {
158
+ type: 'query_lifecycle';
159
+ record: QueryLifecycleRecord;
160
+ };
@@ -0,0 +1,47 @@
1
+ import { z } from 'zod/v4';
2
+ const identity = z.string().min(1).max(256);
3
+ const provenance = z.object({
4
+ version: z.literal(1), actor: z.enum(['human', 'host', 'agent', 'unknown']),
5
+ source: z.string(), session_id: z.string().optional(), request_id: z.string().optional(),
6
+ });
7
+ /** Host observations of one query loop. Neither an authorization nor a business result. */
8
+ export const QueryLifecycleSchema = z.object({
9
+ version: z.literal(1), event_id: identity, query_id: identity, session_id: identity,
10
+ sequence: z.number().int().nonnegative(), timestamp: z.string(),
11
+ scope: z.enum(['main', 'subagent', 'auxiliary']), agent_id: identity.nullable(),
12
+ phase: z.enum(['start', 'stop_attempt', 'stop_failure', 'terminal']),
13
+ attempt: z.number().int().nonnegative(),
14
+ accepted_inputs: z.array(z.object({ message_id: identity, origin: z.string(), provenance: provenance.optional() })),
15
+ // Handed to the host model adapter, not proof of server receipt or understanding.
16
+ input_message_ids: z.array(identity), input_association: z.enum(['known', 'unknown']),
17
+ last_assistant_message_id: identity.nullable(),
18
+ status: z.enum(['completed', 'failed', 'cancelled', 'stopped', 'interrupted']).nullable(),
19
+ terminal_reason: z.string().nullable(),
20
+ }).superRefine((event, ctx) => {
21
+ const invalid = (message) => ctx.addIssue({ code: z.ZodIssueCode.custom, message });
22
+ if ((event.phase === 'terminal') !== (event.status !== null))
23
+ invalid('Only terminal events have a status');
24
+ if (event.phase !== 'terminal' && event.terminal_reason !== null)
25
+ invalid('Only terminal events have a terminal reason');
26
+ const accepted = event.accepted_inputs.map(input => input.message_id);
27
+ if (new Set(accepted).size !== accepted.length)
28
+ invalid('Duplicate accepted input');
29
+ if (new Set(event.input_message_ids).size !== event.input_message_ids.length)
30
+ invalid('Duplicate dispatched input');
31
+ if (event.input_message_ids.some(id => !accepted.includes(id)))
32
+ invalid('Dispatched input was not accepted');
33
+ if (event.phase === 'start' && (event.sequence !== 0 || event.attempt !== 0 || event.input_message_ids.length !== 0))
34
+ invalid('Invalid query start');
35
+ if (event.scope === 'subagent' && event.agent_id === null)
36
+ invalid('Subagent identity missing');
37
+ });
38
+ export const QueryLifecycleWriteSchema = z.union([
39
+ z.object({ state: z.literal('saved') }),
40
+ z.object({ state: z.literal('unavailable'), reason: z.enum(['persistence_disabled', 'no_transcript']) }),
41
+ z.object({ state: z.literal('failed'), reason: z.literal('write_failed') }),
42
+ z.object({ state: z.literal('unknown'), reason: z.literal('write_timeout') }),
43
+ ]);
44
+ export const QueryLifecycleObservationSchema = z.object({
45
+ record: QueryLifecycleSchema, persistence: QueryLifecycleWriteSchema,
46
+ transcript_path: z.string().nullable(),
47
+ });
@@ -0,0 +1,197 @@
1
+ import { z } from 'zod/v4';
2
+ export declare const RuntimeResourceSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
3
+ kind: z.ZodEnum<{
4
+ memory: "memory";
5
+ scratch: "scratch";
6
+ }>;
7
+ scope: z.ZodEnum<{
8
+ shared: "shared";
9
+ session: "session";
10
+ }>;
11
+ lifetime: z.ZodEnum<{
12
+ persistent: "persistent";
13
+ temporary: "temporary";
14
+ }>;
15
+ supported_operations: z.ZodArray<z.ZodEnum<{
16
+ read: "read";
17
+ write: "write";
18
+ }>>;
19
+ status: z.ZodLiteral<"available">;
20
+ path: z.ZodString;
21
+ }, z.core.$strip>, z.ZodObject<{
22
+ kind: z.ZodEnum<{
23
+ memory: "memory";
24
+ scratch: "scratch";
25
+ }>;
26
+ scope: z.ZodEnum<{
27
+ shared: "shared";
28
+ session: "session";
29
+ }>;
30
+ lifetime: z.ZodEnum<{
31
+ persistent: "persistent";
32
+ temporary: "temporary";
33
+ }>;
34
+ supported_operations: z.ZodArray<z.ZodEnum<{
35
+ read: "read";
36
+ write: "write";
37
+ }>>;
38
+ status: z.ZodLiteral<"disabled">;
39
+ reason: z.ZodLiteral<"feature_disabled">;
40
+ }, z.core.$strip>, z.ZodObject<{
41
+ kind: z.ZodEnum<{
42
+ memory: "memory";
43
+ scratch: "scratch";
44
+ }>;
45
+ scope: z.ZodEnum<{
46
+ shared: "shared";
47
+ session: "session";
48
+ }>;
49
+ lifetime: z.ZodEnum<{
50
+ persistent: "persistent";
51
+ temporary: "temporary";
52
+ }>;
53
+ supported_operations: z.ZodArray<z.ZodEnum<{
54
+ read: "read";
55
+ write: "write";
56
+ }>>;
57
+ status: z.ZodLiteral<"unavailable">;
58
+ reason: z.ZodLiteral<"path_unavailable">;
59
+ }, z.core.$strip>]>;
60
+ /** Trusted connection metadata, not a permission grant or authenticated account ID. */
61
+ export declare const RuntimeResourcesSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
62
+ schema_version: z.ZodLiteral<1>;
63
+ runtime_id: z.ZodString;
64
+ snapshot_id: z.ZodString;
65
+ authorization: z.ZodLiteral<"none">;
66
+ status: z.ZodLiteral<"available">;
67
+ context_id: z.ZodString;
68
+ session_id: z.ZodString;
69
+ project_root: z.ZodString;
70
+ original_cwd: z.ZodString;
71
+ cwd: z.ZodString;
72
+ resources: z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
73
+ kind: z.ZodEnum<{
74
+ memory: "memory";
75
+ scratch: "scratch";
76
+ }>;
77
+ scope: z.ZodEnum<{
78
+ shared: "shared";
79
+ session: "session";
80
+ }>;
81
+ lifetime: z.ZodEnum<{
82
+ persistent: "persistent";
83
+ temporary: "temporary";
84
+ }>;
85
+ supported_operations: z.ZodArray<z.ZodEnum<{
86
+ read: "read";
87
+ write: "write";
88
+ }>>;
89
+ status: z.ZodLiteral<"available">;
90
+ path: z.ZodString;
91
+ }, z.core.$strip>, z.ZodObject<{
92
+ kind: z.ZodEnum<{
93
+ memory: "memory";
94
+ scratch: "scratch";
95
+ }>;
96
+ scope: z.ZodEnum<{
97
+ shared: "shared";
98
+ session: "session";
99
+ }>;
100
+ lifetime: z.ZodEnum<{
101
+ persistent: "persistent";
102
+ temporary: "temporary";
103
+ }>;
104
+ supported_operations: z.ZodArray<z.ZodEnum<{
105
+ read: "read";
106
+ write: "write";
107
+ }>>;
108
+ status: z.ZodLiteral<"disabled">;
109
+ reason: z.ZodLiteral<"feature_disabled">;
110
+ }, z.core.$strip>, z.ZodObject<{
111
+ kind: z.ZodEnum<{
112
+ memory: "memory";
113
+ scratch: "scratch";
114
+ }>;
115
+ scope: z.ZodEnum<{
116
+ shared: "shared";
117
+ session: "session";
118
+ }>;
119
+ lifetime: z.ZodEnum<{
120
+ persistent: "persistent";
121
+ temporary: "temporary";
122
+ }>;
123
+ supported_operations: z.ZodArray<z.ZodEnum<{
124
+ read: "read";
125
+ write: "write";
126
+ }>>;
127
+ status: z.ZodLiteral<"unavailable">;
128
+ reason: z.ZodLiteral<"path_unavailable">;
129
+ }, z.core.$strip>]>>;
130
+ }, z.core.$strip>, z.ZodObject<{
131
+ schema_version: z.ZodLiteral<1>;
132
+ runtime_id: z.ZodString;
133
+ snapshot_id: z.ZodString;
134
+ authorization: z.ZodLiteral<"none">;
135
+ status: z.ZodLiteral<"unavailable">;
136
+ reason: z.ZodLiteral<"context_unavailable">;
137
+ resources: z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
138
+ kind: z.ZodEnum<{
139
+ memory: "memory";
140
+ scratch: "scratch";
141
+ }>;
142
+ scope: z.ZodEnum<{
143
+ shared: "shared";
144
+ session: "session";
145
+ }>;
146
+ lifetime: z.ZodEnum<{
147
+ persistent: "persistent";
148
+ temporary: "temporary";
149
+ }>;
150
+ supported_operations: z.ZodArray<z.ZodEnum<{
151
+ read: "read";
152
+ write: "write";
153
+ }>>;
154
+ status: z.ZodLiteral<"available">;
155
+ path: z.ZodString;
156
+ }, z.core.$strip>, z.ZodObject<{
157
+ kind: z.ZodEnum<{
158
+ memory: "memory";
159
+ scratch: "scratch";
160
+ }>;
161
+ scope: z.ZodEnum<{
162
+ shared: "shared";
163
+ session: "session";
164
+ }>;
165
+ lifetime: z.ZodEnum<{
166
+ persistent: "persistent";
167
+ temporary: "temporary";
168
+ }>;
169
+ supported_operations: z.ZodArray<z.ZodEnum<{
170
+ read: "read";
171
+ write: "write";
172
+ }>>;
173
+ status: z.ZodLiteral<"disabled">;
174
+ reason: z.ZodLiteral<"feature_disabled">;
175
+ }, z.core.$strip>, z.ZodObject<{
176
+ kind: z.ZodEnum<{
177
+ memory: "memory";
178
+ scratch: "scratch";
179
+ }>;
180
+ scope: z.ZodEnum<{
181
+ shared: "shared";
182
+ session: "session";
183
+ }>;
184
+ lifetime: z.ZodEnum<{
185
+ persistent: "persistent";
186
+ temporary: "temporary";
187
+ }>;
188
+ supported_operations: z.ZodArray<z.ZodEnum<{
189
+ read: "read";
190
+ write: "write";
191
+ }>>;
192
+ status: z.ZodLiteral<"unavailable">;
193
+ reason: z.ZodLiteral<"path_unavailable">;
194
+ }, z.core.$strip>]>>;
195
+ }, z.core.$strip>]>;
196
+ export type RuntimeResource = z.infer<typeof RuntimeResourceSchema>;
197
+ export type RuntimeResources = z.infer<typeof RuntimeResourcesSchema>;
@@ -0,0 +1,36 @@
1
+ import { z } from 'zod/v4';
2
+ const descriptor = z.object({
3
+ kind: z.enum(['memory', 'scratch']),
4
+ scope: z.enum(['shared', 'session']),
5
+ lifetime: z.enum(['persistent', 'temporary']),
6
+ // Supported file operations, NEVER an authorization decision.
7
+ supported_operations: z.array(z.enum(['read', 'write'])),
8
+ });
9
+ export const RuntimeResourceSchema = z.discriminatedUnion('status', [
10
+ descriptor.extend({ status: z.literal('available'), path: z.string().min(1) }),
11
+ descriptor.extend({ status: z.literal('disabled'), reason: z.literal('feature_disabled') }),
12
+ descriptor.extend({ status: z.literal('unavailable'), reason: z.literal('path_unavailable') }),
13
+ ]);
14
+ const envelope = z.object({
15
+ schema_version: z.literal(1),
16
+ runtime_id: z.string().min(1),
17
+ snapshot_id: z.string().min(1),
18
+ authorization: z.literal('none'),
19
+ });
20
+ /** Trusted connection metadata, not a permission grant or authenticated account ID. */
21
+ export const RuntimeResourcesSchema = z.discriminatedUnion('status', [
22
+ envelope.extend({
23
+ status: z.literal('available'),
24
+ context_id: z.string().min(1),
25
+ session_id: z.string().min(1),
26
+ project_root: z.string().min(1),
27
+ original_cwd: z.string().min(1),
28
+ cwd: z.string().min(1),
29
+ resources: z.array(RuntimeResourceSchema),
30
+ }),
31
+ envelope.extend({
32
+ status: z.literal('unavailable'),
33
+ reason: z.literal('context_unavailable'),
34
+ resources: z.array(RuntimeResourceSchema).length(0),
35
+ }),
36
+ ]);
@@ -0,0 +1,103 @@
1
+ import { z } from 'zod/v4';
2
+ import type { PendingApproval } from './types.js';
3
+ import type { PendingApprovalIdentity } from './pendingApprovalIdentity.js';
4
+ export declare const occurrenceApprovalRequestSchema: z.ZodObject<{
5
+ occurrenceId: z.ZodString;
6
+ expectedRevision: z.ZodNumber;
7
+ requestId: z.ZodString;
8
+ toolUseId: z.ZodString;
9
+ actionId: z.ZodString;
10
+ decision: z.ZodEnum<{
11
+ allow: "allow";
12
+ deny: "deny";
13
+ }>;
14
+ message: z.ZodOptional<z.ZodString>;
15
+ }, z.core.$strict>;
16
+ export type OccurrenceApprovalRequest = z.infer<typeof occurrenceApprovalRequestSchema>;
17
+ export type OccurrenceExecution = 'queued' | 'resuming' | 'running' | 'succeeded' | 'denied' | 'failed' | 'interrupted' | 'waiting_permission' | 'missed' | 'cancelled';
18
+ export type OccurrenceApprovalReceipt = {
19
+ request: OccurrenceApprovalRequest;
20
+ approval: PendingApprovalIdentity;
21
+ originalApproval: PendingApproval;
22
+ acceptedAt: number;
23
+ outcome: 'accepted' | 'running' | 'succeeded' | 'denied' | 'waiting_permission' | 'failed' | 'interrupted';
24
+ completedAt?: number;
25
+ resumedRequestId?: string;
26
+ resumedToolUseId?: string;
27
+ error?: string;
28
+ };
29
+ export type OccurrenceEvent = {
30
+ sequence: number;
31
+ at: number;
32
+ revision: number;
33
+ kind: OccurrenceExecution | 'resume_requested' | 'coalesced' | 'delivery_updated' | 'cancel_requested';
34
+ execution: OccurrenceExecution;
35
+ requestId?: string;
36
+ toolUseId?: string;
37
+ };
38
+ export type ScheduledOccurrence = {
39
+ id: string;
40
+ task: {
41
+ id: string;
42
+ createdAt: number;
43
+ prompt: string;
44
+ delegation?: {
45
+ revision: number;
46
+ sourceSessionId: string;
47
+ };
48
+ };
49
+ scheduledAt: number;
50
+ acceptedAt: number;
51
+ revision: number;
52
+ execution: OccurrenceExecution;
53
+ delivery: 'pending' | 'delivered' | 'failed';
54
+ sessionId?: string;
55
+ result?: string;
56
+ error?: string;
57
+ deliveryError?: string;
58
+ skippedOccurrences?: number;
59
+ coalescedThrough?: number;
60
+ delegationRevision?: number;
61
+ pendingPermission?: {
62
+ revision: number;
63
+ approval: PendingApproval;
64
+ };
65
+ approvalRecoveryError?: string;
66
+ cancellation?: {
67
+ request: OccurrenceCancelRequest;
68
+ requestedAt: number;
69
+ };
70
+ approvalDecisions: OccurrenceApprovalReceipt[];
71
+ events: OccurrenceEvent[];
72
+ };
73
+ export type OccurrenceLookup = {
74
+ status: 'not_found';
75
+ ownerAvailable: boolean;
76
+ } | {
77
+ status: 'found';
78
+ snapshot: ScheduledOccurrence;
79
+ ownerAvailable: boolean;
80
+ };
81
+ export type OccurrenceEvents = {
82
+ events: OccurrenceEvent[];
83
+ nextSequence: number;
84
+ hasMore: boolean;
85
+ };
86
+ export declare const occurrenceSelectorSchema: z.ZodObject<{
87
+ occurrenceId: z.ZodString;
88
+ }, z.core.$strict>;
89
+ export declare const occurrenceListSchema: z.ZodObject<{
90
+ taskId: z.ZodOptional<z.ZodString>;
91
+ sourceSessionId: z.ZodOptional<z.ZodString>;
92
+ }, z.core.$strict>;
93
+ export declare const occurrenceEventsSchema: z.ZodObject<{
94
+ occurrenceId: z.ZodString;
95
+ afterSequence: z.ZodOptional<z.ZodNumber>;
96
+ limit: z.ZodOptional<z.ZodNumber>;
97
+ }, z.core.$strict>;
98
+ export declare const occurrenceCancelRequestSchema: z.ZodObject<{
99
+ occurrenceId: z.ZodString;
100
+ expectedRevision: z.ZodNumber;
101
+ actionId: z.ZodString;
102
+ }, z.core.$strict>;
103
+ export type OccurrenceCancelRequest = z.infer<typeof occurrenceCancelRequestSchema>;
@@ -0,0 +1,12 @@
1
+ import { z } from 'zod/v4';
2
+ export const occurrenceApprovalRequestSchema = z.strictObject({
3
+ occurrenceId: z.string().regex(/^[a-f0-9]{64}$/),
4
+ expectedRevision: z.number().int().nonnegative(),
5
+ requestId: z.string().min(1), toolUseId: z.string().min(1),
6
+ actionId: z.string().min(1).max(200), decision: z.enum(['allow', 'deny']),
7
+ message: z.string().optional(),
8
+ });
9
+ export const occurrenceSelectorSchema = z.strictObject({ occurrenceId: z.string().regex(/^[a-f0-9]{64}$/) });
10
+ export const occurrenceListSchema = z.strictObject({ taskId: z.string().min(1).optional(), sourceSessionId: z.string().min(1).optional() });
11
+ export const occurrenceEventsSchema = occurrenceSelectorSchema.extend({ afterSequence: z.number().int().nonnegative().optional(), limit: z.number().int().min(1).max(1000).optional() });
12
+ export const occurrenceCancelRequestSchema = occurrenceSelectorSchema.extend({ expectedRevision: z.number().int().nonnegative(), actionId: z.string().min(1).max(200) });
@@ -17,6 +17,7 @@ export interface Turn {
17
17
  readonly result: Promise<TurnResult>;
18
18
  cancel(): Promise<void>;
19
19
  }
20
+ export type InputMetadata = Pick<SDKUserMessage, 'isSynthetic' | 'input_provenance'>;
20
21
  /** One CLI process, sequential turns, and a bounded host-side input queue. */
21
22
  export declare class Session {
22
23
  readonly pid: number | undefined;
@@ -34,10 +35,10 @@ export declare class Session {
34
35
  private readonly pumping;
35
36
  private sessionId?;
36
37
  constructor(options?: SessionOptions, transport?: Transport);
37
- prompt(content: SDKUserMessage['message']['content']): Turn;
38
- followUp(content: SDKUserMessage['message']['content']): Turn;
38
+ prompt(content: SDKUserMessage['message']['content'], metadata?: InputMetadata): Turn;
39
+ followUp(content: SDKUserMessage['message']['content'], metadata?: InputMetadata): Turn;
39
40
  /** Interrupt the active turn; correction runs before queued follow-ups. */
40
- steer(content: SDKUserMessage['message']['content']): Turn;
41
+ steer(content: SDKUserMessage['message']['content'], metadata?: InputMetadata): Turn;
41
42
  private enqueue;
42
43
  private inputs;
43
44
  private consume;
@@ -1,6 +1,7 @@
1
1
  import { randomUUID } from 'node:crypto';
2
2
  import { queryHandleWithTransport } from './queryHandle.js';
3
3
  import { spawnForOptions } from './query.js';
4
+ import { normalizeUserInput } from './queryInput.js';
4
5
  /** One CLI process, sequential turns, and a bounded host-side input queue. */
5
6
  export class Session {
6
7
  pid;
@@ -28,37 +29,40 @@ export class Session {
28
29
  this.sessionId = options.sessionId ?? options.resume;
29
30
  const owned = transport ?? spawnForOptions(options);
30
31
  this.pid = owned.pid;
32
+ const transportWithLifecycle = { ...owned, write: async (message) => {
33
+ await owned.write(message);
34
+ if (message.type === 'user' && this.active && !this.active.started) {
35
+ this.active.started = true;
36
+ this.observe({ type: 'turn_started', turnId: this.active.turn.id });
37
+ }
38
+ } };
31
39
  this.handle = queryHandleWithTransport(this.inputs(), { ...options, hooks: {
32
40
  ...options.hooks,
33
41
  onUserPromptSubmit: async (event) => {
34
- if (this.active && !this.active.started) {
35
- this.active.started = true;
36
- this.observe({ type: 'turn_started', turnId: this.active.turn.id });
37
- }
38
42
  await options.hooks?.onUserPromptSubmit?.(event);
39
43
  },
40
44
  onSessionStart: async (event) => {
41
45
  this.sessionId = event.sessionId;
42
46
  await options.hooks?.onSessionStart?.(event);
43
47
  },
44
- } }, owned);
48
+ } }, transportWithLifecycle);
45
49
  this.controls = this.handle;
46
50
  this.pumping = this.consume();
47
51
  }
48
- prompt(content) {
49
- return this.enqueue(content, false);
52
+ prompt(content, metadata = {}) {
53
+ return this.enqueue(content, false, metadata);
50
54
  }
51
- followUp(content) {
52
- return this.enqueue(content, false);
55
+ followUp(content, metadata = {}) {
56
+ return this.enqueue(content, false, metadata);
53
57
  }
54
58
  /** Interrupt the active turn; correction runs before queued follow-ups. */
55
- steer(content) {
56
- const turn = this.enqueue(content, true);
59
+ steer(content, metadata = {}) {
60
+ const turn = this.enqueue(content, true, metadata);
57
61
  if (this.active)
58
62
  void this.interrupt().catch(error => this.fail(error));
59
63
  return turn;
60
64
  }
61
- enqueue(content, priority) {
65
+ enqueue(content, priority, metadata) {
62
66
  if (!this.accepting || this.closed)
63
67
  throw new Error('ccl-sdk: session input is closed');
64
68
  if (this.queue.length + (this.active ? 1 : 0) >= this.limit) {
@@ -71,9 +75,10 @@ export class Session {
71
75
  // It is valid to enqueue follow-ups and observe their results later.
72
76
  void result.catch(() => { });
73
77
  const turn = { id, result, cancel: () => this.cancel(id) };
74
- const entry = { turn, resolve, reject, input: {
78
+ const entry = { turn, resolve, reject, input: normalizeUserInput({
75
79
  type: 'user', uuid: id, message: { role: 'user', content },
76
- } };
80
+ isSynthetic: metadata.isSynthetic, input_provenance: metadata.input_provenance,
81
+ }) };
77
82
  if (priority)
78
83
  this.queue.unshift(entry);
79
84
  else