@a5c-ai/babysitter-sdk 0.0.187-staging.c834693f → 0.0.187-staging.cbd8dccc

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 (111) hide show
  1. package/dist/api/effects.d.ts +87 -0
  2. package/dist/api/effects.d.ts.map +1 -0
  3. package/dist/api/effects.js +329 -0
  4. package/dist/api/index.d.ts +5 -0
  5. package/dist/api/index.d.ts.map +1 -0
  6. package/dist/api/index.js +14 -0
  7. package/dist/api/runs.d.ts +86 -0
  8. package/dist/api/runs.d.ts.map +1 -0
  9. package/dist/api/runs.js +253 -0
  10. package/dist/cli/commandRegistry.d.ts.map +1 -1
  11. package/dist/cli/commandRegistry.js +1 -0
  12. package/dist/cli/commands/runIterate.d.ts +13 -0
  13. package/dist/cli/commands/runIterate.d.ts.map +1 -1
  14. package/dist/cli/commands/runIterate.js +21 -0
  15. package/dist/cli/commands/sessionHistory.d.ts +14 -0
  16. package/dist/cli/commands/sessionHistory.d.ts.map +1 -0
  17. package/dist/cli/commands/sessionHistory.js +82 -0
  18. package/dist/cli/commands/tui.d.ts.map +1 -1
  19. package/dist/cli/commands/tui.js +2 -0
  20. package/dist/cli/main.d.ts.map +1 -1
  21. package/dist/cli/main.js +14 -1
  22. package/dist/dashboard/ink/App.d.ts +1 -1
  23. package/dist/dashboard/ink/App.d.ts.map +1 -1
  24. package/dist/dashboard/ink/App.js +22 -8
  25. package/dist/dashboard/ink/components/Message.d.ts.map +1 -1
  26. package/dist/dashboard/ink/components/Message.js +2 -21
  27. package/dist/dashboard/ink/components/MessagePane.d.ts +3 -0
  28. package/dist/dashboard/ink/components/MessagePane.d.ts.map +1 -1
  29. package/dist/dashboard/ink/components/MessagePane.js +6 -4
  30. package/dist/dashboard/ink/components/PromptBar.d.ts +7 -0
  31. package/dist/dashboard/ink/components/PromptBar.d.ts.map +1 -1
  32. package/dist/dashboard/ink/components/PromptBar.js +32 -3
  33. package/dist/dashboard/ink/components/RunListTable.d.ts +10 -0
  34. package/dist/dashboard/ink/components/RunListTable.d.ts.map +1 -1
  35. package/dist/dashboard/ink/components/RunListTable.js +11 -4
  36. package/dist/dashboard/ink/components/StatusBar.d.ts +12 -0
  37. package/dist/dashboard/ink/components/StatusBar.d.ts.map +1 -1
  38. package/dist/dashboard/ink/components/StatusBar.js +17 -7
  39. package/dist/dashboard/ink/components/StatusLine.d.ts +30 -0
  40. package/dist/dashboard/ink/components/StatusLine.d.ts.map +1 -0
  41. package/dist/dashboard/ink/components/StatusLine.js +122 -0
  42. package/dist/dashboard/ink/components/index.d.ts +3 -0
  43. package/dist/dashboard/ink/components/index.d.ts.map +1 -1
  44. package/dist/dashboard/ink/components/index.js +19 -1
  45. package/dist/dashboard/ink/components/primitives/BorderBox.d.ts +47 -0
  46. package/dist/dashboard/ink/components/primitives/BorderBox.d.ts.map +1 -0
  47. package/dist/dashboard/ink/components/primitives/BorderBox.js +107 -0
  48. package/dist/dashboard/ink/components/primitives/ProgressBar.d.ts +25 -0
  49. package/dist/dashboard/ink/components/primitives/ProgressBar.d.ts.map +1 -0
  50. package/dist/dashboard/ink/components/primitives/ProgressBar.js +55 -0
  51. package/dist/dashboard/ink/components/primitives/Tree.d.ts +27 -0
  52. package/dist/dashboard/ink/components/primitives/Tree.d.ts.map +1 -0
  53. package/dist/dashboard/ink/components/primitives/Tree.js +73 -0
  54. package/dist/dashboard/ink/components/primitives/index.d.ts +10 -0
  55. package/dist/dashboard/ink/components/primitives/index.d.ts.map +1 -0
  56. package/dist/dashboard/ink/components/primitives/index.js +16 -0
  57. package/dist/dashboard/ink/contexts/ChatContext.d.ts +33 -0
  58. package/dist/dashboard/ink/contexts/ChatContext.d.ts.map +1 -0
  59. package/dist/dashboard/ink/contexts/ChatContext.js +105 -0
  60. package/dist/dashboard/ink/helpers.d.ts +238 -0
  61. package/dist/dashboard/ink/helpers.d.ts.map +1 -0
  62. package/dist/dashboard/ink/helpers.js +710 -0
  63. package/dist/dashboard/ink/hooks/useChat.d.ts +6 -0
  64. package/dist/dashboard/ink/hooks/useChat.d.ts.map +1 -0
  65. package/dist/dashboard/ink/hooks/useChat.js +8 -0
  66. package/dist/dashboard/ink/index.d.ts +18 -1
  67. package/dist/dashboard/ink/index.d.ts.map +1 -1
  68. package/dist/dashboard/ink/index.js +74 -1
  69. package/dist/dashboard/ink/types.d.ts +58 -0
  70. package/dist/dashboard/ink/types.d.ts.map +1 -1
  71. package/dist/dashboard/ink/views/DashboardView.d.ts.map +1 -1
  72. package/dist/dashboard/ink/views/DashboardView.js +6 -0
  73. package/dist/dashboard/ink/views/SessionView.d.ts +6 -4
  74. package/dist/dashboard/ink/views/SessionView.d.ts.map +1 -1
  75. package/dist/dashboard/ink/views/SessionView.js +186 -12
  76. package/dist/harness/internal.d.ts.map +1 -1
  77. package/dist/harness/internal.js +10 -2
  78. package/dist/harness/types.d.ts +7 -1
  79. package/dist/harness/types.d.ts.map +1 -1
  80. package/dist/harness/types.js +6 -0
  81. package/dist/index.d.ts +1 -0
  82. package/dist/index.d.ts.map +1 -1
  83. package/dist/index.js +1 -0
  84. package/dist/mcp/tools/runs.d.ts.map +1 -1
  85. package/dist/mcp/tools/runs.js +50 -94
  86. package/dist/prompts/compose.d.ts.map +1 -1
  87. package/dist/prompts/compose.js +2 -0
  88. package/dist/prompts/context.d.ts +8 -0
  89. package/dist/prompts/context.d.ts.map +1 -1
  90. package/dist/prompts/context.js +41 -0
  91. package/dist/prompts/parts/index.d.ts +1 -0
  92. package/dist/prompts/parts/index.d.ts.map +1 -1
  93. package/dist/prompts/parts/index.js +3 -1
  94. package/dist/prompts/parts/parallelDispatch.d.ts +15 -0
  95. package/dist/prompts/parts/parallelDispatch.d.ts.map +1 -0
  96. package/dist/prompts/parts/parallelDispatch.js +46 -0
  97. package/dist/prompts/strata.d.ts.map +1 -1
  98. package/dist/prompts/strata.js +1 -0
  99. package/dist/runtime/createRun.js +1 -1
  100. package/dist/session/history.d.ts +30 -0
  101. package/dist/session/history.d.ts.map +1 -0
  102. package/dist/session/history.js +143 -0
  103. package/dist/session/index.d.ts +2 -1
  104. package/dist/session/index.d.ts.map +1 -1
  105. package/dist/session/index.js +8 -1
  106. package/dist/session/types.d.ts +49 -0
  107. package/dist/session/types.d.ts.map +1 -1
  108. package/dist/storage/createRunDir.js +1 -1
  109. package/dist/storage/types.d.ts +1 -1
  110. package/dist/storage/types.d.ts.map +1 -1
  111. package/package.json +1 -1
