@anhlp/alp-runtime 0.0.1-beta.3 → 0.0.1-beta.5

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 (80) hide show
  1. package/dist/acp-transport.js +5 -36
  2. package/dist/antigravity-transport.d.ts +17 -0
  3. package/dist/antigravity-transport.js +82 -58
  4. package/dist/assignment-results.d.ts +52 -0
  5. package/dist/assignment-results.js +169 -0
  6. package/dist/attachments.d.ts +84 -0
  7. package/dist/attachments.js +213 -0
  8. package/dist/board-domain.js +2 -2
  9. package/dist/board.d.ts +6 -0
  10. package/dist/board.js +7 -0
  11. package/dist/catalog.d.ts +13 -0
  12. package/dist/catalog.js +9 -1
  13. package/dist/claude-transport.d.ts +35 -0
  14. package/dist/claude-transport.js +152 -10
  15. package/dist/compact.d.ts +29 -0
  16. package/dist/compact.js +49 -0
  17. package/dist/configure.d.ts +44 -0
  18. package/dist/configure.js +64 -0
  19. package/dist/contracts.d.ts +185 -4
  20. package/dist/contracts.js +11 -0
  21. package/dist/conversation.d.ts +45 -0
  22. package/dist/conversation.js +62 -0
  23. package/dist/index.d.ts +15 -4
  24. package/dist/index.js +40 -3
  25. package/dist/input-limits.d.ts +25 -0
  26. package/dist/input-limits.js +48 -0
  27. package/dist/language.d.ts +8 -0
  28. package/dist/language.js +20 -0
  29. package/dist/mailbox.d.ts +2 -0
  30. package/dist/mailbox.js +3 -1
  31. package/dist/mcp-tools.d.ts +8 -0
  32. package/dist/mcp-tools.js +26 -0
  33. package/dist/model-catalog.d.ts +76 -0
  34. package/dist/model-catalog.js +193 -0
  35. package/dist/model-probes.d.ts +7 -0
  36. package/dist/model-probes.js +69 -0
  37. package/dist/providers.js +2 -0
  38. package/dist/resolve.d.ts +1 -0
  39. package/dist/resolve.js +3 -1
  40. package/dist/runtime.d.ts +9 -0
  41. package/dist/runtime.js +1547 -142
  42. package/dist/session-config.d.ts +279 -0
  43. package/dist/session-config.js +10 -10
  44. package/dist/session-state.d.ts +44 -6
  45. package/dist/tools.d.ts +119 -0
  46. package/dist/tools.js +72 -5
  47. package/dist/transport.js +3 -1
  48. package/dist/workspace.d.ts +11 -4
  49. package/dist/workspace.js +29 -11
  50. package/dist/worktree-domain.d.ts +2 -1
  51. package/dist/worktree-domain.js +4 -1
  52. package/package.json +11 -3
  53. package/src/acp-transport.ts +7 -37
  54. package/src/antigravity-transport.ts +95 -53
  55. package/src/assignment-results.ts +146 -0
  56. package/src/attachments.ts +254 -0
  57. package/src/board-domain.ts +2 -2
  58. package/src/board.ts +7 -0
  59. package/src/catalog.ts +10 -1
  60. package/src/claude-transport.ts +171 -11
  61. package/src/compact.ts +62 -0
  62. package/src/configure.ts +93 -0
  63. package/src/contracts.ts +172 -5
  64. package/src/conversation.ts +81 -0
  65. package/src/index.ts +15 -4
  66. package/src/input-limits.ts +65 -0
  67. package/src/language.ts +18 -0
  68. package/src/mailbox.ts +4 -1
  69. package/src/mcp-tools.ts +33 -0
  70. package/src/model-catalog.ts +166 -0
  71. package/src/model-probes.ts +58 -0
  72. package/src/providers.ts +3 -0
  73. package/src/resolve.ts +4 -2
  74. package/src/runtime.ts +1681 -151
  75. package/src/session-config.ts +9 -9
  76. package/src/session-state.ts +29 -2
  77. package/src/tools.ts +69 -5
  78. package/src/transport.ts +3 -1
  79. package/src/workspace.ts +42 -15
  80. package/src/worktree-domain.ts +5 -1
package/dist/tools.d.ts CHANGED
@@ -227,6 +227,29 @@ export declare const DISCARD_TOOL: {
227
227
  additionalProperties: boolean;
228
228
  };
229
229
  };
