@anhlp/alp-runtime 0.0.0-stage → 0.0.1-beta.10

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 (127) hide show
  1. package/LICENSE +202 -0
  2. package/NOTICE +7 -0
  3. package/README.md +6 -2
  4. package/dist/acp-transport.d.ts +130 -0
  5. package/dist/acp-transport.js +482 -0
  6. package/dist/antigravity-transport.d.ts +107 -0
  7. package/dist/antigravity-transport.js +665 -0
  8. package/dist/assignment-results.d.ts +55 -0
  9. package/dist/assignment-results.js +181 -0
  10. package/dist/attachments.d.ts +84 -0
  11. package/dist/attachments.js +213 -0
  12. package/dist/board-domain.d.ts +56 -0
  13. package/dist/board-domain.js +157 -0
  14. package/dist/board.d.ts +27 -0
  15. package/dist/board.js +76 -0
  16. package/dist/catalog.d.ts +44 -0
  17. package/dist/catalog.js +47 -0
  18. package/dist/claude-transport.d.ts +251 -0
  19. package/dist/claude-transport.js +931 -0
  20. package/dist/compact.d.ts +29 -0
  21. package/dist/compact.js +49 -0
  22. package/dist/configure.d.ts +44 -0
  23. package/dist/configure.js +64 -0
  24. package/dist/contracts.d.ts +378 -0
  25. package/dist/contracts.js +16 -0
  26. package/dist/conversation.d.ts +45 -0
  27. package/dist/conversation.js +62 -0
  28. package/dist/events.d.ts +1 -0
  29. package/dist/events.js +0 -0
  30. package/dist/github.d.ts +10 -0
  31. package/dist/github.js +39 -0
  32. package/dist/handoff.d.ts +36 -0
  33. package/dist/handoff.js +73 -0
  34. package/dist/index.d.ts +39 -0
  35. package/dist/index.js +122 -0
  36. package/dist/input-limits.d.ts +25 -0
  37. package/dist/input-limits.js +48 -0
  38. package/dist/language.d.ts +51 -0
  39. package/dist/language.js +94 -0
  40. package/dist/live.d.ts +48 -0
  41. package/dist/live.js +50 -0
  42. package/dist/mailbox.d.ts +26 -0
  43. package/dist/mailbox.js +38 -0
  44. package/dist/mcp-tools.d.ts +123 -0
  45. package/dist/mcp-tools.js +97 -0
  46. package/dist/model-catalog.d.ts +162 -0
  47. package/dist/model-catalog.js +338 -0
  48. package/dist/model-probes.d.ts +7 -0
  49. package/dist/model-probes.js +69 -0
  50. package/dist/permission-path.d.ts +2 -0
  51. package/dist/permission-path.js +44 -0
  52. package/dist/process-info.d.ts +14 -0
  53. package/dist/process-info.js +32 -0
  54. package/dist/providers.d.ts +28 -0
  55. package/dist/providers.js +73 -0
  56. package/dist/recall.d.ts +42 -0
  57. package/dist/recall.js +61 -0
  58. package/dist/resolve.d.ts +123 -0
  59. package/dist/resolve.js +242 -0
  60. package/dist/runtime-context.d.ts +43 -0
  61. package/dist/runtime-context.js +61 -0
  62. package/dist/runtime.d.ts +13 -0
  63. package/dist/runtime.js +4818 -0
  64. package/dist/session-config.d.ts +2345 -0
  65. package/dist/session-config.js +209 -0
  66. package/dist/session-state.d.ts +190 -0
  67. package/dist/session-state.js +0 -0
  68. package/dist/skill-resources.d.ts +30 -0
  69. package/dist/skill-resources.js +55 -0
  70. package/dist/tool-detail.d.ts +81 -0
  71. package/dist/tool-detail.js +332 -0
  72. package/dist/tool-results.d.ts +12 -0
  73. package/dist/tool-results.js +25 -0
  74. package/dist/tools.d.ts +827 -0
  75. package/dist/tools.js +463 -0
  76. package/dist/transport.d.ts +47 -0
  77. package/dist/transport.js +171 -0
  78. package/dist/usage.d.ts +25 -0
  79. package/dist/usage.js +60 -0
  80. package/dist/workspace.d.ts +127 -0
  81. package/dist/workspace.js +340 -0
  82. package/dist/worktree-domain.d.ts +89 -0
  83. package/dist/worktree-domain.js +199 -0
  84. package/dist/write-error.d.ts +2 -0
  85. package/dist/write-error.js +10 -0
  86. package/package.json +262 -4
  87. package/src/acp-transport.ts +481 -0
  88. package/src/antigravity-transport.ts +740 -0
  89. package/src/assignment-results.ts +154 -0
  90. package/src/attachments.ts +254 -0
  91. package/src/board-domain.ts +185 -0
  92. package/src/board.ts +87 -0
  93. package/src/catalog.ts +43 -0
  94. package/src/claude-transport.ts +1097 -0
  95. package/src/compact.ts +62 -0
  96. package/src/configure.ts +93 -0
  97. package/src/contracts.ts +363 -0
  98. package/src/conversation.ts +81 -0
  99. package/src/events.ts +1 -0
  100. package/src/github.ts +37 -0
  101. package/src/handoff.ts +86 -0
  102. package/src/index.ts +41 -0
  103. package/src/input-limits.ts +65 -0
  104. package/src/language.ts +130 -0
  105. package/src/live.ts +90 -0
  106. package/src/mailbox.ts +49 -0
  107. package/src/mcp-tools.ts +106 -0
  108. package/src/model-catalog.ts +316 -0
  109. package/src/model-probes.ts +58 -0
  110. package/src/permission-path.ts +37 -0
  111. package/src/process-info.ts +40 -0
  112. package/src/providers.ts +87 -0
  113. package/src/recall.ts +86 -0
  114. package/src/resolve.ts +238 -0
  115. package/src/runtime-context.ts +49 -0
  116. package/src/runtime.ts +5608 -0
  117. package/src/session-config.ts +312 -0
  118. package/src/session-state.ts +180 -0
  119. package/src/skill-resources.ts +73 -0
  120. package/src/tool-detail.ts +397 -0
  121. package/src/tool-results.ts +26 -0
  122. package/src/tools.ts +466 -0
  123. package/src/transport.ts +118 -0
  124. package/src/usage.ts +79 -0
  125. package/src/workspace.ts +424 -0
  126. package/src/worktree-domain.ts +220 -0
  127. package/src/write-error.ts +4 -0