@@ -0,0 +1,87 @@
1
+ /**
2
+ * GAP-JSON-002: Effect Dispatch and Response Protocol.
3
+ *
4
+ * Typed API wrappers for listing, showing, cancelling, and batch-committing
5
+ * effects. All functions return ApiResult envelopes and never throw.
6
+ */
7
+ import type { ApiResult } from "./runs";
8
+ import type { JsonRecord } from "../storage/types";
9
+ type EffectStatusFilter = "requested" | "resolved" | "cancelled";
10
+ type EffectStatusOutput = "requested" | "resolved_ok" | "resolved_error" | "cancelled";
11
+ export interface ListEffectsInput {
12
+ runDir: string;
13
+ filter?: {
14
+ kind?: string | string[];
15
+ status?: EffectStatusFilter;
16
+ };
17
+ }
18
+ export interface EffectSummary {
19
+ effectId: string;
20
+ kind?: string;
21
+ status: EffectStatusOutput;
22
+ taskId?: string;
23
+ labels?: string[];
24
+ requestedAt?: string;
25
+ resolvedAt?: string;
26
+ }
27
+ export interface ListEffectsOutput {
28
+ effects: EffectSummary[];
29
+ }
30
+ export interface ShowEffectInput {
31
+ runDir: string;
32
+ effectId: string;
33
+ }
34
+ export interface ShowEffectOutput {
35
+ effectId: string;
36
+ kind?: string;
37
+ status: EffectStatusOutput;
38
+ taskId?: string;
39
+ labels?: string[];
40
+ requestedAt?: string;
41
+ resolvedAt?: string;
42
+ taskDefinition?: JsonRecord;
43
+ result?: unknown;
44
+ autoApproval?: unknown;
45
+ }
46
+ export interface CancelEffectInput {
47
+ runDir: string;
48
+ effectId: string;
49
+ reason?: string;
50
+ }
51
+ export interface CancelEffectOutput {
52
+ resultRef: string;
53
+ }
54
+ export interface BatchCommitEffectEntry {
55
+ effectId: string;
56
+ result: {
57
+ status: "ok" | "error";
58
+ value?: unknown;
59
+ error?: string;
60
+ stdout?: string;
61
+ stderr?: string;
62
+ stdoutRef?: string;
63
+ stderrRef?: string;
64
+ startedAt?: string;
65
+ finishedAt?: string;
66
+ metadata?: JsonRecord;
67
+ };
68
+ }
69
+ export interface BatchCommitEffectsInput {
70
+ runDir: string;
71
+ effects: BatchCommitEffectEntry[];
72
+ }
73
+ export interface BatchCommitEffectResult {
74
+ effectId: string;
75
+ ok: boolean;
76
+ resultRef?: string;
77
+ error?: string;
78
+ }
79
+ export interface BatchCommitEffectsOutput {
80
+ results: BatchCommitEffectResult[];
81
+ }
82
+ export declare function apiListEffects(input: ListEffectsInput): Promise<ApiResult<ListEffectsOutput>>;
83
+ export declare function apiShowEffect(input: ShowEffectInput): Promise<ApiResult<ShowEffectOutput>>;
84
+ export declare function apiCancelEffect(input: CancelEffectInput): Promise<ApiResult<CancelEffectOutput>>;
85
+ export declare function apiBatchCommitEffects(input: BatchCommitEffectsInput): Promise<ApiResult<BatchCommitEffectsOutput>>;
86
+ export {};
87
+ //# sourceMappingURL=effects.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"effects.d.ts","sourceRoot":"","sources":["../../src/api/effects.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAOH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AACxC,OAAO,KAAK,EAAgB,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAuBjE,KAAK,kBAAkB,GAAG,WAAW,GAAG,UAAU,GAAG,WAAW,CAAC;AACjE,KAAK,kBAAkB,GAAG,WAAW,GAAG,aAAa,GAAG,gBAAgB,GAAG,WAAW,CAAC;AAEvF,MAAM,WAAW,gBAAgB;IAC/B,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE;QACP,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;QACzB,MAAM,CAAC,E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,MAAM,CAAC;QACf,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,UAAU,CAAC,EAAE,MAAM,CAAC;QACpB,QAAQ,CAAC,EAAE,UAAU,CAAC;KACvB,CAAC;CACH;AAED,MAAM,WAAW,uBAAuB;IACtC,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,sBAAsB,EAAE,CAAC;CACnC;AAED,MAAM,WAAW,uBAAuB;IACtC,QAAQ,EAAE,MAAM,CAAC;IACjB,EAAE,EAAE,OAAO,CAAC;IACZ,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,wBAAwB;IACvC,OAAO,EAAE,uBAAuB,EAAE,CAAC;CACpC;AAyDD,wBAAsB,cAAc,CAClC,KAAK,EAAE,gBAAgB,GACtB,OAAO,CAAC,SAAS,CAAC,iBAAiB,CAAC,CAAC,CAiDvC;AAED,wBAAsB,aAAa,CACjC,KAAK,EAAE,eAAe,GACrB,OAAO,CAAC,SAAS,CAAC,gBAAgB,CAAC,CAAC,CA0DtC;AAED,wBAAsB,eAAe,CACnC,KAAK,EAAE,iBAAiB,GACvB,OAAO,CAAC,SAAS,CAAC,kBAAkB,CAAC,CAAC,CA8DxC;AAED,wBAAsB,qBAAqB,CACzC,KAAK,EAAE,uBAAuB,GAC7B,OAAO,CAAC,SAAS,CAAC,wBAAwB,CAAC,CAAC,CA8G9C"}
@@ -0,0 +1,329 @@
1
+ "use strict";
2
+ /**
3
+ * GAP-JSON-002: Effect Dispatch and Response Protocol.
4
+ *
5
+ * Typed API wrappers for listing, showing, cancelling, and batch-committing
6
+ * effects. All functions return ApiResult envelopes and never throw.
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.apiListEffects = apiListEffects;
10
+ exports.apiShowEffect = apiShowEffect;
11
+ exports.apiCancelEffect = apiCancelEffect;
12
+ exports.apiBatchCommitEffects = apiBatchCommitEffects;
13
+ const fs_1 = require("fs");
14
+ const journal_1 = require("../storage/journal");
15
+ const tasks_1 = require("../storage/tasks");
16
+ const lock_1 = require("../storage/lock");
17
+ const serializer_1 = require("../tasks/serializer");
18
+ // ── Result envelope helpers (mirror runs.ts) ───────────────────────────────
19
+ function ok(data) {
20
+ return { ok: true, data };
21
+ }
22
+ function fail(code, message) {
23
+ return { ok: false, error: { code, message } };
24
+ }
25
+ async function pathExists(p) {
26
+ try {
27
+ await fs_1.promises.access(p);
28
+ return true;
29
+ }
30
+ catch {
31
+ return false;
32
+ }
33
+ }
34
+ function buildEffectInfoMap(events) {
35
+ const effects = new Map();
36
+ for (const event of events) {
37
+ if (event.type === "EFFECT_REQUESTED") {
38
+ const data = event.data;
39
+ const effectId = data.effectId;
40
+ if (!effectId)
41
+ continue;
42
+ effects.set(effectId, {
43
+ effectId,
44
+ kind: typeof data.kind === "string" ? data.kind : undefined,
45
+ taskId: typeof data.taskId === "string" ? data.taskId : undefined,
46
+ labels: Array.isArray(data.labels) ? data.labels : undefined,
47
+ status: "requested",
48
+ requestedAt: event.recordedAt,
49
+ });
50
+ }
51
+ else if (event.type === "EFFECT_RESOLVED") {
52
+ const data = event.data;
53
+ const effectId = data.effectId;
54
+ if (!effectId)
55
+ continue;
56
+ const existing = effects.get(effectId);
57
+ if (existing) {
58
+ const resultStatus = data.status;
59
+ existing.status = resultStatus === "error" ? "resolved_error" : "resolved_ok";
60
+ existing.resolvedAt = event.recordedAt;
61
+ }
62
+ }
63
+ else if (event.type === "EFFECT_CANCELLED") {
64
+ const data = event.data;
65
+ const effectId = data.effectId;
66
+ if (!effectId)
67
+ continue;
68
+ const existing = effects.get(effectId);
69
+ if (existing) {
70
+ existing.status = "cancelled";
71
+ existing.resolvedAt = event.recordedAt;
72
+ }
73
+ }
74
+ }
75
+ return effects;
76
+ }
77
+ // ── API functions ──────────────────────────────────────────────────────────
78
+ async function apiListEffects(input) {
79
+ try {
80
+ if (!input.runDir) {
81
+ return fail("INVALID_INPUT", "runDir must be a non-empty string");
82
+ }
83
+ if (!(await pathExists(input.runDir))) {
84
+ return fail("RUN_NOT_FOUND", `Run directory not found: ${input.runDir}`);
85
+ }
86
+ const events = await (0, journal_1.loadJournal)(input.runDir);
87
+ const effectMap = buildEffectInfoMap(events);
88
+ let effects = Array.from(effectMap.values());
89
+ // Apply filters
90
+ if (input.filter) {
91
+ if (input.filter.kind !== undefined) {
92
+ const kinds = Array.isArray(input.filter.kind) ? input.filter.kind : [input.filter.kind];
93
+ effects = effects.filter((e) => e.kind !== undefined && kinds.includes(e.kind));
94
+ }
95
+ if (input.filter.status !== undefined) {
96
+ const statusFilter = input.filter.status;
97
+ effects = effects.filter((e) => {
98
+ if (statusFilter === "requested")
99
+ return e.status === "requested";
100
+ if (statusFilter === "resolved")
101
+ return e.status === "resolved_ok" || e.status === "resolved_error";
102
+ if (statusFilter === "cancelled")
103
+ return e.status === "cancelled";
104
+ return true;
105
+ });
106
+ }
107
+ }
108
+ // Sort by effectId ascending
109
+ effects.sort((a, b) => a.effectId.localeCompare(b.effectId));
110
+ return ok({
111
+ effects: effects.map((e) => ({
112
+ effectId: e.effectId,
113
+ kind: e.kind,
114
+ status: e.status,
115
+ taskId: e.taskId,
116
+ labels: e.labels,
117
+ requestedAt: e.requestedAt,
118
+ resolvedAt: e.resolvedAt,
119
+ })),
120
+ });
121
+ }
122
+ catch (error) {
123
+ const msg = error instanceof Error ? error.message : String(error);
124
+ return fail("INTERNAL_ERROR", msg);
125
+ }
126
+ }
127
+ async function apiShowEffect(input) {
128
+ try {
129
+ if (!input.runDir) {
130
+ return fail("INVALID_INPUT", "runDir must be a non-empty string");
131
+ }
132
+ if (!input.effectId) {
133
+ return fail("INVALID_INPUT", "effectId must be a non-empty string");
134
+ }
135
+ if (!(await pathExists(input.runDir))) {
136
+ return fail("RUN_NOT_FOUND", `Run directory not found: ${input.runDir}`);
137
+ }
138
+ const events = await (0, journal_1.loadJournal)(input.runDir);
139
+ const effectMap = buildEffectInfoMap(events);
140
+ const info = effectMap.get(input.effectId);
141
+ if (!info) {
142
+ return fail("EFFECT_NOT_FOUND", `Effect not found: ${input.effectId}`);
143
+ }
144
+ // Read task definition
145
+ const taskDef = await (0, tasks_1.readTaskDefinition)(input.runDir, input.effectId);
146
+ // Read result if resolved
147
+ let resultData = null;
148
+ if (info.status === "resolved_ok" || info.status === "resolved_error") {
149
+ const storedResult = await (0, tasks_1.readTaskResult)(input.runDir, input.effectId);
150
+ resultData = storedResult ?? null;
151
+ }
152
+ const output = {
153
+ effectId: info.effectId,
154
+ kind: info.kind,
155
+ status: info.status,
156
+ taskId: info.taskId,
157
+ labels: info.labels,
158
+ requestedAt: info.requestedAt,
159
+ resolvedAt: info.resolvedAt,
160
+ taskDefinition: taskDef ?? undefined,
161
+ result: resultData === null ? undefined : resultData,
162
+ };
163
+ // Include autoApproval for breakpoint effects
164
+ if (info.kind === "breakpoint" || info.taskId === "__sdk.breakpoint") {
165
+ if (taskDef && typeof taskDef === "object") {
166
+ const autoApproval = taskDef.autoApproval;
167
+ if (autoApproval !== undefined) {
168
+ output.autoApproval = autoApproval;
169
+ }
170
+ }
171
+ }
172
+ return ok(output);
173
+ }
174
+ catch (error) {
175
+ const msg = error instanceof Error ? error.message : String(error);
176
+ return fail("INTERNAL_ERROR", msg);
177
+ }
178
+ }
179
+ async function apiCancelEffect(input) {
180
+ try {
181
+ if (!input.runDir) {
182
+ return fail("INVALID_INPUT", "runDir must be a non-empty string");
183
+ }
184
+ if (!input.effectId) {
185
+ return fail("INVALID_INPUT", "effectId must be a non-empty string");
186
+ }
187
+ if (!(await pathExists(input.runDir))) {
188
+ return fail("RUN_NOT_FOUND", `Run directory not found: ${input.runDir}`);
189
+ }
190
+ return await (0, lock_1.withRunLock)(input.runDir, "api:cancelEffect", async () => {
191
+ const events = await (0, journal_1.loadJournal)(input.runDir);
192
+ const effectMap = buildEffectInfoMap(events);
193
+ const info = effectMap.get(input.effectId);
194
+ if (!info) {
195
+ return fail("EFFECT_NOT_FOUND", `Effect not found: ${input.effectId}`);
196
+ }
197
+ if (info.status !== "requested") {
198
+ return fail("EFFECT_NOT_PENDING", `Effect ${input.effectId} is not pending (status=${info.status})`);
199
+ }
200
+ // Extract taskId and invocationKey from the EFFECT_REQUESTED event
201
+ const requestedEvent = events.find((e) => e.type === "EFFECT_REQUESTED" && e.data.effectId === input.effectId);
202
+ const eventData = requestedEvent?.data;
203
+ const taskId = eventData?.taskId ?? `task-${input.effectId}`;
204
+ const invocationKey = eventData?.invocationKey ?? `key-${input.effectId}`;
205
+ const { resultRef } = await (0, serializer_1.serializeAndWriteTaskResult)({
206
+ runDir: input.runDir,
207
+ effectId: input.effectId,
208
+ taskId,
209
+ invocationKey,
210
+ payload: {
211
+ status: "cancelled",
212
+ reason: input.reason,
213
+ error: { name: "EffectCancelledError", message: input.reason ?? "Effect cancelled" },
214
+ metadata: { cancelled: true, reason: input.reason },
215
+ },
216
+ });
217
+ await (0, journal_1.appendEvent)({
218
+ runDir: input.runDir,
219
+ eventType: "EFFECT_CANCELLED",
220
+ event: {
221
+ effectId: input.effectId,
222
+ reason: input.reason,
223
+ },
224
+ });
225
+ return ok({ resultRef });
226
+ });
227
+ }
228
+ catch (error) {
229
+ const msg = error instanceof Error ? error.message : String(error);
230
+ return fail("INTERNAL_ERROR", msg);
231
+ }
232
+ }
233
+ async function apiBatchCommitEffects(input) {
234
+ try {
235
+ if (!input.runDir) {
236
+ return fail("INVALID_INPUT", "runDir must be a non-empty string");
237
+ }
238
+ if (!Array.isArray(input.effects)) {
239
+ return fail("INVALID_INPUT", "effects must be an array");
240
+ }
241
+ if (input.effects.length === 0) {
242
+ return fail("INVALID_INPUT", "effects array must not be empty");
243
+ }
244
+ const results = [];
245
+ for (const entry of input.effects) {
246
+ try {
247
+ const commitResult = await (0, lock_1.withRunLock)(input.runDir, "api:batchCommitEffect", async () => {
248
+ // Load journal to find the effect metadata
249
+ const events = await (0, journal_1.loadJournal)(input.runDir);
250
+ const requestedEvent = events.find((e) => e.type === "EFFECT_REQUESTED" && e.data.effectId === entry.effectId);
251
+ if (!requestedEvent) {
252
+ throw new Error(`Unknown effectId ${entry.effectId}`);
253
+ }
254
+ const eventData = requestedEvent.data;
255
+ const taskId = eventData.taskId ?? `task-${entry.effectId}`;
256
+ const invocationKey = eventData.invocationKey ?? `key-${entry.effectId}`;
257
+ // Check if already resolved
258
+ const alreadyResolved = events.some((e) => (e.type === "EFFECT_RESOLVED" || e.type === "EFFECT_CANCELLED") &&
259
+ e.data.effectId === entry.effectId);
260
+ if (alreadyResolved) {
261
+ throw new Error(`Effect ${entry.effectId} is already resolved`);
262
+ }
263
+ const resultPayload = entry.result.status === "ok"
264
+ ? {
265
+ status: "ok",
266
+ result: entry.result.value,
267
+ stdout: entry.result.stdout,
268
+ stderr: entry.result.stderr,
269
+ stdoutRef: entry.result.stdoutRef,
270
+ stderrRef: entry.result.stderrRef,
271
+ startedAt: entry.result.startedAt,
272
+ finishedAt: entry.result.finishedAt,
273
+ metadata: entry.result.metadata,
274
+ }
275
+ : {
276
+ status: "error",
277
+ error: { name: "Error", message: entry.result.error ?? "Unknown error" },
278
+ stdout: entry.result.stdout,
279
+ stderr: entry.result.stderr,
280
+ stdoutRef: entry.result.stdoutRef,
281
+ stderrRef: entry.result.stderrRef,
282
+ startedAt: entry.result.startedAt,
283
+ finishedAt: entry.result.finishedAt,
284
+ metadata: entry.result.metadata,
285
+ };
286
+ const { resultRef, stdoutRef, stderrRef } = await (0, serializer_1.serializeAndWriteTaskResult)({
287
+ runDir: input.runDir,
288
+ effectId: entry.effectId,
289
+ taskId,
290
+ invocationKey,
291
+ payload: resultPayload,
292
+ });
293
+ await (0, journal_1.appendEvent)({
294
+ runDir: input.runDir,
295
+ eventType: "EFFECT_RESOLVED",
296
+ event: {
297
+ effectId: entry.effectId,
298
+ status: entry.result.status,
299
+ resultRef,
300
+ stdoutRef: stdoutRef ?? undefined,
301
+ stderrRef: stderrRef ?? undefined,
302
+ startedAt: resultPayload.startedAt,
303
+ finishedAt: resultPayload.finishedAt,
304
+ },
305
+ });
306
+ return { resultRef };
307
+ });
308
+ results.push({
309
+ effectId: entry.effectId,
310
+ ok: true,
311
+ resultRef: commitResult.resultRef,
312
+ });
313
+ }
314
+ catch (error) {
315
+ const msg = error instanceof Error ? error.message : String(error);
316
+ results.push({
317
+ effectId: entry.effectId,
318
+ ok: false,
319
+ error: msg,
320
+ });
321
+ }
322
+ }
323
+ return ok({ results });
324
+ }
325
+ catch (error) {
326
+ const msg = error instanceof Error ? error.message : String(error);
327
+ return fail("INTERNAL_ERROR", msg);
328
+ }
329
+ }
@@ -0,0 +1,5 @@
1
+ export { apiCreateRun, apiIterate, apiCommitEffect, apiRunStatus, apiRunEvents, } from "./runs";
2
+ export type { ApiResult, ApiCreateRunInput, ApiIterateOutput, RunStatusOutput, RunEventsOutput, } from "./runs";
3
+ export { apiListEffects, apiShowEffect, apiCancelEffect, apiBatchCommitEffects, } from "./effects";
4
+ export type { ListEffectsInput, ListEffectsOutput, EffectSummary, ShowEffectInput, ShowEffectOutput, CancelEffectInput, CancelEffectOutput, BatchCommitEffectEntry, BatchCommitEffectsInput, BatchCommitEffectResult, BatchCommitEffectsOutput, } from "./effects";
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/api/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,EACZ,UAAU,EACV,eAAe,EACf,YAAY,EACZ,YAAY,GACb,MAAM,QAAQ,CAAC;AAEhB,YAAY,EACV,SAAS,EACT,iBAAiB,EACjB,gBAAgB,EAChB,eAAe,EACf,eAAe,GAChB,MAAM,QAAQ,CAAC;AAEhB,OAAO,EACL,cAAc,EACd,aAAa,EACb,eAAe,EACf,qBAAqB,GACtB,MAAM,WAAW,CAAC;AAEnB,YAAY,EACV,gBAAgB,EAChB,iBAAiB,EACjB,aAAa,EACb,eAAe,EACf,gBAAgB,EAChB,iBAAiB,EACjB,kBAAkB,EAClB,sBAAsB,EACtB,uBAAuB,EACvB,uBAAuB,EACvB,wBAAwB,GACzB,MAAM,WAAW,CAAC"}
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.apiBatchCommitEffects = exports.apiCancelEffect = exports.apiShowEffect = exports.apiListEffects = exports.apiRunEvents = exports.apiRunStatus = exports.apiCommitEffect = exports.apiIterate = exports.apiCreateRun = void 0;
4
+ var runs_1 = require("./runs");
5
+ Object.defineProperty(exports, "apiCreateRun", { enumerable: true, get: function () { return runs_1.apiCreateRun; } });
6
+ Object.defineProperty(exports, "apiIterate", { enumerable: true, get: function () { return runs_1.apiIterate; } });
7
+ Object.defineProperty(exports, "apiCommitEffect", { enumerable: true, get: function () { return runs_1.apiCommitEffect; } });
8
+ Object.defineProperty(exports, "apiRunStatus", { enumerable: true, get: function () { return runs_1.apiRunStatus; } });
9
+ Object.defineProperty(exports, "apiRunEvents", { enumerable: true, get: function () { return runs_1.apiRunEvents; } });
10
+ var effects_1 = require("./effects");
11
+ Object.defineProperty(exports, "apiListEffects", { enumerable: true, get: function () { return effects_1.apiListEffects; } });
12
+ Object.defineProperty(exports, "apiShowEffect", { enumerable: true, get: function () { return effects_1.apiShowEffect; } });
13
+ Object.defineProperty(exports, "apiCancelEffect", { enumerable: true, get: function () { return effects_1.apiCancelEffect; } });
14
+ Object.defineProperty(exports, "apiBatchCommitEffects", { enumerable: true, get: function () { return effects_1.apiBatchCommitEffects; } });
@@ -0,0 +1,86 @@
1
+ /**
2
+ * GAP-JSON-001: Programmatic API for run lifecycle.
3
+ *
4
+ * Thin typed wrappers over existing runtime functions with validation,
5
+ * error handling, and ApiResult envelopes. These functions never throw.
6
+ */
7
+ import type { EffectAction, IterationResult } from "../runtime/types";
8
+ import type { JsonRecord } from "../storage/types";
9
+ export type ApiResult<T> = {
10
+ ok: true;
11
+ data: T;
12
+ } | {
13
+ ok: false;
14
+ error: {
15
+ code: string;
16
+ message: string;
17
+ };
18
+ };
19
+ export interface ApiCreateRunInput {
20
+ processId: string;
21
+ entrypoint: string;
22
+ runsDir: string;
23
+ inputs?: unknown;
24
+ prompt?: string;
25
+ harness?: string;
26
+ }
27
+ export interface ApiIterateOutput {
28
+ status: IterationResult["status"];
29
+ output?: unknown;
30
+ error?: unknown;
31
+ nextActions?: EffectAction[];
32
+ metadata?: unknown;
33
+ }
34
+ export interface RunStatusOutput {
35
+ state: "created" | "running" | "waiting" | "completed" | "failed";
36
+ processId: string;
37
+ runId: string;
38
+ pendingEffects: Array<{
39
+ effectId: string;
40
+ kind?: string;
41
+ }>;
42
+ }
43
+ export interface RunEventsOutput {
44
+ events: Array<{
45
+ seq: number;
46
+ type: string;
47
+ recordedAt: string;
48
+ data: JsonRecord;
49
+ }>;
50
+ }
51
+ export declare function apiCreateRun(input: ApiCreateRunInput): Promise<ApiResult<{
52
+ runId: string;
53
+ runDir: string;
54
+ }>>;
55
+ export declare function apiIterate(input: {
56
+ runDir: string;
57
+ }): Promise<ApiResult<ApiIterateOutput>>;
58
+ export declare function apiCommitEffect(input: {
59
+ runDir: string;
60
+ effectId: string;
61
+ result: {
62
+ status: "ok" | "error";
63
+ value?: unknown;
64
+ error?: string;
65
+ stdout?: string;
66
+ stderr?: string;
67
+ stdoutRef?: string;
68
+ stderrRef?: string;
69
+ startedAt?: string;
70
+ finishedAt?: string;
71
+ metadata?: JsonRecord;
72
+ };
73
+ }): Promise<ApiResult<{
74
+ resultRef: string;
75
+ }>>;
76
+ export declare function apiRunStatus(input: {
77
+ runId: string;
78
+ runsDir: string;
79
+ }): Promise<ApiResult<RunStatusOutput>>;
80
+ export declare function apiRunEvents(input: {
81
+ runId: string;
82
+ runsDir: string;
83
+ limit?: number;
84
+ filterType?: string;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