230
+ export declare const RESOLVE_TOOL: {
231
+ type: string;
232
+ name: string;
233
+ description: string;
234
+ inputSchema: {
235
+ type: string;
236
+ properties: {
237
+ assignmentId: {
238
+ type: string;
239
+ };
240
+ outcome: {
241
+ type: string;
242
+ enum: readonly ["applied", "discarded", "acknowledged"];
243
+ };
244
+ note: {
245
+ type: string;
246
+ description: string;
247
+ };
248
+ };
249
+ required: string[];
250
+ additionalProperties: boolean;
251
+ };
252
+ };
230
253
  export declare const CANCEL_TOOL: {
231
254
  type: string;
232
255
  name: string;
@@ -289,7 +312,9 @@ export declare const PIN_TOOL: {
289
312
  type: string;
290
313
  items: {
291
314
  type: string;
315
+ maxLength: number;
292
316
  };
317
+ maxItems: number;
293
318
  description: string;
294
319
  };
295
320
  };
@@ -310,6 +335,7 @@ export declare const BOARD_TOOL: {
310
335
  type: string;
311
336
  enum: readonly ["claim", "decision", "finding"];
312
337
  };
338
+ maxItems: 3;
313
339
  };
314
340
  limit: {
315
341
  type: string;
@@ -381,6 +407,52 @@ export declare const LESSON_TOOL: {
381
407
  additionalProperties: boolean;
382
408
  };
383
409
  };