@@ -0,0 +1,157 @@
1
+ // packages/runtime/src/board-domain.ts
2
+ import { createHash, randomUUID } from "node:crypto";
3
+ import { appendFile, mkdir, readFile, writeFile } from "node:fs/promises";
4
+ import { moveFile } from "@anhlp/alp-core/atomic";
5
+ import path from "node:path";
6
+ import { BOARD_KEEP, live, normalizePaths, overlapping, PIN_BODY_CHARS, PIN_KINDS, renderPin } from "./board.js";
7
+ import { plainObject, toolResult } from "./tool-results.js";
8
+ function createBoardDomain({ options, sessions, boards, loadedBoards, rootOf, lineage, runLog, emit, post, steerMail }) {
9
+ const boardFile = (project) => path.join(options.boardDir, `${createHash("sha256").update(project).digest("hex").slice(0, 16)}.jsonl`);
10
+ let boardWrites = Promise.resolve();
11
+ function prune(pins) {
12
+ const notes = pins.filter((pin) => pin.kind !== "claim" && live(pin));
13
+ return [...pins.filter((pin) => pin.kind === "claim" && live(pin)), ...notes.slice(-BOARD_KEEP)];
14
+ }
15
+ function boardOf(project) {
16
+ let board = boards.get(project);
17
+ if (!board) {
18
+ board = (async () => {
19
+ if (!options.boardDir) return [];
20
+ const text = await readFile(boardFile(project), "utf8").catch(() => "");
21
+ const pins = /* @__PURE__ */ new Map();
22
+ for (const line of text.split("\n").filter(Boolean)) {
23
+ try {
24
+ const entry = JSON.parse(line);
25
+ if (entry.pin?.id) pins.set(entry.pin.id, entry.pin);
26
+ else if (entry.release && pins.has(entry.release)) pins.get(entry.release).released = entry.at;
27
+ } catch {
28
+ }
29
+ }
30
+ const now = (/* @__PURE__ */ new Date()).toISOString();
31
+ for (const pin of pins.values()) if (pin.kind === "claim" && !pin.released) pin.released = now;
32
+ const kept = prune([...pins.values()]);
33
+ boardWrites = boardWrites.then(async () => {
34
+ await mkdir(options.boardDir, { recursive: true });
35
+ const temporary = `${boardFile(project)}.${randomUUID().slice(0, 8)}.tmp`;
36
+ await writeFile(temporary, kept.map((pin) => JSON.stringify({ pin })).join("\n") + (kept.length ? "\n" : ""));
37
+ await moveFile(temporary, boardFile(project));
38
+ }).catch(() => {
39
+ });
40
+ loadedBoards.set(project, kept);
41
+ return kept;
42
+ })();
43
+ boards.set(project, board);
44
+ }
45
+ return board;
46
+ }
47
+ function saveBoard(project, entry) {
48
+ if (!options.boardDir) return;
49
+ const line = `${JSON.stringify(entry)}
50
+ `;
51
+ boardWrites = boardWrites.then(() => mkdir(options.boardDir, { recursive: true })).then(() => appendFile(boardFile(project), line)).catch(() => {
52
+ });
53
+ }
54
+ const related = (a, b) => lineage(a).includes(b) || lineage(b).includes(a);
55
+ function claimConflicts(sessionId, pins, paths) {
56
+ return pins.filter((pin) => pin.kind === "claim" && live(pin) && pin.sessionId !== sessionId && !related(sessionId, pin.sessionId) && overlapping(paths, pin.paths ?? []).length).map((pin) => ({ pinId: pin.id, agent: pin.agent, sessionId: pin.sessionId, paths: overlapping(pin.paths ?? [], paths), body: pin.body, at: pin.at, ...pin.task ? { task: pin.task } : {} }));
57
+ }
58
+ function taskOf(sessionId) {
59
+ for (const id of lineage(sessionId)) {
60
+ const parent = sessions.get(id)?.parent;
61
+ const taskId = parent ? sessions.get(parent)?.assignments.get(id)?.taskId : void 0;
62
+ if (taskId) return taskId;
63
+ }
64
+ return void 0;
65
+ }
66
+ function addPin(sessionId, session, pins, fields) {
67
+ const project = session.mapping.agent.projectRoot;
68
+ const pin = {
69
+ id: `p-${randomUUID().slice(0, 8)}`,
70
+ project,
71
+ kind: fields.kind,
72
+ body: fields.body,
73
+ ...fields.paths ? { paths: fields.paths } : {},
74
+ ...fields.task ? { task: fields.task } : {},
75
+ agent: session.mapping.agent.name,
76
+ sessionId,
77
+ rootId: rootOf(sessionId),
78
+ at: (/* @__PURE__ */ new Date()).toISOString()
79
+ };
80
+ const kept = prune([...pins, pin]);
81
+ pins.splice(0, pins.length, ...kept);
82
+ saveBoard(project, { pin });
83
+ runLog(pin.rootId, { event: "board.pin", pinId: pin.id, kind: pin.kind, agent: pin.agent, body: pin.body, ...pin.paths ? { paths: pin.paths } : {}, ...pin.task ? { task: pin.task } : {} });
84
+ emit(sessionId, { type: "pin", pin });
85
+ for (const [id, other] of sessions) {
86
+ if (id === sessionId || other.closed || !other.active || other.mapping.agent.projectRoot !== project) continue;
87
+ post(id, { kind: "board", from: pin.agent, assignment: pin.id, body: renderPin(pin), passive: true });
88
+ if (!other.pending) void steerMail(id, other);
89
+ }
90
+ return pin;
91
+ }
92
+ async function pinTool(sessionId, session, args) {
93
+ if (!plainObject(args, ["kind", "body", "paths"]) || !PIN_KINDS.includes(args.kind) || typeof args.body !== "string" || !args.body.trim() || args.body.length > PIN_BODY_CHARS) {
94
+ return toolResult(false, { error: `A pin needs kind (${PIN_KINDS.join(", ")}) and a body of at most ${PIN_BODY_CHARS} characters` });
95
+ }
96
+ if (args.kind === "claim" && session.mapping.mode === "read-only") return toolResult(false, { error: "A read-only session changes no files and cannot claim paths; pin a decision or finding instead" });
97
+ const project = session.mapping.agent.projectRoot;
98
+ let paths;
99
+ if (args.paths !== void 0 || args.kind === "claim") {
100
+ const normalized = normalizePaths(args.paths, project, session.spec.writeRoot ? [session.spec.writeRoot] : void 0);
101
+ if (typeof normalized === "string") return toolResult(false, { error: normalized });
102
+ paths = normalized;
103
+ }
104
+ const pins = await boardOf(project);
105
+ if (session.closed) return toolResult(false, { error: "Session closed" });
106
+ if (args.kind === "claim") {
107
+ const conflicts = claimConflicts(sessionId, pins, paths);
108
+ if (conflicts.length) {
109
+ return toolResult(false, {
110
+ error: "Another agent has claimed overlapping paths; do not edit them. Ask your requester, or claim other paths.",
111
+ conflicts
112
+ });
113
+ }
114
+ }
115
+ const task = args.kind === "claim" ? taskOf(sessionId) : void 0;
116
+ const pin = addPin(sessionId, session, pins, { kind: args.kind, body: args.body, ...paths ? { paths } : {}, ...task ? { task } : {} });
117
+ return toolResult(true, { pinned: pin.id, kind: pin.kind, ...paths ? { paths } : {}, ...task ? { task } : {} });
118
+ }
119
+ async function boardTool(session, args) {
120
+ if (!plainObject(args, ["kinds", "limit"]) || args.kinds !== void 0 && (!Array.isArray(args.kinds) || args.kinds.length > PIN_KINDS.length || !args.kinds.every((kind) => PIN_KINDS.includes(kind))) || args.limit !== void 0 && (!Number.isSafeInteger(args.limit) || args.limit < 1)) {
121
+ return toolResult(false, { error: `kinds lists at most ${PIN_KINDS.length} of claim, decision and finding; limit is a positive integer` });
122
+ }
123
+ const kinds = args.kinds ?? [...PIN_KINDS];
124
+ const pins = (await boardOf(session.mapping.agent.projectRoot)).filter((pin) => live(pin) && kinds.includes(pin.kind));
125
+ const claims = pins.filter((pin) => pin.kind === "claim");
126
+ const notes = pins.filter((pin) => pin.kind !== "claim").slice(-(args.limit ?? 30));
127
+ const view = ({ project: _project, rootId: _root, released: _released, ...pin }) => pin;
128
+ return toolResult(true, { claims: claims.map(view), notes: notes.map(view) });
129
+ }
130
+ async function unpinTool(sessionId, session, args) {
131
+ if (!plainObject(args, ["pinId"]) || typeof args.pinId !== "string") return toolResult(false, { error: "pinId is required" });
132
+ const pins = await boardOf(session.mapping.agent.projectRoot);
133
+ const pin = pins.find((candidate) => candidate.id === args.pinId && live(candidate));
134
+ if (!pin) return toolResult(false, { error: "No such pin on this board" });
135
+ if (pin.sessionId !== sessionId) return toolResult(false, { error: `Only ${pin.agent}, who pinned it, can take it down` });
136
+ release(pin, "unpinned");
137
+ return toolResult(true, { unpinned: pin.id });
138
+ }
139
+ function release(pin, reason) {
140
+ pin.released = (/* @__PURE__ */ new Date()).toISOString();
141
+ saveBoard(pin.project, { release: pin.id, at: pin.released });
142
+ runLog(pin.rootId, { event: "board.unpin", pinId: pin.id, agent: pin.agent, reason });
143
+ if (sessions.has(pin.sessionId)) emit(pin.sessionId, { type: "unpin", pinId: pin.id, reason });
144
+ void boardOf(pin.project).then((pins) => pins.splice(0, pins.length, ...prune(pins)));
145
+ }
146
+ function releaseClaims(sessionId, project) {
147
+ const board = boards.get(project);
148
+ if (!board) return;
149
+ void board.then((pins) => {
150
+ for (const pin of [...pins]) if (pin.kind === "claim" && live(pin) && pin.sessionId === sessionId) release(pin, "session_ended");
151
+ });
152
+ }
153
+ return { boardOf, claimConflicts, taskOf, addPin, pinTool, boardTool, unpinTool, releaseClaims, flush: () => boardWrites };
154
+ }
155
+ export {
156
+ createBoardDomain
157
+ };
@@ -0,0 +1,27 @@
1
+ import type { InputLimits } from './input-limits.js';
2
+ /**
3
+ * The project board (plans/reference/ALPD.md §18): one group channel per project that every
4
+ * agent working on it shares, across trees. Agents pin claims (paths they are changing),
5
+ * decisions (the approach everyone follows) and findings (what others need to know), so
6
+ * agents working independently neither edit each other's files nor pursue different ideas.
7
+ * These helpers stay pure; storage and delivery live in the runtime.
8
+ */
9
+ export declare const PIN_KINDS: readonly ["claim", "decision", "finding"];
10
+ import type { Pin } from '@anhlp/alp-protocol/dto';
11
+ export type { PinKind, Pin } from '@anhlp/alp-protocol/dto';
12
+ export declare const PIN_BODY_CHARS = 2000;
13
+ export declare const PIN_PATHS = 50;
14
+ /** One claimed path; macOS's PATH_MAX. Each segment of a path is one more realpath call. */
15
+ export declare const PIN_PATH_CHARS = 1024;
16
+ /** alp_pin's paths and alp_board's kinds, checked before any schema walks them. */
17
+ export declare const PIN_PATHS_INPUT: InputLimits;
18
+ export declare const BOARD_KINDS_INPUT: InputLimits;
19
+ /** Decisions and findings kept per project; live claims are always kept. */
20
+ export declare const BOARD_KEEP = 200;
21
+ /** Normalized project-relative paths, or absolute paths in a declared external write root. */
22
+ export declare function normalizePaths(paths: unknown, project: string, roots?: string[]): string[] | string;
23
+ export declare function overlapping(a: string[], b: string[]): string[];
24
+ export declare const live: (pin: Pin) => boolean;
25
+ export declare function renderPin(pin: Pin): string;
26
+ /** What an agent should know before it starts: live claims, then recent decisions and findings. */
27
+ export declare function renderBoard(pins: Pin[], limit?: number): string;
package/dist/board.js ADDED
@@ -0,0 +1,76 @@
1
+ // packages/runtime/src/board.ts
2
+ import path from "node:path";
3
+ import { realpathSync } from "node:fs";
4
+ var PIN_KINDS = ["claim", "decision", "finding"];
5
+ var PIN_BODY_CHARS = 2e3;
6
+ var PIN_PATHS = 50;
7
+ var PIN_PATH_CHARS = 1024;
8
+ var PIN_PATHS_INPUT = { bytes: PIN_PATHS * (3 * PIN_PATH_CHARS + 3), items: PIN_PATHS, depth: 1, string: PIN_PATH_CHARS };
9
+ var BOARD_KINDS_INPUT = { bytes: 64, items: PIN_KINDS.length, depth: 1, string: 16 };
10
+ var BOARD_KEEP = 200;
11
+ var DIGEST_CHARS = 3e3;
12
+ function canonicalPath(file) {
13
+ try {
14
+ return realpathSync(file);
15
+ } catch {
16
+ const parent = path.dirname(file);
17
+ return parent === file ? file : path.join(canonicalPath(parent), path.basename(file));
18
+ }
19
+ }
20
+ var containsPath = (outer, inner) => {
21
+ const relative = path.relative(outer, inner);
22
+ return !relative || relative !== ".." && !relative.startsWith(`..${path.sep}`) && !path.isAbsolute(relative);
23
+ };
24
+ function normalizePaths(paths, project, roots = [project]) {
25
+ if (!Array.isArray(paths) || !paths.length || paths.length > PIN_PATHS) return `paths must list 1 to ${PIN_PATHS} files or directories`;
26
+ const normalized = [];
27
+ for (const entry of paths) {
28
+ if (typeof entry !== "string" || !entry.trim()) return "paths must be nonempty strings";
29
+ if (entry.length > PIN_PATH_CHARS) return `paths must be at most ${PIN_PATH_CHARS} characters each`;
30
+ const absolute = canonicalPath(path.resolve(project, entry.trim()));
31
+ if (!roots.some((root) => containsPath(canonicalPath(root), absolute))) return `${entry} is outside the project or declared write root`;
32
+ const relative = path.relative(canonicalPath(project), absolute).split(path.sep).join("/");
33
+ normalized.push(relative === "" ? "." : relative === ".." || relative.startsWith("../") || path.isAbsolute(relative) ? absolute.split(path.sep).join("/") : relative);
34
+ }
35
+ return [...new Set(normalized)];
36
+ }
37
+ var contains = (outer, inner) => path.isAbsolute(outer) === path.isAbsolute(inner) && (outer === "." || inner === outer || inner.startsWith(outer.endsWith("/") ? outer : `${outer}/`));
38
+ function overlapping(a, b) {
39
+ return a.filter((left) => b.some((right) => contains(left, right) || contains(right, left)));
40
+ }
41
+ var live = (pin) => !pin.released;
42
+ function renderPin(pin) {
43
+ const where = pin.paths?.length ? ` [${pin.paths.join(", ")}]` : "";
44
+ return `${pin.kind} ${pin.id} by ${pin.agent}${pin.task ? ` for task ${pin.task}` : ""}${where}: ${pin.body}`;
45
+ }
46
+ function renderBoard(pins, limit = DIGEST_CHARS) {
47
+ const claims = pins.filter((pin) => pin.kind === "claim" && live(pin));
48
+ const notes = pins.filter((pin) => pin.kind !== "claim" && live(pin)).reverse();
49
+ if (!claims.length && !notes.length) return "";
50
+ const lines = ["Project board (shared by every agent on this project; read more with alp_board):"];
51
+ let size = lines[0].length;
52
+ for (const pin of [...claims, ...notes]) {
53
+ const line = `- ${renderPin(pin)}`;
54
+ if (size + line.length > limit) {
55
+ lines.push("- \u2026 more on alp_board");
56
+ break;
57
+ }
58
+ lines.push(line);
59
+ size += line.length;
60
+ }
61
+ return lines.join("\n");
62
+ }
63
+ export {
64
+ BOARD_KEEP,
65
+ BOARD_KINDS_INPUT,
66
+ PIN_BODY_CHARS,
67
+ PIN_KINDS,
68
+ PIN_PATHS,
69
+ PIN_PATHS_INPUT,
70
+ PIN_PATH_CHARS,
71
+ live,
72
+ normalizePaths,
73
+ overlapping,
74
+ renderBoard,
75
+ renderPin
76
+ };
@@ -0,0 +1,44 @@
1
+ export declare const DEFAULT_MODEL = "gpt-5.6-sol";
2
+ export declare const DEFAULT_CLAUDE_MODEL = "sonnet";
3
+ export declare const DEFAULT_ANTIGRAVITY_MODEL = "gemini-3.8-flash-high";
4
+ /** Oracle runs on one of these; main may consult both for two opinions. */
5
+ export declare const ORACLE_MODELS: string[];
6
+ export declare const ORACLE_THINKING = "high";
7
+ export declare const modes: {
8
+ id: string;
9
+ label: string;
10
+ }[];
11
+ /** Whether a session in `mode` may run with `requested`; a child never exceeds its requester. */
12
+ export declare const withinMode: (requested: string, mode: string) => boolean;
13
+ export declare const writes: (mode: string) => boolean;
14
+ export declare const thinkingOptions: {
15
+ id: string;
16
+ label: string;
17
+ }[];
18
+ export type CatalogEntry = {
19
+ runtime: 'codex' | 'claude' | 'antigravity';
20
+ id: string;
21
+ label: string;
22
+ description: string;
23
+ efforts: string[];
24
+ effort?: string;
25
+ source?: 'live' | 'fallback' | 'static';
26
+ };
27
+ /** The rows every consumer reads: core MODELS at start, replaced in place by the live catalog (model-catalog.ts). */
28
+ export declare const entries: CatalogEntry[];
29
+ export declare const models: {
30
+ defaultThinkingOptionId?: string | undefined;
31
+ id: string;
32
+ label: string;
33
+ description: string;
34
+ thinkingOptions: {
35
+ id: string;
36
+ label: string;
37
+ }[];
38
+ }[];
39
+ /** Replaces the catalog in place so every module holding `models`/`entries` sees the new rows. */
40
+ export declare function applyCatalog(next: CatalogEntry[]): void;
41
+ export declare function thinkingOptionsFor(runtime: 'codex' | 'claude' | 'antigravity', nativeModel: string): {
42
+ id: string;
43
+ label: string;
44
+ }[];
@@ -0,0 +1,47 @@
1
+ // packages/runtime/src/catalog.ts
2
+ import { MODELS, useLiveModels } from "@anhlp/alp-core/models";
3
+ var DEFAULT_MODEL = "gpt-5.6-sol";
4
+ var DEFAULT_CLAUDE_MODEL = "sonnet";
5
+ var DEFAULT_ANTIGRAVITY_MODEL = "gemini-3.8-flash-high";
6
+ var ORACLE_MODELS = ["claude:claude-fable-5-1", "codex:gpt-6-astra"];
7
+ var ORACLE_THINKING = "high";
8
+ var modes = [{ id: "read-only", label: "Read only" }, { id: "workspace-write", label: "Workspace write" }, { id: "full-access", label: "Full access" }];
9
+ var modeRank = { "read-only": 0, "workspace-write": 1, "full-access": 2 };
10
+ var withinMode = (requested, mode) => (modeRank[requested] ?? 3) <= (modeRank[mode] ?? -1);
11
+ var writes = (mode) => mode !== "read-only";
12
+ var option = (id) => ({ id, label: id });
13
+ var options = (ids) => ids.map(option);
14
+ var thinkingOptions = options(["none", "off", "low", "medium", "high", "xhigh", "max", "ultra", "ultracode"]);
15
+ var model = (runtime, id, label, description, modelThinkingOptions, defaultThinkingOptionId) => ({
16
+ id: `${runtime}:${id}`,
17
+ label: `${runtime === "codex" ? "Codex" : runtime === "claude" ? "Claude Code" : "Antigravity"} \xB7 ${label}`,
18
+ description,
19
+ thinkingOptions: modelThinkingOptions,
20
+ ...defaultThinkingOptionId ? { defaultThinkingOptionId } : {}
21
+ });
22
+ var toModel = (entry) => model(entry.runtime, entry.id, entry.label, entry.description, options(entry.efforts), entry.effort);
23
+ var entries = MODELS.map((entry) => ({ ...entry, source: "static" }));
24
+ var models = entries.map(toModel);
25
+ function applyCatalog(next) {
26
+ entries.splice(0, entries.length, ...next);
27
+ models.splice(0, models.length, ...next.map(toModel));
28
+ useLiveModels(next);
29
+ }
30
+ function thinkingOptionsFor(runtime, nativeModel) {
31
+ return models.find((candidate) => candidate.id === `${runtime}:${nativeModel}`)?.thinkingOptions ?? thinkingOptions;
32
+ }
33
+ export {
34
+ DEFAULT_ANTIGRAVITY_MODEL,
35
+ DEFAULT_CLAUDE_MODEL,
36
+ DEFAULT_MODEL,
37
+ ORACLE_MODELS,
38
+ ORACLE_THINKING,
39
+ applyCatalog,
40
+ entries,
41
+ models,
42
+ modes,
43
+ thinkingOptions,
44
+ thinkingOptionsFor,
45
+ withinMode,
46
+ writes
47
+ };
@@ -0,0 +1,251 @@
1
+ import { z } from 'zod';
2
+ export declare const toolShapes: Record<string, Record<string, z.ZodType>>;
3
+ type Listener = (method: string, params: any) => void;
4
+ type RequestHandler = (method: string, params: any) => Promise<unknown>;
5
+ /** The plugin name ALP's skills are loaded under, so Claude Code calls them alp:<name>. */
6
+ export declare const SKILL_PLUGIN = "alp";
7
+ type ListedCommand = {
8
+ name?: unknown;
9
+ builtin?: unknown;
10
+ };
11
+ /**
12
+ * t-5ac5: the aliases of /clear (new, reset) that, in this listing, run a command of the user's,
13
+ * project, plugin or MCP server rather than Claude's /clear. The SDK marks Claude's own rows
14
+ * `builtin: true`; a marked row wins its name, and an alias runs a command that has it as its name
15
+ * (SlashCommand.builtin). So /new is the user's when an unmarked row is named new and no marked row is.
16
+ * A listing without the marker (an older Claude Code) cannot tell the two apart: nothing is the
17
+ * user's then, and ALP keeps refusing /new and /reset, since letting Claude's /clear through loses the
18
+ * conversation while refusing a custom command only costs the user its name. /clear itself is always
19
+ * Claude's: a marked row is named clear.
20
+ */
21
+ export declare function customClearAliases(listed: ReadonlyArray<ListedCommand> | undefined): Set<string>;
22
+ /**
23
+ * t-e906: Claude's /clear moves it to a new conversation under a new session id while ALP keeps the
24
+ * old thread, so resume, fork and rewind would point at the conversation from before. ALP refuses it
25
+ * rather than follow: its timeline, turn ids and rewinds belong to the old conversation. /reset and /new are
26
+ * the same command, unless the session lists a command of the user's under that name (`custom`,
27
+ * from customClearAliases).
28
+ */
29
+ export declare function nativeCommandRefusal(runtimeKind: string, content: ReadonlyArray<{
30
+ type: string;
31
+ text?: string;
32
+ }>, custom?: ReadonlySet<string>): "ALP does not pass /clear (or /new, /reset) to Claude: Claude would start a new conversation that this session does not follow. Start a new session in ALP for a fresh conversation, or compact this one (alp compact, or Compact in the app)." | undefined;
33
+ /**
34
+ * A Claude Code plugin in `directory` holding the given skills, linked to their own
35
+ * directories so an edit to a skill reaches the next session (ALPD §59).
36
+ */
37
+ export declare function skillPlugin(directory: string, skills: Array<{
38
+ name: string;
39
+ path: string;
40
+ }>): string;
41
+ type PermissionRules = {
42
+ allow: string[];
43
+ ask?: string[];
44
+ deny: string[];
45
+ beyondMode?: 'refuse' | 'ask';
46
+ /** The OS sandbox ALP puts Bash in, and the directory it may write besides temp files. */
47
+ floor?: 'read-only' | 'workspace-write';
48
+ floorRoot?: string;
49
+ };
50
+ /** Whether Claude Code can sandbox Bash here: Seatbelt on macOS, bubblewrap and socat on Linux. ALP_CLAUDE_SANDBOX=0 turns it off, =1 claims it (tests). */
51
+ export declare function claudeSandboxAvailable(): boolean;
52
+ /** What ALP asks the user for a permission Claude would otherwise not have. */
53
+ /** One turn-input part as Claude's: text, or a data-URL image as a base64 image block. */
54
+ export declare function claudeContent(part: any): {
55
+ type: string;
56
+ source: {
57
+ type: string;
58
+ media_type: string;
59
+ data: string;
60
+ };
61
+ text?: undefined;
62
+ } | {
63
+ type: string;
64
+ text: any;
65
+ source?: undefined;
66
+ };
67
+ export type PermissionRequest = {
68
+ tool: string;
69
+ input: Record<string, unknown>;
70
+ reason: 'rule' | 'mode';
71
+ rule?: string;
72
+ };
73
+ export type PermissionAnswer = {
74
+ allow: boolean;
75
+ always?: boolean;
76
+ message?: string;
77
+ };
78
+ /** Claude's permission mode for an ALP mode; full-access skips every permission check. */
79
+ export declare const claudePermissionMode: (sandbox: string) => "default" | "acceptEdits" | "bypassPermissions";
80
+ export declare function claudePermissions(sandbox: string, currentSandbox?: () => string, rules?: PermissionRules | null, ask?: (request: PermissionRequest) => Promise<PermissionAnswer>): {
81
+ canUseTool: (name: string, input: Record<string, unknown>, context?: {
82
+ decisionReasonType?: string;
83
+ suggestions?: unknown;
84
+ }) => Promise<{
85
+ behavior: string;
86
+ message: string;
87
+ } | {
88
+ updatedPermissions?: {
89
+ type: string;
90
+ rules: {
91
+ ruleContent?: string | undefined;
92
+ toolName: string;
93
+ }[];
94
+ behavior: string;
95
+ destination: string;
96
+ }[] | undefined;
97
+ behavior: string;
98
+ updatedInput: Record<string, unknown>;
99
+ message?: undefined;
100
+ }>;
101
+ sandbox?: {
102
+ filesystem?: {
103
+ denyWrite: string[];
104
+ } | undefined;
105
+ enabled: boolean;
106
+ autoAllowBashIfSandboxed: boolean;
107
+ allowUnsandboxedCommands: boolean;
108
+ } | undefined;
109
+ settings?: {
110
+ permissions: {
111
+ ask: string[];
112
+ };
113
+ } | undefined;
114
+ disallowedTools: string[];
115
+ allowedTools?: string[] | undefined;
116
+ tools?: string[] | undefined;
117
+ permissionMode: string;
118
+ allowDangerouslySkipPermissions: boolean;
119
+ };
120
+ /** Whether Claude's last rate limit report means requests are refused: rejected, with no overage to fall back on. */
121
+ export declare const claudeLimited: (info?: {
122
+ status: string;
123
+ overageStatus?: string;
124
+ }) => boolean;
125
+ /**
126
+ * A Claude session's main chain, read from its transcript by the Agent SDK: user and assistant entries
127
+ * in order, with their transcript uuids. Found under `dir`'s project, else in any project (a session
128
+ * resumed or forked from another directory). Empty when the session has no transcript yet.
129
+ */
130
+ export declare function claudeChain(sessionId: string, dir?: string): Promise<Array<{
131
+ uuid: string;
132
+ type: 'user' | 'assistant';
133
+ toolResult?: boolean;
134
+ }>>;
135
+ /** Maps Claude Agent SDK streaming sessions to the normalized runtime protocol. */
136
+ export declare class ClaudeTransport {
137
+ private readonly command;
138
+ private readonly cwd;
139
+ private readonly env;
140
+ private listeners;
141
+ private failures;
142
+ private requestHandler?;
143
+ /** Whether the workspace had a .claude directory before a sandboxed session started. */
144
+ private claudeDirectory?;
145
+ private input;
146
+ private query?;
147
+ private pump?;
148
+ private config?;
149
+ private threadId;
150
+ private activeTurn?;
151
+ private closed;
152
+ private assistantText;
153
+ private streamingMessage?;
154
+ private toolCalls;
155
+ /** The last rate limit Claude reported, and whether the running turn hit one. */
156
+ private rateLimit?;
157
+ private limitedTurn;
158
+ /** The model's context window and the fill at which Claude compacts it, as Claude reports them (ALPD §57). */
159
+ private contextWindow?;
160
+ private compactAt?;
161
+ /** The compaction running now, from its start to its boundary. */
162
+ private compaction?;
163
+ /** The plugin directory that loads the agent's skills, removed on close. */
164
+ private skillDirectory?;
165
+ /** Whether a turn ran in this process; before one, an error result is a boot refusal. */
166
+ private turnsStarted;
167
+ /** Rejects when the process fails, for a resume that waits for Claude to start. */
168
+ private bootFailure?;
169
+ private rejectBoot?;
170
+ private bootError?;
171
+ constructor(command: string, cwd: string, env: NodeJS.ProcessEnv);
172
+ orchestrationContext(): Promise<{
173
+ runtime: string;
174
+ observedAt: string;
175
+ catalogAvailable: boolean;
176
+ models: {
177
+ id: string;
178
+ label: string;
179
+ description: string;
180
+ thinking: string[] | undefined;
181
+ }[];
182
+ usage: {
183
+ available: boolean;
184
+ plan?: undefined;
185
+ windows?: undefined;
186
+ } | {
187
+ available: boolean;
188
+ plan: any;
189
+ windows: {
190
+ name: string;
191
+ usedPercent: any;
192
+ remainingPercent: number | null;
193
+ resetsAt: any;
194
+ }[];
195
+ };
196
+ }>;
197
+ /**
198
+ * Claude's slash commands, skills included, for the composer (t-f628); none before the session starts.
199
+ * Not the ones whose work ALP does itself (t-efa3): /clear (/reset, /new) moves Claude to a new conversation ALP does not
200
+ * follow, and /compact and /rewind skip ALP's checkpoint and its rewind of the timeline. A command of the user's
201
+ * named new or reset is offered (t-5ac5, customClearAliases); one named clear, compact or rewind never runs, Claude's wins.
202
+ */
203
+ commands(): Promise<{
204
+ kind: "skill" | "command";
205
+ argumentHint?: string | undefined;
206
+ name: string;
207
+ description: string;
208
+ }[]>;
209
+ /** The aliases of /clear that run a command of the user's, as the last listing said (t-5ac5); none before one. */
210
+ customCommands(): ReadonlySet<string>;
211
+ private customAliases;
212
+ private listCommands;
213
+ initialize(): Promise<void>;
214
+ /** The models Claude offers now, from a Claude process that sends no prompt and is closed after (t-e5ee). */
215
+ probeModels(signal?: AbortSignal): Promise<{
216
+ id: string;
217
+ label: string;
218
+ description: string;
219
+ efforts: string[] | undefined;
220
+ }[]>;
221
+ /** The plan's usage windows before a session starts, from a Claude process that sends no prompt and is closed after. */
222
+ private probeUsage;
223
+ onNotification(listener: Listener): () => boolean;
224
+ onFailure(listener: (error: Error) => void): () => boolean;
225
+ onRequest(handler: RequestHandler): void;
226
+ request(method: string, params: any): Promise<any>;
227
+ /**
228
+ * How a resume starts. With a base, a session whose transcript does not exist yet is made from the
229
+ * base's conversation cut at `at` (a fork or rewind, §12.7): Claude writes it, under this session's
230
+ * id, only when its first prompt runs. Otherwise, the session's own transcript.
231
+ */
232
+ private resumeFrom;
233
+ /**
234
+ * Waits until Claude has started: its answer to the SDK's initialize request, or the failure that
235
+ * ends it first. Past BOOT_MS ALP goes on, as any resume does, and a later refusal fails the session.
236
+ */
237
+ private booted;
238
+ private start;
239
+ /** Reads the window and the compaction threshold Claude resolved for this session, before any turn. */
240
+ private measureContext;
241
+ private convertMcp;
242
+ private consume;
243
+ private handle;
244
+ private refuseBoot;
245
+ private emit;
246
+ private assistantState;
247
+ private clearAssistantText;
248
+ private fail;
249
+ close(): Promise<void>;
250
+ }
251
+ export {};