410
+ export declare const LESSON_CURATE_TOOL: {
411
+ type: string;
412
+ name: string;
413
+ description: string;
414
+ inputSchema: {
415
+ type: string;
416
+ properties: {
417
+ changes: {
418
+ type: string;
419
+ description: string;
420
+ items: {
421
+ type: string;
422
+ properties: {
423
+ scope: {
424
+ type: string;
425
+ enum: string[];
426
+ };
427
+ remove: {
428
+ type: string;
429
+ items: {
430
+ type: string;
431
+ };
432
+ description: string;
433
+ };
434
+ add: {
435
+ type: string;
436
+ description: string;
437
+ };
438
+ reason: {
439
+ type: string;
440
+ description: string;
441
+ };
442
+ };
443
+ required: string[];
444
+ additionalProperties: boolean;
445
+ };
446
+ };
447
+ requestId: {
448
+ type: string;
449
+ description: string;
450
+ };
451
+ };
452
+ required: string[];
453
+ additionalProperties: boolean;
454
+ };
455
+ };
384
456
  export declare const SKILL_TOOL: {
385
457
  type: string;
386
458
  name: string;
@@ -638,6 +710,15 @@ export declare function taskTool(actions: TaskAction[]): {
638
710
  type: string;
639
711
  description: string;
640
712
  } | undefined;
713
+ options?: {
714
+ type: string;
715
+ items: {
716
+ type: string;
717
+ maxLength: number;
718
+ };
719
+ maxItems: number;
720
+ description: string;
721
+ } | undefined;
641
722
  gate?: {
642
723
  type: string;
643
724
  description: string;
@@ -650,6 +731,7 @@ export declare function taskTool(actions: TaskAction[]): {
650
731
  type: string;
651
732
  additionalProperties: {
652
733
  type: string;
734
+ maxLength: number;
653
735
  };
654
736
  description: string;
655
737
  } | undefined;
@@ -680,3 +762,40 @@ export declare function taskTool(actions: TaskAction[]): {
680
762
  };
681
763
  /** The task an assignment takes, as the start of its brief. */
682
764
  export declare function taskBrief(task: Task, writing: boolean): string;
765
+ /** Only the project's main root may schedule a future continuation. */
766
+ export declare const SCHEDULE_TOOL: {
767
+ type: string;
768
+ name: string;
769
+ description: string;
770
+ inputSchema: {
771
+ type: string;
772
+ properties: {
773
+ action: {
774
+ type: string;
775
+ enum: string[];
776
+ };
777
+ dueAt: {
778
+ type: string;
779
+ description: string;
780
+ };
781
+ prompt: {
782
+ type: string;
783
+ description: string;
784
+ };
785
+ requestId: {
786
+ type: string;
787
+ description: string;
788
+ };
789
+ id: {
790
+ type: string;
791
+ description: string;
792
+ };
793
+ status: {
794
+ type: string;
795
+ enum: string[];
796
+ };
797
+ };
798
+ required: string[];
799
+ additionalProperties: boolean;
800
+ };
801
+ };
package/dist/tools.js CHANGED
@@ -1,8 +1,10 @@
1
1
  // packages/runtime/src/tools.ts
2
2
  import { CLOSE_REASONS, GATE_KINDS, TASK_STATUSES, TASK_TYPES, TASKS_DIR } from "@anhlp/alp-core/tasks";
3
3
  import { READ_ONLY_AGENTS } from "./resolve.js";
4
- import { PIN_KINDS } from "./board.js";
4
+ import { PIN_KINDS, PIN_PATH_CHARS, PIN_PATHS } from "./board.js";
5
+ import { POUR_VARS } from "./input-limits.js";
5
6
  import { RECALL_KEEP_MS } from "./recall.js";
7
+ import { RESULT_OUTCOMES } from "./assignment-results.js";
6
8
  import { HANDOFF_OUTCOMES, VERDICT_RESULTS, CRITERION_RESULTS, SEVERITIES } from "./handoff.js";
7
9
  var handoffList = (description) => ({ type: "array", items: { type: "string" }, description });
8
10
  var HANDOFF_TOOL = {
@@ -125,6 +127,21 @@ var DISCARD_TOOL = {
125
127
  additionalProperties: false
126
128
  }
127
129
  };
130
+ var RESOLVE_TOOL = {
131
+ type: "function",
132
+ name: "alp_resolve",
133
+ description: "Record how you handled a finished writer's change in your checkout: applied (you kept or committed it), discarded (you reverted it) or acknowledged (you reviewed it; nothing to do). Until then ALP keeps its result and will not let that checkout be removed; then it archives the result.",
134
+ inputSchema: {
135
+ type: "object",
136
+ properties: {
137
+ assignmentId: { type: "string" },
138
+ outcome: { type: "string", enum: RESULT_OUTCOMES },
139
+ note: { type: "string", description: "What you did with it, for the archive and the run log." }
140
+ },
141
+ required: ["assignmentId", "outcome"],
142
+ additionalProperties: false
143
+ }
144
+ };
128
145
  var CANCEL_TOOL = {
129
146
  type: "function",
130
147
  name: "alp_cancel",
@@ -163,7 +180,7 @@ var PIN_TOOL = {
163
180
  properties: {
164
181
  kind: { type: "string", enum: PIN_KINDS },
165
182
  body: { type: "string", description: "For a claim, what you are changing; otherwise the decision or finding itself." },
166
- paths: { type: "array", items: { type: "string" }, description: "Project-relative files or directories. Required for a claim." }
183
+ paths: { type: "array", items: { type: "string", maxLength: PIN_PATH_CHARS }, maxItems: PIN_PATHS, description: `Project-relative files or directories, at most ${PIN_PATHS}. Required for a claim.` }
167
184
  },
168
185
  required: ["kind", "body"],
169
186
  additionalProperties: false
@@ -176,7 +193,7 @@ var BOARD_TOOL = {
176
193
  inputSchema: {
177
194
  type: "object",
178
195
  properties: {
179
- kinds: { type: "array", items: { type: "string", enum: PIN_KINDS } },
196
+ kinds: { type: "array", items: { type: "string", enum: PIN_KINDS }, maxItems: PIN_KINDS.length },
180
197
  limit: { type: "integer", description: "Most recent decisions and findings to return. Default 30." }
181
198
  },
182
199
  additionalProperties: false
@@ -222,6 +239,34 @@ var LESSON_TOOL = {
222
239
  additionalProperties: false
223
240
  }
224
241
  };
242
+ var LESSON_CURATE_TOOL = {
243
+ type: "function",
244
+ name: "alp_lesson_curate",
245
+ description: "Merge, shorten or remove recorded lessons. Each change removes the exact text of lessons from one scope and may add one rule in their place (a merge or a shortening); a change without add removes them. ALP shows every change to the user at once and applies them only when the user approves. Returns pending_approval with approvalId immediately; the result (applied, lessons not found, or the user's feedback) arrives once by mail. Never edit lessons files any other way.",
246
+ inputSchema: {
247
+ type: "object",
248
+ properties: {
249
+ changes: {
250
+ type: "array",
251
+ description: "At most 50 changes.",
252
+ items: {
253
+ type: "object",
254
+ properties: {
255
+ scope: { type: "string", enum: ["project", "user"] },
256
+ remove: { type: "array", items: { type: "string" }, description: "The exact text of each lesson to remove, with or without its date." },
257
+ add: { type: "string", description: "One rule, at most 600 characters, that replaces them." },
258
+ reason: { type: "string", description: "Why, in one line." }
259
+ },
260
+ required: ["scope", "remove"],
261
+ additionalProperties: false
262
+ }
263
+ },
264
+ requestId: { type: "string", description: "Optional session-scoped idempotency key (1-100 characters)." }
265
+ },
266
+ required: ["changes"],
267
+ additionalProperties: false
268
+ }
269
+ };
225
270
  var SKILL_TOOL = {
226
271
  type: "function",
227
272
  name: "alp_skill",
@@ -270,7 +315,7 @@ var TASK_FIELDS = {
270
315
  start: ["id"],
271
316
  close: ["id", "reason", "summary", "unverified"],
272
317
  reopen: ["id", "note"],
273
- gate: ["id", "kind", "note", "until", "ref"],
318
+ gate: ["id", "kind", "note", "until", "ref", "options"],
274
319
  clear: ["id", "gate", "note"],
275
320
  pour: ["formula", "vars", "parent"],
276
321
  formulas: [],
@@ -322,9 +367,10 @@ function taskTool(actions) {
322
367
  kind: { type: "string", enum: GATE_KINDS, description: "For gate: human (the user approves; give the question as note), timer (until), gh:pr (until a pull request merges; ref), gh:run (until a workflow run succeeds; ref)." },
323
368
  until: { type: "string", description: "For a timer gate: an ISO time, or +30m, +2h, +3d." },
324
369
  ref: { type: "string", description: "For a gh:pr or gh:run gate: 123, or owner/repo#123." },
370
+ options: { type: "array", items: { type: "string", maxLength: 200 }, maxItems: 10, description: "For a human gate: up to 10 answers the user picks from, each at most 200 characters; picking any approves it, and you get the choice by mail. Default approve or reject." },
325
371
  gate: { type: "string", description: "For clear: the gate id, such as g1. You cannot clear a human gate; the user does." },
326
372
  formula: { type: "string", description: "For pour: the formula name, from action formulas." },
327
- vars: { type: "object", additionalProperties: { type: "string" }, description: "For pour: values of the formula variables." },
373
+ vars: { type: "object", additionalProperties: { type: "string", maxLength: POUR_VARS.string }, description: `For pour: values of the formula variables (at most ${POUR_VARS.items}), each at most ${POUR_VARS.string} characters.` },
328
374
  summary: { type: "string", description: "For close: the outcome and its evidence." },
329
375
  unverified: { type: "string", description: "For close as done when the task's last verification failed: why it is done anyway. Recorded on the task." },
330
376
  note: { type: "string", description: "For update and reopen: why." }
@@ -348,6 +394,24 @@ function taskBrief(task, writing) {
348
394
  "Your handoff moves this task to review for your requester to accept. List work you found outside the task under discovered; only main and the user create tasks."
349
395
  ].join("\n");
350
396
  }
397
+ var SCHEDULE_TOOL = {
398
+ type: "function",
399
+ name: "alp_schedule",
400
+ description: "Create, list, inspect or cancel a one-shot continuation of this main/root session. create proposes the exact prompt and ISO time with UTC offset for user approval. Jobs wake an idle main without a user message; timer gates only unblock tasks, and assignment notes do not schedule a wake. Scheduling a quota-reset continuation never guarantees provider availability: recheck actual availability before delegating.",
401
+ inputSchema: {
402
+ type: "object",
403
+ properties: {
404
+ action: { type: "string", enum: ["create", "list", "get", "cancel"] },
405
+ dueAt: { type: "string", description: "For create: ISO timestamp with Z or an explicit UTC offset." },
406
+ prompt: { type: "string", description: "For create: the exact continuation, at most 8000 characters." },
407
+ requestId: { type: "string", description: "For create: stable id for this approval proposal; reuse only for an identical draft." },
408
+ id: { type: "string", description: "For get/cancel: the scheduled job id." },
409
+ status: { type: "string", enum: ["pending", "delivered", "failed", "cancelled"] }
410
+ },
411
+ required: ["action"],
412
+ additionalProperties: false
413
+ }
414
+ };
351
415
  export {
352
416
  ASK_TOOL,
353
417
  BOARD_TOOL,
@@ -355,10 +419,13 @@ export {
355
419
  DISCARD_TOOL,
356
420
  HANDOFF_TOOL,
357
421
  ISSUE_TOOL,
422
+ LESSON_CURATE_TOOL,
358
423
  LESSON_TOOL,
359
424
  MERGE_TOOL,
360
425
  PIN_TOOL,
361
426
  RECALL_TOOL,
427
+ RESOLVE_TOOL,
428
+ SCHEDULE_TOOL,
362
429
  SEND_TOOL,
363
430
  SKILL_TOOL,
364
431
  TASK_ACTIONS,
package/dist/transport.js CHANGED
@@ -2,6 +2,7 @@
2
2
  import { optionalRead, codexUsage } from "./runtime-context.js";
3
3
  import { spawn, execFile } from "node:child_process";
4
4
  import { createInterface } from "node:readline";
5
+ import { scriptCommand } from "@anhlp/alp-core/packaged";
5
6
  function unanswered(error) {
6
7
  return Object.assign(new Error(error.message), { outcomeUnknown: true });
7
8
  }
@@ -17,7 +18,8 @@ var CodexTransport = class {
17
18
  constructor(command, cwd, env, args = ["app-server", "--listen", "stdio://"]) {
18
19
  if (/\.(cmd|bat|ps1)$/i.test(command)) throw new Error("Codex executable must be a native binary, not a shell launcher");
19
20
  const script = process.platform === "win32" && /\.[cm]?js$/i.test(command);
20
- this.child = spawn(script ? process.execPath : command, script ? [command, ...args] : args, { cwd, env, windowsHide: true, stdio: ["pipe", "pipe", "pipe"] });
21
+ const run = script ? scriptCommand(command, args) : { command, args, env: void 0 };
22
+ this.child = spawn(run.command, run.args, { cwd, env: run.env ? { ...env, ...run.env } : env, windowsHide: true, stdio: ["pipe", "pipe", "pipe"] });
21
23
  this.exit = new Promise((resolve) => {
22
24
  this.child.once("close", resolve);
23
25
  this.child.once("error", () => resolve());
@@ -39,10 +39,14 @@ export declare function createWorktree(workdir: string, root: string, id: string
39
39
  commit: string;
40
40
  }): Promise<Worktree>;
41
41
  /**
42
- * Checks out an assignment's existing branch again at its worktree's place, after
43
- * reclaimWorktrees committed and removed it, so the assignment continues there.
42
+ * Continues an assignment in its worktree after a restart. A worktree that is still valid
43
+ * is reused as is, whatever it holds. A directory left without valid git metadata (a crash
44
+ * mid-write) is never deleted: it moves aside to `preserved` and the branch is checked out
45
+ * again at its place.
44
46
  */
45
- export declare function reattachWorktree(worktree: Worktree): Promise<Worktree>;
47
+ export declare function reattachWorktree(worktree: Worktree): Promise<Worktree & {
48
+ preserved?: string;
49
+ }>;
46
50
  /** A digest of a checkout's state: HEAD, its uncommitted changes, and the names of untracked files. */
47
51
  export declare function checkoutFingerprint(checkout: string): Promise<string | undefined>;
48
52
  /**
@@ -79,7 +83,10 @@ export declare function removeWorktree(worktree: Worktree, { deleteBranch }?: {
79
83
  }): Promise<void>;
80
84
  /**
81
85
  * After a crash: commits work left in worktrees under `root` to their branches and
82
- * removes the directories. Returns the branches that were kept.
86
+ * removes the directories. Returns the branches that were kept. A directory is removed
87
+ * only once everything in it is committed to its own `alp/<name>` branch; any other one
88
+ * (invalid git metadata, a failed commit, another branch checked out, a detached HEAD)
89
+ * stays untouched, so recovery reuses or preserves it and nothing uncommitted is lost.
83
90
  */
84
91
  export declare function reclaimWorktrees(root: string): Promise<string[]>;
85
92
  /**
package/dist/workspace.js CHANGED
@@ -1,7 +1,7 @@
1
1
  // packages/runtime/src/workspace.ts
2
2
  import { spawn } from "node:child_process";
3
3
  import { createHash } from "node:crypto";
4
- import { copyFile, lstat, mkdir, mkdtemp, readdir, readFile, realpath, rm, stat, symlink, unlink, writeFile } from "node:fs/promises";
4
+ import { copyFile, lstat, mkdir, mkdtemp, readdir, readFile, realpath, rename, rm, stat, symlink, unlink, writeFile } from "node:fs/promises";
5
5
  import os from "node:os";
6
6
  import path from "node:path";
7
7
  var IDENTITY = ["-c", "user.name=ALP", "-c", "user.email=alp@localhost", "-c", "commit.gpgsign=false"];
@@ -103,13 +103,29 @@ async function createWorktree(workdir, root, id, from) {
103
103
  const relative = path.relative(checkout, await realpath(workdir));
104
104
  return { checkout, path: target, workdir: path.join(target, relative), branch, base, ...fingerprint ? { fingerprint } : {} };
105
105
  }
106
+ async function validWorktree(directory) {
107
+ const top = await git(directory, ["rev-parse", "--show-toplevel"]).catch(() => void 0);
108
+ if (top?.code !== 0) return false;
109
+ const [a, b] = await Promise.all([realpath(top.stdout.trim()).catch(() => ""), realpath(directory).catch(() => directory)]);
110
+ return a === b && (await git(directory, ["status", "--porcelain"])).code === 0;
111
+ }
106
112
  async function reattachWorktree(worktree) {
113
+ const exists = !!await stat(worktree.path).catch(() => void 0);
114
+ if (exists && await validWorktree(worktree.path)) {
115
+ const gitdir = await git(worktree.path, ["rev-parse", "--absolute-git-dir"]);
116
+ if (gitdir.code === 0) await rm(path.join(gitdir.stdout.trim(), "index.lock"), { force: true });
117
+ return worktree;
118
+ }
107
119
  if (!await branchExists(worktree.checkout, worktree.branch)) throw new Error(`Branch ${worktree.branch} of the worktree no longer exists`);
108
- if (await stat(worktree.path).catch(() => void 0)) return worktree;
120
+ let preserved;
121
+ if (exists) {
122
+ preserved = `${worktree.path}.preserved-${(/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-")}`;
123
+ await rename(worktree.path, preserved);
124
+ }
109
125
  await mkdir(path.dirname(worktree.path), { recursive: true, mode: 448 });
110
126
  await git(worktree.checkout, ["worktree", "prune"]);
111
127
  await checked(worktree.checkout, ["worktree", "add", "--quiet", worktree.path, worktree.branch]);
112
- return worktree;
128
+ return preserved ? { ...worktree, preserved } : worktree;
113
129
  }
114
130
  async function checkoutFingerprint(checkout) {
115
131
  const head = await git(checkout, ["rev-parse", "--verify", "HEAD"]);
@@ -181,17 +197,19 @@ async function reclaimWorktrees(root) {
181
197
  for (const name of entries) {
182
198
  const target = path.join(root, name);
183
199
  if (!(await stat(target).catch(() => void 0))?.isDirectory()) continue;
184
- const common = await git(target, ["rev-parse", "--path-format=absolute", "--git-common-dir"]).catch(() => void 0);
185
- if (common?.code !== 0) {
186
- await rm(target, { recursive: true, force: true });
187
- continue;
188
- }
200
+ if (!await validWorktree(target)) continue;
201
+ const common = await git(target, ["rev-parse", "--path-format=absolute", "--git-common-dir"]);
202
+ if (common.code !== 0) continue;
189
203
  const checkout = path.dirname(common.stdout.trim());
190
- const branch = (await git(target, ["rev-parse", "--abbrev-ref", "HEAD"])).stdout.trim();
191
- await git(target, ["add", "-A"]);
204
+ const ref = await git(target, ["symbolic-ref", "--quiet", "--short", "HEAD"]);
205
+ const branch = ref.stdout.trim();
206
+ if (ref.code !== 0 || branch !== `alp/${name}`) continue;
207
+ if ((await git(target, ["add", "-A"])).code !== 0) continue;
192
208
  if ((await git(target, ["diff", "--cached", "--quiet"])).code === 1) {
193
- await git(target, [...IDENTITY, "commit", "--quiet", "--no-verify", "-m", "alp: work left by an interrupted assignment"]);
209
+ if ((await git(target, [...IDENTITY, "commit", "--quiet", "--no-verify", "-m", "alp: work left by an interrupted assignment"])).code !== 0) continue;
194
210
  }
211
+ const status = await git(target, ["status", "--porcelain", "--ignored=no"]);
212
+ if (status.code !== 0 || status.stdout.trim()) continue;
195
213
  await removeWorktree({ checkout, path: target, workdir: target, branch, base: "" });
196
214
  kept.push(branch);
197
215
  }
@@ -4,6 +4,7 @@ import type { RuntimeOptions } from './contracts.js';
4
4
  import type { Session, Assignment } from './session-state.js';
5
5
  type WorktreeContext = {
6
6
  options: RuntimeOptions;
7
+ releaseResult(assignmentId: string): Promise<void>;
7
8
  leases: Map<string, {
8
9
  assignment: string;
9
10
  agent: string;
@@ -15,7 +16,7 @@ type WorktreeContext = {
15
16
  touchTask(rootId: string, id: string): void;
16
17
  };
17
18
  /** Checkout mutation and verification retain one shared queue per checkout. */
18
- export declare function createWorktreeDomain({ options, leases, rootOf, lineage, runLog, runHooks, touchTask }: WorktreeContext): {
19
+ export declare function createWorktreeDomain({ options, leases, releaseResult, rootOf, lineage, runLog, runHooks, touchTask }: WorktreeContext): {
19
20
  settleWorktree: (parentId: string, parent: Session, assignment: Assignment) => Promise<{
20
21
  branch: string;
21
22
  files: never[];
@@ -8,7 +8,7 @@ import { writes } from "./catalog.js";
8
8
  import { nativeEnvironment } from "./providers.js";
9
9
  import { mainOf } from "./tools.js";
10
10
  import { errorData, plainObject, toolResult } from "./tool-results.js";
11
- function createWorktreeDomain({ options, leases, rootOf, lineage, runLog, runHooks, touchTask }) {
11
+ function createWorktreeDomain({ options, leases, releaseResult, rootOf, lineage, runLog, runHooks, touchTask }) {
12
12
  const merging = /* @__PURE__ */ new Map();
13
13
  async function settleWorktree(parentId, parent, assignment) {
14
14
  const worktree = assignment.worktree;
@@ -16,6 +16,7 @@ function createWorktreeDomain({ options, leases, rootOf, lineage, runLog, runHoo
16
16
  const change = await commitWorktree(worktree, `alp: ${assignment.agent} assignment ${assignment.id}`);
17
17
  if (!change.files.length) {
18
18
  await removeWorktree(worktree, { deleteBranch: true });
19
+ await releaseResult(assignment.id);
19
20
  return { branch: worktree.branch, files: [], note: "No changes; the worktree was removed" };
20
21
  }
21
22
  const described = { branch: worktree.branch, base: worktree.base, commit: change.commit, files: change.files, stat: change.stat };
@@ -44,6 +45,7 @@ function createWorktreeDomain({ options, leases, rootOf, lineage, runLog, runHoo
44
45
  if (action === "discard") {
45
46
  session.worktrees.delete(args.assignmentId);
46
47
  await removeWorktree(worktree, { deleteBranch: true });
48
+ await releaseResult(args.assignmentId);
47
49
  runLog(rootOf(sessionId), { event: "worktree.discarded", assignmentId: args.assignmentId, branch: worktree.branch });
48
50
  return toolResult(true, { discarded: args.assignmentId, branch: worktree.branch });
49
51
  }
@@ -104,6 +106,7 @@ ${refused}`, branch: worktree.branch, next: `Fix what it reports in a new assign
104
106
  return toolResult(false, { error: errorData(error).message, branch: worktree.branch, next: "Merge the branch yourself, or alp_discard it" });
105
107
  }
106
108
  await removeWorktree(worktree, { deleteBranch: merged.status !== "conflicts" });
109
+ if (merged.status !== "conflicts") await releaseResult(args.assignmentId);
107
110
  runLog(rootId, { event: "worktree.merged", assignmentId: args.assignmentId, branch: worktree.branch, ...merged });
108
111
  let checked;
109
112
  if (config && args.skipVerify === void 0 && merged.status === "applied" && moved) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@anhlp/alp-runtime",
3
- "version": "0.0.1-beta.3",
3
+ "version": "0.0.1-beta.5",
4
4
  "type": "module",
5
5
  "description": "ALP runtime module",
6
6
  "files": [
@@ -25,6 +25,14 @@
25
25
  "types": "./dist/antigravity-transport.d.ts",
26
26
  "default": "./dist/antigravity-transport.js"
27
27
  },
28
+ "./attachments": {
29
+ "alp-source": {
30
+ "types": "./src/attachments.ts",
31
+ "default": "./src/attachments.ts"
32
+ },
33
+ "types": "./dist/attachments.d.ts",
34
+ "default": "./dist/attachments.js"
35
+ },
28
36
  "./board": {
29
37
  "alp-source": {
30
38
  "types": "./src/board.ts",
@@ -222,8 +230,8 @@
222
230
  "node": ">=22.12"
223
231
  },
224
232
  "dependencies": {
225
- "@anhlp/alp-core": "0.0.1-beta.3",
226
- "@anhlp/alp-protocol": "0.0.1-beta.3",
233
+ "@anhlp/alp-core": "0.0.1-beta.5",
234
+ "@anhlp/alp-protocol": "0.0.1-beta.5",
227
235
  "@anthropic-ai/claude-agent-sdk": "^0.3.292",
228
236
  "@modelcontextprotocol/sdk": "^1.32.1",
229
237
  "@agentclientprotocol/sdk": "1.7.0",
@@ -8,6 +8,7 @@ import path from 'node:path';
8
8
  import { createInterface } from 'node:readline';
9
9
  import { commandDecision, unwrapShell, type PermissionProfile } from '@anhlp/alp-core/permissions';
10
10
  import { launchCommand } from '@anhlp/alp-core/providers';
11
+ import { bridgeCommand } from '@anhlp/alp-core/bridges';
11
12
  import { acpText, acpToolDetail, type AcpCall } from './tool-detail.js';
12
13
 
13
14
  /**
@@ -40,39 +41,6 @@ type RequestHandler = (method: string, params: any) => Promise<unknown>;
40
41
  export type AcpPermission = { kind: string; title: string; command?: string; paths: string[]; alpTool: boolean };
41
42
 
42
43
  /** The MCP server ALP's tools reach an ACP agent through; it speaks MCP on stdio and forwards calls to the socket. */
43
- const BRIDGE = `
44
- const net = require('node:net');
45
- const readline = require('node:readline');
46
- const socket = net.connect(process.env.ALP_BRIDGE_SOCKET);
47
- const waiting = new Map();
48
- let sequence = 0;
49
- let buffer = '';
50
- socket.setEncoding('utf8');
51
- socket.write(JSON.stringify({ token: process.env.ALP_BRIDGE_TOKEN }) + '\\n');
52
- socket.on('data', data => {
53
- buffer += data;
54
- for (let index; (index = buffer.indexOf('\\n')) >= 0;) {
55
- const line = buffer.slice(0, index); buffer = buffer.slice(index + 1);
56
- try { const message = JSON.parse(line); const waiter = waiting.get(message.id); if (waiter) { waiting.delete(message.id); waiter(message); } } catch {}
57
- }
58
- });
59
- socket.on('close', () => process.exit(0));
60
- socket.on('error', () => process.exit(1));
61
- const ask = message => new Promise(resolve => { const id = ++sequence; waiting.set(id, resolve); socket.write(JSON.stringify({ ...message, id }) + '\\n'); });
62
- const send = value => process.stdout.write(JSON.stringify({ jsonrpc: '2.0', ...value }) + '\\n');
63
- readline.createInterface({ input: process.stdin }).on('line', async line => {
64
- let message; try { message = JSON.parse(line); } catch { return; }
65
- if (message.id === undefined || message.id === null) return;
66
- try {
67
- if (message.method === 'initialize') return send({ id: message.id, result: { protocolVersion: (message.params && message.params.protocolVersion) || '2025-06-18', capabilities: { tools: {} }, serverInfo: { name: 'alp', version: '1' } } });
68
- if (message.method === 'ping') return send({ id: message.id, result: {} });
69
- if (message.method === 'tools/list') { const reply = await ask({ op: 'list' }); return send({ id: message.id, result: { tools: reply.tools } }); }
70
- if (message.method === 'tools/call') { const reply = await ask({ op: 'call', name: message.params.name, arguments: message.params.arguments || {} }); return send({ id: message.id, result: reply.result }); }
71
- send({ id: message.id, error: { code: -32601, message: 'Method not found' } });
72
- } catch (error) { send({ id: message.id, error: { code: -32603, message: String((error && error.message) || error) } }); }
73
- });
74
- process.stdin.on('end', () => process.exit(0));
75
- `;
76
44
 
77
45
  const READERS = ['read', 'search', 'think', 'fetch'];
78
46
 
@@ -126,7 +94,8 @@ export function acpWhat(request: AcpPermission) {
126
94
  * user passed in OPENCODE_CONFIG_CONTENT, and ALP answers each by the mode.
127
95
  */
128
96
  export function acpEnv(provider: Pick<AcpProvider, 'command' | 'env'>, base: NodeJS.ProcessEnv): NodeJS.ProcessEnv {
129
- const env = { ...base, ...provider.env };
97
+ // Provider env never sheds the agent mark (t-ca1f).
98
+ const env: NodeJS.ProcessEnv = { ...base, ...provider.env, ...(base.ALP_AGENT_SESSION ? { ALP_AGENT_SESSION: base.ALP_AGENT_SESSION } : {}) };
130
99
  if (provider.command.split(/[\\/]/).pop()!.replace(/\.exe$/i, '').toLowerCase() !== 'opencode') return env;
131
100
  let config: any = {};
132
101
  try { config = JSON.parse(env.OPENCODE_CONFIG_CONTENT ?? '{}') ?? {}; } catch {}
@@ -188,8 +157,8 @@ export class AcpTransport {
188
157
  async initialize() {
189
158
  if (/\.(cmd|bat|ps1)$/i.test(this.provider.command)) throw new Error(`${this.provider.label}: the command must be a native executable, not a shell launcher`);
190
159
  const env = acpEnv(this.provider, this.env);
191
- const launch = launchCommand(this.provider.command, this.provider.args, env);
192
- const child = spawn(launch.command, launch.args, { cwd: this.cwd, env, windowsHide: true, stdio: ['pipe', 'pipe', 'pipe'] });
160
+ const launch: { command: string; args: string[]; env?: Record<string, string> } = launchCommand(this.provider.command, this.provider.args, env);
161
+ const child = spawn(launch.command, launch.args, { cwd: this.cwd, env: launch.env ? { ...env, ...launch.env } : env, windowsHide: true, stdio: ['pipe', 'pipe', 'pipe'] });
193
162
  this.child = child;
194
163
  this.exit = new Promise(resolve => { child.once('close', () => resolve()); child.once('error', () => resolve()); });
195
164
  child.stderr.on('data', () => {});
@@ -431,7 +400,8 @@ export class AcpTransport {
431
400
  }
432
401
  // Under Paseo, alpd runs on Electron's binary, which is node only with ELECTRON_RUN_AS_NODE; the agent may not pass its own environment on.
433
402
  const electron = process.versions.electron ? [{ name: 'ELECTRON_RUN_AS_NODE', value: '1' }] : [];
434
- return { name: 'alp', command: process.execPath, args: ['-e', BRIDGE], env: [{ name: 'ALP_BRIDGE_SOCKET', value: this.bridge.socket }, { name: 'ALP_BRIDGE_TOKEN', value: this.bridge.token }, ...electron] };
403
+ const bridge = bridgeCommand('acp');
404
+ return { name: 'alp', command: bridge.command, args: bridge.args, env: [{ name: 'ALP_BRIDGE_SOCKET', value: this.bridge.socket }, { name: 'ALP_BRIDGE_TOKEN', value: this.bridge.token }, ...electron] };
435
405
  }
436
406
 
437
407
  private serveBridge(connection: net.Socket, token: string) {