@anhlp/alp-runtime 0.0.1-beta.7 → 0.0.1-beta.9
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.
- package/dist/acp-transport.js +2 -0
- package/dist/antigravity-transport.d.ts +10 -2
- package/dist/antigravity-transport.js +26 -4
- package/dist/assignment-results.d.ts +5 -2
- package/dist/assignment-results.js +27 -15
- package/dist/catalog.js +2 -1
- package/dist/claude-transport.d.ts +33 -2
- package/dist/claude-transport.js +48 -9
- package/dist/contracts.d.ts +12 -1
- package/dist/index.d.ts +4 -3
- package/dist/index.js +9 -2
- package/dist/language.d.ts +2 -0
- package/dist/language.js +6 -0
- package/dist/live.d.ts +2 -2
- package/dist/live.js +7 -2
- package/dist/model-catalog.d.ts +87 -1
- package/dist/model-catalog.js +151 -6
- package/dist/model-probes.d.ts +1 -1
- package/dist/model-probes.js +2 -2
- package/dist/recall.d.ts +2 -2
- package/dist/recall.js +4 -3
- package/dist/resolve.js +4 -4
- package/dist/runtime.js +243 -33
- package/dist/session-config.d.ts +75 -6
- package/dist/session-config.js +9 -5
- package/dist/session-state.d.ts +2 -0
- package/dist/skill-resources.d.ts +30 -0
- package/dist/skill-resources.js +55 -0
- package/dist/tools.d.ts +27 -1
- package/dist/tools.js +20 -1
- package/dist/write-error.d.ts +2 -0
- package/dist/write-error.js +10 -0
- package/package.json +4 -4
- package/src/acp-transport.ts +3 -0
- package/src/antigravity-transport.ts +39 -8
- package/src/assignment-results.ts +23 -15
- package/src/catalog.ts +3 -1
- package/src/claude-transport.ts +87 -10
- package/src/contracts.ts +12 -0
- package/src/index.ts +4 -3
- package/src/language.ts +10 -0
- package/src/live.ts +7 -3
- package/src/model-catalog.ts +156 -6
- package/src/model-probes.ts +2 -2
- package/src/recall.ts +4 -3
- package/src/resolve.ts +9 -5
- package/src/runtime.ts +255 -29
- package/src/session-config.ts +13 -5
- package/src/session-state.ts +2 -0
- package/src/skill-resources.ts +73 -0
- package/src/tools.ts +22 -1
- package/src/write-error.ts +4 -0
package/dist/acp-transport.js
CHANGED
|
@@ -11,6 +11,7 @@ import { commandDecision, unwrapShell } from "@anhlp/alp-core/permissions";
|
|
|
11
11
|
import { launchCommand } from "@anhlp/alp-core/providers";
|
|
12
12
|
import { bridgeCommand } from "@anhlp/alp-core/bridges";
|
|
13
13
|
import { acpText, acpToolDetail } from "./tool-detail.js";
|
|
14
|
+
import { feedAcpSession } from "./model-catalog.js";
|
|
14
15
|
var READERS = ["read", "search", "think", "fetch"];
|
|
15
16
|
function acpPermission(toolCall, tools) {
|
|
16
17
|
const raw = toolCall?.rawInput;
|
|
@@ -158,6 +159,7 @@ var AcpTransport = class {
|
|
|
158
159
|
} else {
|
|
159
160
|
const result = await this.call("session/new", { cwd: params.cwd, mcpServers }, 12e4);
|
|
160
161
|
this.sessionId = result.sessionId;
|
|
162
|
+
feedAcpSession(this.provider.id, result);
|
|
161
163
|
await this.chooseModel(result.models, result.configOptions);
|
|
162
164
|
}
|
|
163
165
|
return { thread: { id: this.sessionId, turns: [] }, cwd: params.cwd, model: params.model, reasoningEffort: params.thinking };
|
|
@@ -18,11 +18,14 @@ export type AntigravityProvider = {
|
|
|
18
18
|
description?: string;
|
|
19
19
|
}>;
|
|
20
20
|
enabled?: boolean;
|
|
21
|
-
/** Explicit opt-in: read-only is a prompt constraint, never a native sandbox. */
|
|
22
|
-
readOnlyMode?: 'instructions' | 'reject';
|
|
23
21
|
};
|
|
24
22
|
type Listener = (method: string, params: any) => void;
|
|
25
23
|
type RequestHandler = (method: string, params: any) => Promise<unknown>;
|
|
24
|
+
/**
|
|
25
|
+
* Whether read-only allows a terminal command line, by ALP's own reading of the allowlist:
|
|
26
|
+
* one allowed command with no shell syntax. Unknown input is refused.
|
|
27
|
+
*/
|
|
28
|
+
export declare function antigravityReadOnlyCommandAllowed(commandLine: unknown): boolean;
|
|
26
29
|
/**
|
|
27
30
|
* The agy flags for an ALP mode. Headless agy cannot ask the user, so a tool its
|
|
28
31
|
* permission mode does not allow is denied: both limited modes fail closed.
|
|
@@ -35,6 +38,9 @@ type RequestHandler = (method: string, params: any) => Promise<unknown>;
|
|
|
35
38
|
* reads and edits there) and allow ALP's own MCP server, which carries alp_*.
|
|
36
39
|
*/
|
|
37
40
|
export declare function antigravityModeArgs(sandbox: unknown, cwd: string): string[];
|
|
41
|
+
/** Efforts `agy --effort` takes (agy --help: low|medium|high|xhigh|max); others leave agy's default. */
|
|
42
|
+
export declare const AGY_EFFORTS: string[];
|
|
43
|
+
export declare function antigravityEffortArgs(thinking: unknown): string[];
|
|
38
44
|
/** What each mode lets an Antigravity agent do, for its instructions. */
|
|
39
45
|
export declare function antigravityModeText(sandbox: unknown): string;
|
|
40
46
|
export declare function encodePrompt(text: string): string;
|
|
@@ -80,6 +86,8 @@ export declare class AntigravityTransport {
|
|
|
80
86
|
private startProcess;
|
|
81
87
|
private receiveLine;
|
|
82
88
|
private handleStepUpdate;
|
|
89
|
+
/** Whether read-only refuses this tool step: an edit, or a terminal command outside the allowlist. */
|
|
90
|
+
private readOnlyRefuses;
|
|
83
91
|
private handleResult;
|
|
84
92
|
private endTurn;
|
|
85
93
|
private openBridge;
|
|
@@ -11,7 +11,14 @@ import { openMcpTools } from "./mcp-tools.js";
|
|
|
11
11
|
import { antigravityToolDetail } from "./tool-detail.js";
|
|
12
12
|
import { bridgeCommand, isBridgeArgs } from "@anhlp/alp-core/bridges";
|
|
13
13
|
var MODES = ["read-only", "workspace-write", "full-access"];
|
|
14
|
-
var READ_ONLY_COMMANDS = ["pwd"
|
|
14
|
+
var READ_ONLY_COMMANDS = ["pwd"];
|
|
15
|
+
var SHELL_SYNTAX = /[;&|<>`$(){}\\\n\r]/;
|
|
16
|
+
function antigravityReadOnlyCommandAllowed(commandLine) {
|
|
17
|
+
if (typeof commandLine !== "string" || SHELL_SYNTAX.test(commandLine)) return false;
|
|
18
|
+
const [command] = commandLine.trim().split(/\s+/);
|
|
19
|
+
return READ_ONLY_COMMANDS.includes(command);
|
|
20
|
+
}
|
|
21
|
+
var COMMAND_TOOLS = /* @__PURE__ */ new Set(["run_command"]);
|
|
15
22
|
var EDIT_TOOLS = /* @__PURE__ */ new Set(["write_file", "write_to_file", "replace_file_content", "multi_replace_file_content", "sed_file", "notebook_edit"]);
|
|
16
23
|
var modeOf = (sandbox) => sandbox === "danger-full-access" ? "full-access" : String(sandbox);
|
|
17
24
|
function antigravityModeArgs(sandbox, cwd) {
|
|
@@ -31,9 +38,13 @@ function antigravityModeArgs(sandbox, cwd) {
|
|
|
31
38
|
};
|
|
32
39
|
return [...mode === "workspace-write" ? ["--mode", "accept-edits"] : [], "--sandbox", "--settings", JSON.stringify(settings)];
|
|
33
40
|
}
|
|
41
|
+
var AGY_EFFORTS = ["low", "medium", "high", "xhigh", "max"];
|
|
42
|
+
function antigravityEffortArgs(thinking) {
|
|
43
|
+
return typeof thinking === "string" && AGY_EFFORTS.includes(thinking) ? ["--effort", thinking] : [];
|
|
44
|
+
}
|
|
34
45
|
function antigravityModeText(sandbox) {
|
|
35
46
|
const mode = modeOf(sandbox);
|
|
36
|
-
if (mode === "read-only") return "agy enforces read-only: its own file reading and search tools work, and ALP's tools; it allows only the terminal
|
|
47
|
+
if (mode === "read-only") return "agy enforces read-only: its own file reading and search tools work, and ALP's tools; it allows only the terminal command pwd, with no redirection or chaining (read files with its own tools), and denies every file edit and other command. A denied tool ends your turn, so do not attempt one: report work that needs changes to your requester.";
|
|
37
48
|
if (mode === "workspace-write") return "agy accepts file edits and runs terminal commands in its sandbox, which writes only inside your workspace; anything outside the workspace or the sandbox is denied, and a denied tool ends your turn. Report work that needs more to your requester.";
|
|
38
49
|
return "Antigravity runs with full access: every tool runs without asking.";
|
|
39
50
|
}
|
|
@@ -195,6 +206,7 @@ ${promptText}`;
|
|
|
195
206
|
if (params.model) {
|
|
196
207
|
args.push("--model", params.model);
|
|
197
208
|
}
|
|
209
|
+
args.push(...antigravityEffortArgs(params.thinking));
|
|
198
210
|
if (params.threadId) {
|
|
199
211
|
args.push("--conversation", params.threadId);
|
|
200
212
|
}
|
|
@@ -343,8 +355,8 @@ ${promptText}`;
|
|
|
343
355
|
}
|
|
344
356
|
});
|
|
345
357
|
} else if (step.state === "DONE" || step.state === "ERROR") {
|
|
346
|
-
if (step.state === "DONE" && modeOf(this.config?.sandbox) === "read-only" &&
|
|
347
|
-
step = { ...step, state: "ERROR", tool_info: { ...step.tool_info, output: void 0, error: { message: `Antigravity denied ${
|
|
358
|
+
if (step.state === "DONE" && modeOf(this.config?.sandbox) === "read-only" && this.readOnlyRefuses(toolName, step.tool_info)) {
|
|
359
|
+
step = { ...step, state: "ERROR", tool_info: { ...step.tool_info, output: void 0, error: { message: `Antigravity denied ${typed.tool} in read-only mode` } } };
|
|
348
360
|
}
|
|
349
361
|
const output = typeof step.tool_info?.output === "string" ? step.tool_info.output : step.tool_info?.error?.message || "";
|
|
350
362
|
this.emit("item/completed", {
|
|
@@ -364,6 +376,13 @@ ${promptText}`;
|
|
|
364
376
|
}
|
|
365
377
|
}
|
|
366
378
|
}
|
|
379
|
+
/** Whether read-only refuses this tool step: an edit, or a terminal command outside the allowlist. */
|
|
380
|
+
readOnlyRefuses(toolName, info) {
|
|
381
|
+
const name = typeof info?.name === "string" && info.name ? info.name : toolName;
|
|
382
|
+
if (EDIT_TOOLS.has(toolName) || EDIT_TOOLS.has(name)) return true;
|
|
383
|
+
if (COMMAND_TOOLS.has(toolName) || COMMAND_TOOLS.has(name)) return !antigravityReadOnlyCommandAllowed(info?.parameters?.CommandLine);
|
|
384
|
+
return false;
|
|
385
|
+
}
|
|
367
386
|
handleResult(result) {
|
|
368
387
|
if (!this.activeTurn) return;
|
|
369
388
|
const turnId = this.activeTurn;
|
|
@@ -636,8 +655,11 @@ ${promptText}`;
|
|
|
636
655
|
}
|
|
637
656
|
};
|
|
638
657
|
export {
|
|
658
|
+
AGY_EFFORTS,
|
|
639
659
|
AntigravityTransport,
|
|
660
|
+
antigravityEffortArgs,
|
|
640
661
|
antigravityModeArgs,
|
|
641
662
|
antigravityModeText,
|
|
663
|
+
antigravityReadOnlyCommandAllowed,
|
|
642
664
|
encodePrompt
|
|
643
665
|
};
|
|
@@ -35,8 +35,11 @@ type Ledger = {
|
|
|
35
35
|
};
|
|
36
36
|
/** Archived results stay this long after the month they were archived in ends; ledger entries never expire. */
|
|
37
37
|
export declare const ARCHIVE_KEEP_MS: number;
|
|
38
|
-
/**
|
|
39
|
-
|
|
38
|
+
/**
|
|
39
|
+
* Permanent ownership, independent of native-thread recall expiry. Missing initialized data is never recreated.
|
|
40
|
+
* A failed write still fails its caller; `onError` hears of it too, so a full disk is seen at once.
|
|
41
|
+
*/
|
|
42
|
+
export declare function createAssignmentResults(file?: string, onError?: (error: unknown) => void): {
|
|
40
43
|
register(directory: string): Promise<void>;
|
|
41
44
|
put(entry: AssignmentResultOwner): Promise<void>;
|
|
42
45
|
remove(assignmentId: string): Promise<void>;
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import { readFile, readdir, mkdir, writeFile, open, rm } from "node:fs/promises";
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
import { writeAtomic } from "@anhlp/alp-core/atomic";
|
|
5
|
+
import { tell } from "./write-error.js";
|
|
5
6
|
var RESULT_OUTCOMES = ["applied", "discarded", "acknowledged"];
|
|
6
7
|
var ARCHIVE_KEEP_MS = 365 * 24 * 60 * 60 * 1e3;
|
|
7
8
|
var empty = () => ({ version: 1, workspaces: [], results: [] });
|
|
@@ -11,7 +12,8 @@ var evidence = (value) => value === void 0 || !!value && typeof value === "objec
|
|
|
11
12
|
var handling = (value) => value === void 0 || !!value && typeof value === "object" && !Array.isArray(value) && RESULT_OUTCOMES.includes(value.outcome) && text(value.by) && text(value.at) && (value.note === void 0 || text(value.note));
|
|
12
13
|
var valid = (value) => value?.version === 1 && Array.isArray(value.workspaces) && value.workspaces.every(absolute) && Array.isArray(value.results) && value.results.every((entry) => entry && typeof entry.assignmentId === "string" && absolute(entry.checkout) && (entry.worktree === void 0 || absolute(entry.worktree)) && evidence(entry.result) && handling(entry.handled));
|
|
13
14
|
var MONTH = /^(\d{4})-(\d{2})\.jsonl$/;
|
|
14
|
-
function createAssignmentResults(file) {
|
|
15
|
+
function createAssignmentResults(file, onError = () => {
|
|
16
|
+
}) {
|
|
15
17
|
let memory = empty();
|
|
16
18
|
let archivedInMemory = [];
|
|
17
19
|
let queue = Promise.resolve();
|
|
@@ -40,11 +42,16 @@ function createAssignmentResults(file) {
|
|
|
40
42
|
memory = value;
|
|
41
43
|
return;
|
|
42
44
|
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
45
|
+
try {
|
|
46
|
+
await mkdir(path.dirname(file), { recursive: true, mode: 448 });
|
|
47
|
+
await writeAtomic(file, JSON.stringify(value) + "\n");
|
|
48
|
+
await writeFile(marker, "1\n", { flag: "wx", mode: 384 }).catch((error) => {
|
|
49
|
+
if (error.code !== "EEXIST") throw error;
|
|
50
|
+
});
|
|
51
|
+
} catch (error) {
|
|
52
|
+
tell(onError, error);
|
|
53
|
+
throw error;
|
|
54
|
+
}
|
|
48
55
|
}
|
|
49
56
|
function serialize(run) {
|
|
50
57
|
const result = queue.then(run);
|
|
@@ -58,17 +65,22 @@ function createAssignmentResults(file) {
|
|
|
58
65
|
archivedInMemory.push(record);
|
|
59
66
|
return;
|
|
60
67
|
}
|
|
61
|
-
await mkdir(archiveDir, { recursive: true, mode: 448 });
|
|
62
|
-
const handle = await open(path.join(archiveDir, `${record.archivedAt.slice(0, 7)}.jsonl`), "a+", 384);
|
|
63
68
|
try {
|
|
64
|
-
|
|
65
|
-
const
|
|
66
|
-
|
|
67
|
-
|
|
69
|
+
await mkdir(archiveDir, { recursive: true, mode: 448 });
|
|
70
|
+
const handle = await open(path.join(archiveDir, `${record.archivedAt.slice(0, 7)}.jsonl`), "a+", 384);
|
|
71
|
+
try {
|
|
72
|
+
const { size } = await handle.stat();
|
|
73
|
+
const last = Buffer.alloc(1);
|
|
74
|
+
const torn = size > 0 && (await handle.read(last, 0, 1, size - 1)).bytesRead === 1 && last[0] !== 10;
|
|
75
|
+
await handle.appendFile(`${torn ? "\n" : ""}${JSON.stringify(record)}
|
|
68
76
|
`);
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
77
|
+
await handle.sync();
|
|
78
|
+
} finally {
|
|
79
|
+
await handle.close();
|
|
80
|
+
}
|
|
81
|
+
} catch (error) {
|
|
82
|
+
tell(onError, error);
|
|
83
|
+
throw error;
|
|
72
84
|
}
|
|
73
85
|
}
|
|
74
86
|
async function archived() {
|
package/dist/catalog.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// packages/runtime/src/catalog.ts
|
|
2
|
-
import { MODELS } from "@anhlp/alp-core/models";
|
|
2
|
+
import { MODELS, useLiveModels } from "@anhlp/alp-core/models";
|
|
3
3
|
var DEFAULT_MODEL = "gpt-5.6-sol";
|
|
4
4
|
var DEFAULT_CLAUDE_MODEL = "sonnet";
|
|
5
5
|
var DEFAULT_ANTIGRAVITY_MODEL = "gemini-3.8-flash-high";
|
|
@@ -25,6 +25,7 @@ var models = entries.map(toModel);
|
|
|
25
25
|
function applyCatalog(next) {
|
|
26
26
|
entries.splice(0, entries.length, ...next);
|
|
27
27
|
models.splice(0, models.length, ...next.map(toModel));
|
|
28
|
+
useLiveModels(next);
|
|
28
29
|
}
|
|
29
30
|
function thinkingOptionsFor(runtime, nativeModel) {
|
|
30
31
|
return models.find((candidate) => candidate.id === `${runtime}:${nativeModel}`)?.thinkingOptions ?? thinkingOptions;
|
|
@@ -4,6 +4,32 @@ type Listener = (method: string, params: any) => void;
|
|
|
4
4
|
type RequestHandler = (method: string, params: any) => Promise<unknown>;
|
|
5
5
|
/** The plugin name ALP's skills are loaded under, so Claude Code calls them alp:<name>. */
|
|
6
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;
|
|
7
33
|
/**
|
|
8
34
|
* A Claude Code plugin in `directory` holding the given skills, linked to their own
|
|
9
35
|
* directories so an edit to a skill reaches the next session (ALPD §59).
|
|
@@ -170,8 +196,9 @@ export declare class ClaudeTransport {
|
|
|
170
196
|
}>;
|
|
171
197
|
/**
|
|
172
198
|
* Claude's slash commands, skills included, for the composer (t-f628); none before the session starts.
|
|
173
|
-
* Not the ones whose work ALP does itself (t-efa3): /clear moves Claude to a new conversation ALP does not
|
|
174
|
-
* follow, and /compact and /rewind skip ALP's checkpoint and its rewind of the timeline.
|
|
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.
|
|
175
202
|
*/
|
|
176
203
|
commands(): Promise<{
|
|
177
204
|
kind: "skill" | "command";
|
|
@@ -179,6 +206,10 @@ export declare class ClaudeTransport {
|
|
|
179
206
|
name: string;
|
|
180
207
|
description: string;
|
|
181
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;
|
|
182
213
|
initialize(): Promise<void>;
|
|
183
214
|
/** The models Claude offers now, from a Claude process that sends no prompt and is closed after (t-e5ee). */
|
|
184
215
|
probeModels(signal?: AbortSignal): Promise<{
|
package/dist/claude-transport.js
CHANGED
|
@@ -12,8 +12,10 @@ import { inputLimitError, POUR_VARS, VAR_NAME } from "./input-limits.js";
|
|
|
12
12
|
import { claudeToolDetail, resultText } from "./tool-detail.js";
|
|
13
13
|
import { CLOSE_REASONS, GATE_KINDS, TASK_STATUSES, TASK_TYPES } from "@anhlp/alp-core/tasks";
|
|
14
14
|
import { commandDecision } from "@anhlp/alp-core/permissions";
|
|
15
|
+
import { isScript, nativeDaemon, nodeExecutable } from "@anhlp/alp-core/packaged";
|
|
15
16
|
var CLAUDE_SDK = ["@anthropic-ai", "claude-agent-sdk"].join("/");
|
|
16
|
-
var claudeSdk = () => import(CLAUDE_SDK);
|
|
17
|
+
var claudeSdk = () => nativeDaemon()?.modules.claudeAgentSdk?.() ?? import(CLAUDE_SDK);
|
|
18
|
+
var scriptExecutable = (command) => nativeDaemon() && (isScript(command) || /\.(ts|tsx|jsx)$/i.test(command)) ? { executable: nodeExecutable() } : {};
|
|
17
19
|
var bounded = (schema, limits) => z.preprocess((value, ctx) => {
|
|
18
20
|
const error = inputLimitError(value, limits);
|
|
19
21
|
if (error) ctx.addIssue({ code: "custom", message: error });
|
|
@@ -71,6 +73,11 @@ var toolShapes = {
|
|
|
71
73
|
replace: z.boolean().optional(),
|
|
72
74
|
requestId: z.string().min(1).max(100).optional()
|
|
73
75
|
},
|
|
76
|
+
alp_skill_retire: {
|
|
77
|
+
name: z.string().min(1).max(64),
|
|
78
|
+
reason: z.string().min(1).max(300),
|
|
79
|
+
requestId: z.string().min(1).max(100).optional()
|
|
80
|
+
},
|
|
74
81
|
alp_issue: {
|
|
75
82
|
action: z.enum(["search", "create", "comment"]),
|
|
76
83
|
target: z.enum(["project", "alp"]),
|
|
@@ -175,7 +182,23 @@ var toolShapes = {
|
|
|
175
182
|
}
|
|
176
183
|
};
|
|
177
184
|
var SKILL_PLUGIN = "alp";
|
|
178
|
-
var
|
|
185
|
+
var NEW_CONVERSATION_COMMANDS = ["clear", "reset", "new"];
|
|
186
|
+
var NEW_CONVERSATION = new RegExp(`^\\s*\\/(${NEW_CONVERSATION_COMMANDS.join("|")})(?:\\s|$)`);
|
|
187
|
+
var ALP_HANDLED_COMMANDS = /* @__PURE__ */ new Set([...NEW_CONVERSATION_COMMANDS, "compact", "rewind"]);
|
|
188
|
+
var CLEAR_ALIASES = /* @__PURE__ */ new Set(["reset", "new"]);
|
|
189
|
+
function customClearAliases(listed) {
|
|
190
|
+
const rows = Array.isArray(listed) ? listed : [];
|
|
191
|
+
if (!rows.some((row) => typeof row?.builtin === "boolean")) return /* @__PURE__ */ new Set();
|
|
192
|
+
const builtin = new Set(rows.filter((row) => row?.builtin === true).map((row) => row.name));
|
|
193
|
+
return new Set(rows.filter((row) => row?.builtin !== true && typeof row?.name === "string" && CLEAR_ALIASES.has(row.name) && !builtin.has(row.name)).map((row) => row.name));
|
|
194
|
+
}
|
|
195
|
+
function nativeCommandRefusal(runtimeKind, content, custom) {
|
|
196
|
+
if (runtimeKind !== "claude") return void 0;
|
|
197
|
+
const typed = content.filter((part) => part.type === "text").map((part) => part.text ?? "").join("\n");
|
|
198
|
+
const named = NEW_CONVERSATION.exec(typed)?.[1];
|
|
199
|
+
if (!named || custom?.has(named)) return void 0;
|
|
200
|
+
return "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).";
|
|
201
|
+
}
|
|
179
202
|
function skillPlugin(directory, skills) {
|
|
180
203
|
rmSync(directory, { recursive: true, force: true });
|
|
181
204
|
mkdirSync(path.join(directory, ".claude-plugin"), { recursive: true });
|
|
@@ -379,25 +402,37 @@ var ClaudeTransport = class {
|
|
|
379
402
|
}
|
|
380
403
|
/**
|
|
381
404
|
* Claude's slash commands, skills included, for the composer (t-f628); none before the session starts.
|
|
382
|
-
* Not the ones whose work ALP does itself (t-efa3): /clear moves Claude to a new conversation ALP does not
|
|
383
|
-
* follow, and /compact and /rewind skip ALP's checkpoint and its rewind of the timeline.
|
|
405
|
+
* Not the ones whose work ALP does itself (t-efa3): /clear (/reset, /new) moves Claude to a new conversation ALP does not
|
|
406
|
+
* follow, and /compact and /rewind skip ALP's checkpoint and its rewind of the timeline. A command of the user's
|
|
407
|
+
* named new or reset is offered (t-5ac5, customClearAliases); one named clear, compact or rewind never runs, Claude's wins.
|
|
384
408
|
*/
|
|
385
409
|
async commands() {
|
|
386
|
-
const listed =
|
|
387
|
-
|
|
410
|
+
const listed = await this.listCommands();
|
|
411
|
+
const custom = customClearAliases(listed);
|
|
412
|
+
return (Array.isArray(listed) ? listed : []).filter((command) => typeof command?.name === "string" && command.name && (!ALP_HANDLED_COMMANDS.has(command.name) || command.builtin !== true && custom.has(command.name))).map((command) => ({
|
|
388
413
|
name: command.name,
|
|
389
414
|
description: typeof command.description === "string" ? command.description : "",
|
|
390
415
|
...command.argumentHint ? { argumentHint: command.argumentHint } : {},
|
|
391
416
|
kind: command.name.startsWith(`${SKILL_PLUGIN}:`) ? "skill" : "command"
|
|
392
417
|
}));
|
|
393
418
|
}
|
|
419
|
+
/** The aliases of /clear that run a command of the user's, as the last listing said (t-5ac5); none before one. */
|
|
420
|
+
customCommands() {
|
|
421
|
+
return this.customAliases;
|
|
422
|
+
}
|
|
423
|
+
customAliases = /* @__PURE__ */ new Set();
|
|
424
|
+
async listCommands() {
|
|
425
|
+
const listed = this.query ? await optionalRead(async () => this.query.supportedCommands(), 1e4) : void 0;
|
|
426
|
+
if (Array.isArray(listed)) this.customAliases = customClearAliases(listed);
|
|
427
|
+
return listed;
|
|
428
|
+
}
|
|
394
429
|
async initialize() {
|
|
395
430
|
}
|
|
396
431
|
/** The models Claude offers now, from a Claude process that sends no prompt and is closed after (t-e5ee). */
|
|
397
432
|
async probeModels(signal) {
|
|
398
433
|
const { query } = await claudeSdk();
|
|
399
434
|
if (signal?.aborted) throw new Error("aborted");
|
|
400
|
-
const probe = query({ prompt: new InputQueue(), options: { cwd: this.cwd, env: this.env, settingSources: [], persistSession: false, strictMcpConfig: true, mcpServers: {}, pathToClaudeCodeExecutable: this.command } });
|
|
435
|
+
const probe = query({ prompt: new InputQueue(), options: { cwd: this.cwd, env: this.env, settingSources: [], persistSession: false, strictMcpConfig: true, mcpServers: {}, pathToClaudeCodeExecutable: this.command, ...scriptExecutable(this.command) } });
|
|
401
436
|
const stop = () => probe.close();
|
|
402
437
|
signal?.addEventListener("abort", stop);
|
|
403
438
|
try {
|
|
@@ -412,7 +447,7 @@ var ClaudeTransport = class {
|
|
|
412
447
|
async probeUsage() {
|
|
413
448
|
if (this.closed) return void 0;
|
|
414
449
|
const { query } = await claudeSdk();
|
|
415
|
-
const probe = query({ prompt: new InputQueue(), options: { cwd: this.cwd, env: this.env, settingSources: [], persistSession: false, strictMcpConfig: true, mcpServers: {}, pathToClaudeCodeExecutable: this.command } });
|
|
450
|
+
const probe = query({ prompt: new InputQueue(), options: { cwd: this.cwd, env: this.env, settingSources: [], persistSession: false, strictMcpConfig: true, mcpServers: {}, pathToClaudeCodeExecutable: this.command, ...scriptExecutable(this.command) } });
|
|
416
451
|
try {
|
|
417
452
|
return await probe.usage_EXPERIMENTAL_MAY_CHANGE_DO_NOT_RELY_ON_THIS_API_YET({ skipBehaviors: true });
|
|
418
453
|
} finally {
|
|
@@ -636,7 +671,8 @@ var ClaudeTransport = class {
|
|
|
636
671
|
includePartialMessages: true,
|
|
637
672
|
...from ? { resume: from.resume, ...from.fork ? { forkSession: true, sessionId: this.threadId } : {}, ...from.at ? { resumeSessionAt: from.at } : {} } : { sessionId: this.threadId },
|
|
638
673
|
// Explicit native path avoids SDK optional binaries inside Electron app.asar.
|
|
639
|
-
pathToClaudeCodeExecutable: this.command
|
|
674
|
+
pathToClaudeCodeExecutable: this.command,
|
|
675
|
+
...scriptExecutable(this.command)
|
|
640
676
|
};
|
|
641
677
|
this.bootFailure = new Promise((_, reject) => {
|
|
642
678
|
this.rejectBoot = reject;
|
|
@@ -646,6 +682,7 @@ var ClaudeTransport = class {
|
|
|
646
682
|
this.query = query({ prompt: this.input, options });
|
|
647
683
|
this.pump = this.consume(this.query).catch((error) => this.fail(error));
|
|
648
684
|
void this.measureContext();
|
|
685
|
+
void this.listCommands();
|
|
649
686
|
}
|
|
650
687
|
/** Reads the window and the compaction threshold Claude resolved for this session, before any turn. */
|
|
651
688
|
async measureContext() {
|
|
@@ -887,6 +924,8 @@ export {
|
|
|
887
924
|
claudePermissionMode,
|
|
888
925
|
claudePermissions,
|
|
889
926
|
claudeSandboxAvailable,
|
|
927
|
+
customClearAliases,
|
|
928
|
+
nativeCommandRefusal,
|
|
890
929
|
skillPlugin,
|
|
891
930
|
toolShapes
|
|
892
931
|
};
|
package/dist/contracts.d.ts
CHANGED
|
@@ -21,6 +21,8 @@ export type RuntimeTransport = {
|
|
|
21
21
|
orchestrationContext?: () => Promise<unknown>;
|
|
22
22
|
/** The runtime's own slash commands and skills for the composer (t-f628); omitted, the runtime offers none. */
|
|
23
23
|
commands?: () => Promise<RuntimeCommand[]>;
|
|
24
|
+
/** Claude: the aliases of /clear (new, reset) that run a command of the user's, so they are not refused (t-5ac5). */
|
|
25
|
+
customCommands?: () => ReadonlySet<string>;
|
|
24
26
|
onNotification(listener: (method: string, params: any) => void): void;
|
|
25
27
|
onFailure(listener: (error: unknown) => void): void;
|
|
26
28
|
close(): Promise<void>;
|
|
@@ -92,6 +94,13 @@ export type RuntimeOptions = {
|
|
|
92
94
|
limitCheckMs?: number;
|
|
93
95
|
/** Where running assignments are kept, so the next alpd continues them (ALPD §31). Omitted keeps them in memory. */
|
|
94
96
|
liveFile?: string;
|
|
97
|
+
/**
|
|
98
|
+
* Told of every failed write to pauseFile, liveFile, recallFile and assignmentResultFile, as it
|
|
99
|
+
* happens, so the host's disk guard pauses work on a full disk at once (t-e80a). Each write still
|
|
100
|
+
* fails as before: pauses and recall go on in memory, live entries are logged, and result
|
|
101
|
+
* ownership is refused to its caller.
|
|
102
|
+
*/
|
|
103
|
+
onWriteError?: (error: unknown) => void;
|
|
95
104
|
/** False parks assignments an earlier alpd left running until the user runs alp resume. Default true: they continue. */
|
|
96
105
|
recoveryResume?: boolean;
|
|
97
106
|
/** How the previous alpd ended, for what recovered sessions are told. */
|
|
@@ -104,7 +113,7 @@ export type RuntimeOptions = {
|
|
|
104
113
|
/** Runs the GitHub CLI for alp_issue. Default: `gh` (or ALP_GH_BIN) on PATH. */
|
|
105
114
|
github?: GitHubRunner;
|
|
106
115
|
};
|
|
107
|
-
import type { NativeBase, OpenOptions, PromptInput } from '@anhlp/alp-protocol/session';
|
|
116
|
+
import type { NativeBase, OpenOptions, PromptContent, PromptInput } from '@anhlp/alp-protocol/session';
|
|
108
117
|
export type { NativeBase, OpenOptions, PromptContent, PromptInput } from '@anhlp/alp-protocol/session';
|
|
109
118
|
export type ScheduleHandler = (action: 'create' | 'list' | 'get' | 'cancel', params: Record<string, unknown>) => Promise<unknown>;
|
|
110
119
|
export type AlpRuntime = {
|
|
@@ -114,6 +123,8 @@ export type AlpRuntime = {
|
|
|
114
123
|
bindAttachments?: (reader: AttachmentReader | undefined) => void;
|
|
115
124
|
/** Whether this live session's runtime takes `{ type: 'attachment' }` parts (RuntimeAttachment) now. */
|
|
116
125
|
takesAttachments?: (sessionId: string) => boolean;
|
|
126
|
+
/** Why this live session's runtime refuses this prompt before it is sent (t-e906), or undefined. */
|
|
127
|
+
refusesPrompt?: (sessionId: string, content: PromptContent) => string | undefined;
|
|
117
128
|
/** Removes the staged copy of an attachment alpd no longer keeps. */
|
|
118
129
|
dropAttachment?: (attachmentId: string) => Promise<void>;
|
|
119
130
|
onEvent(listener: (envelope: Envelope) => void): () => void;
|
package/dist/index.d.ts
CHANGED
|
@@ -4,11 +4,12 @@ export { ConversationError } from './contracts.js';
|
|
|
4
4
|
export type { RuntimeCommand, BranchRequest, ConversationErrorReason, NativeBase, NativeBinding, ConfigureChanges, ConfigureResult, ConfigurePreview, EffectiveConfig } from './contracts.js';
|
|
5
5
|
export type { AlpEvent, AlpError, Envelope, SessionSnapshot, TimelineItem, TurnOrigin, AssignmentSnapshot, UserQuestion, TreeStatus, SessionState } from './events.js';
|
|
6
6
|
export { resolveSession, InstructionsAdapter, skillDescription } from './resolve.js';
|
|
7
|
+
export { resourceUses, pathActions } from './skill-resources.js';
|
|
7
8
|
export type { SessionSpec, HostMcpServer, ResolvedSession, RuntimeKind } from './resolve.js';
|
|
8
9
|
export { DEFAULT_MODEL, DEFAULT_CLAUDE_MODEL, entries as catalogEntries, models, modes, thinkingOptions, thinkingOptionsFor } from './catalog.js';
|
|
9
10
|
export type { CatalogEntry } from './catalog.js';
|
|
10
|
-
export { ModelCatalog, mergeCatalog, liveFromContext, feedCatalog, setActiveCatalog, activeCatalog, POLICY as CATALOG_POLICY, REFRESH_MS as CATALOG_REFRESH_MS } from './model-catalog.js';
|
|
11
|
-
export type { CatalogSnapshot, CatalogRuntime, LiveModel, Probe as CatalogProbe } from './model-catalog.js';
|
|
11
|
+
export { ModelCatalog, mergeCatalog, liveFromContext, feedCatalog, feedAcpSession, acpSessionModels, setActiveCatalog, activeCatalog, POLICY as CATALOG_POLICY, REFRESH_MS as CATALOG_REFRESH_MS } from './model-catalog.js';
|
|
12
|
+
export type { CatalogSnapshot, CatalogRuntime, LiveModel, Probe as CatalogProbe, AcpProviderConfig, AcpProbe, AcpRow, AcpState } from './model-catalog.js';
|
|
12
13
|
export { liveProbes, codexProbe, claudeProbe, antigravityProbe, parseAgyModels } from './model-probes.js';
|
|
13
14
|
export { CodexTransport } from './transport.js';
|
|
14
15
|
export { ATTACHMENT_HEADER, ATTACHMENT_ROUTES, attachmentStageDir, createAttachmentStager, stagingExposure } from './attachments.js';
|
|
@@ -18,7 +19,7 @@ export { AcpTransport, acpDecision, acpEnv, acpPermission } from './acp-transpor
|
|
|
18
19
|
export type { AcpProvider } from './acp-transport.js';
|
|
19
20
|
export { AntigravityTransport } from './antigravity-transport.js';
|
|
20
21
|
export type { AntigravityProvider } from './antigravity-transport.js';
|
|
21
|
-
export { ClaudeTransport, claudePermissions, claudeSandboxAvailable, skillPlugin, SKILL_PLUGIN, toolShapes as claudeToolShapes } from './claude-transport.js';
|
|
22
|
+
export { ClaudeTransport, claudePermissions, claudeSandboxAvailable, customClearAliases, nativeCommandRefusal, skillPlugin, SKILL_PLUGIN, toolShapes as claudeToolShapes } from './claude-transport.js';
|
|
22
23
|
export { MAIL_BATCH_CHARS, MAIL_BODY_CHARS, publicEvent, renderMail, takeBatch, USER } from './mailbox.js';
|
|
23
24
|
export type { MailEvent, MailKind } from './mailbox.js';
|
|
24
25
|
export { createCopy, gitEnvironment, reattachWorktree, reclaimCopies, reclaimWorktrees, removeCopy } from './workspace.js';
|
package/dist/index.js
CHANGED
|
@@ -2,15 +2,16 @@
|
|
|
2
2
|
import { createAlpRuntime, DEFAULT_TEAM, WorkspaceMutationError } from "./runtime.js";
|
|
3
3
|
import { ConversationError } from "./contracts.js";
|
|
4
4
|
import { resolveSession, InstructionsAdapter, skillDescription } from "./resolve.js";
|
|
5
|
+
import { resourceUses, pathActions } from "./skill-resources.js";
|
|
5
6
|
import { DEFAULT_MODEL, DEFAULT_CLAUDE_MODEL, entries, models, modes, thinkingOptions, thinkingOptionsFor } from "./catalog.js";
|
|
6
|
-
import { ModelCatalog, mergeCatalog, liveFromContext, feedCatalog, setActiveCatalog, activeCatalog, POLICY, REFRESH_MS } from "./model-catalog.js";
|
|
7
|
+
import { ModelCatalog, mergeCatalog, liveFromContext, feedCatalog, feedAcpSession, acpSessionModels, setActiveCatalog, activeCatalog, POLICY, REFRESH_MS } from "./model-catalog.js";
|
|
7
8
|
import { liveProbes, codexProbe, claudeProbe, antigravityProbe, parseAgyModels } from "./model-probes.js";
|
|
8
9
|
import { CodexTransport } from "./transport.js";
|
|
9
10
|
import { ATTACHMENT_HEADER, ATTACHMENT_ROUTES, attachmentStageDir, createAttachmentStager, stagingExposure } from "./attachments.js";
|
|
10
11
|
import { usageAllows } from "./runtime-context.js";
|
|
11
12
|
import { AcpTransport, acpDecision, acpEnv, acpPermission } from "./acp-transport.js";
|
|
12
13
|
import { AntigravityTransport } from "./antigravity-transport.js";
|
|
13
|
-
import { ClaudeTransport, claudePermissions, claudeSandboxAvailable, skillPlugin, SKILL_PLUGIN, toolShapes } from "./claude-transport.js";
|
|
14
|
+
import { ClaudeTransport, claudePermissions, claudeSandboxAvailable, customClearAliases, nativeCommandRefusal, skillPlugin, SKILL_PLUGIN, toolShapes } from "./claude-transport.js";
|
|
14
15
|
import { MAIL_BATCH_CHARS, MAIL_BODY_CHARS, publicEvent, renderMail, takeBatch, USER } from "./mailbox.js";
|
|
15
16
|
import { createCopy, gitEnvironment, reattachWorktree, reclaimCopies, reclaimWorktrees, removeCopy } from "./workspace.js";
|
|
16
17
|
import { OWN_START, processStartedAt, sameProcessAlive } from "./process-info.js";
|
|
@@ -55,6 +56,7 @@ export {
|
|
|
55
56
|
acpDecision,
|
|
56
57
|
acpEnv,
|
|
57
58
|
acpPermission,
|
|
59
|
+
acpSessionModels,
|
|
58
60
|
acpToolDetail,
|
|
59
61
|
activeCatalog,
|
|
60
62
|
antigravityProbe,
|
|
@@ -78,6 +80,8 @@ export {
|
|
|
78
80
|
createAttachmentStager,
|
|
79
81
|
createCopy,
|
|
80
82
|
createProviderRegistry,
|
|
83
|
+
customClearAliases,
|
|
84
|
+
feedAcpSession,
|
|
81
85
|
feedCatalog,
|
|
82
86
|
gitEnvironment,
|
|
83
87
|
inputLimitError,
|
|
@@ -88,7 +92,9 @@ export {
|
|
|
88
92
|
mergeCatalog,
|
|
89
93
|
models,
|
|
90
94
|
modes,
|
|
95
|
+
nativeCommandRefusal,
|
|
91
96
|
parseAgyModels,
|
|
97
|
+
pathActions,
|
|
92
98
|
processStartedAt,
|
|
93
99
|
publicEvent,
|
|
94
100
|
reattachWorktree,
|
|
@@ -99,6 +105,7 @@ export {
|
|
|
99
105
|
renderMail,
|
|
100
106
|
renderPin,
|
|
101
107
|
resolveSession,
|
|
108
|
+
resourceUses,
|
|
102
109
|
sameProcessAlive,
|
|
103
110
|
seedPrompt,
|
|
104
111
|
setActiveCatalog,
|
package/dist/language.d.ts
CHANGED
|
@@ -11,6 +11,7 @@ declare const en: {
|
|
|
11
11
|
skill: (agent: string, replacing: boolean, file: string, roles: string, lessons: string[]) => string;
|
|
12
12
|
issue: (agent: string, create: boolean, issue: number | undefined, where: string) => string;
|
|
13
13
|
issueTitle: string;
|
|
14
|
+
skillRetire: (agent: string, name: string, file: string, retired: string, roles: string, users: string, reason: string) => string;
|
|
14
15
|
lessonCurate: (agent: string, changes: string) => string;
|
|
15
16
|
lessonRemove: string;
|
|
16
17
|
lessonAdd: string;
|
|
@@ -25,6 +26,7 @@ declare const en: {
|
|
|
25
26
|
permission: (agent: string, what: string, byRule: boolean, profile: string | undefined, mode: string, always: string | undefined) => string;
|
|
26
27
|
limitReached: (runtime: string, resetsAt: string | undefined, other: string | undefined, autoResume: boolean, kind: string) => string;
|
|
27
28
|
limitLifted: (runtime: string, kind: string) => string;
|
|
29
|
+
compacting: () => string;
|
|
28
30
|
compacted: (native: boolean) => string;
|
|
29
31
|
compactFailed: (reason: string) => string;
|
|
30
32
|
usageWarning: (runtime: string, used: string, resetsAt: string | undefined) => string;
|
package/dist/language.js
CHANGED
|
@@ -8,6 +8,8 @@ var en = {
|
|
|
8
8
|
${lessons.map((lesson) => `- ${lesson}`).join("\n")}` : ""),
|
|
9
9
|
issue: (agent, create, issue, where) => `${agent} wants to ${create ? `open an issue in ${where}` : `comment on issue #${issue} in ${where}`}. It is posted with your GitHub account, and anyone who can see the repository can read it.`,
|
|
10
10
|
issueTitle: "Title",
|
|
11
|
+
skillRetire: (agent, name, file, retired, roles, users, reason) => `${agent} proposes to retire the skill ${name} (${file}): ${reason}
|
|
12
|
+
Approve to move it to ${retired}, where it is kept and can be restored, and remove it from ${roles ? `the roles that have it: ${roles}` : "role-skills.json (no role has it)"}. Nothing else changes.` + (users ? ` It is still named in agent.json by ${users}; it is not retired until they stop naming it.` : ""),
|
|
11
13
|
lessonCurate: (agent, changes) => `${agent} proposes to curate the lessons files. Approve to apply every change below at once; nothing else changes.
|
|
12
14
|
|
|
13
15
|
${changes}`,
|
|
@@ -24,6 +26,7 @@ ${changes}`,
|
|
|
24
26
|
permission: (agent, what, byRule, profile, mode, always) => `${agent} wants to ${what}. ` + (byRule ? `Its permission profile ${profile} asks you each time.` : `Its ${mode} mode does not allow that.`) + (always ? ` Always allow adds ${always} to profile ${profile}.` : ""),
|
|
25
27
|
limitReached: (runtime, resetsAt, other, autoResume, kind) => `${runtime} usage limit reached${resetsAt ? `; it resets ${resetsAt}` : ""}. ALP paused delegation to ${runtime} agents and parked their assignments${other ? `; ${other} agents keep working` : ""}. ${autoResume ? `ALP asks ${runtime} every minute and resumes it as soon as the limit lifts.` : `ALP asks ${runtime} every minute and tells you when the limit lifts; then run alp resume ${kind}.`}`,
|
|
26
28
|
limitLifted: (runtime, kind) => `${runtime} says its usage limit has lifted. Run alp resume ${kind} to continue its work.`,
|
|
29
|
+
compacting: () => "Compacting main's context: main writes a checkpoint first.",
|
|
27
30
|
compacted: (native) => `Main's context was compacted${native ? "" : " into a fresh conversation"}; it keeps its checkpoint and carries on.`,
|
|
28
31
|
compactFailed: (reason) => `Compacting main's context failed (${reason}); ALP tries again later.`,
|
|
29
32
|
usageWarning: (runtime, used, resetsAt) => `${runtime} has used ${used} of a usage window${resetsAt ? ` that resets ${resetsAt}` : ""}.`,
|
|
@@ -43,6 +46,8 @@ var vi = {
|
|
|
43
46
|
${lessons.map((lesson) => `- ${lesson}`).join("\n")}` : ""),
|
|
44
47
|
issue: (agent, create, issue, where) => `${agent} mu\u1ED1n ${create ? `m\u1EDF m\u1ED9t issue trong ${where}` : `b\xECnh lu\u1EADn v\xE0o issue #${issue} trong ${where}`}. N\u1ED9i dung \u0111\u01B0\u1EE3c \u0111\u0103ng b\u1EB1ng t\xE0i kho\u1EA3n GitHub c\u1EE7a b\u1EA1n, ai xem \u0111\u01B0\u1EE3c repository \u0111\u1EC1u \u0111\u1ECDc \u0111\u01B0\u1EE3c.`,
|
|
45
48
|
issueTitle: "Ti\xEAu \u0111\u1EC1",
|
|
49
|
+
skillRetire: (agent, name, file, retired, roles, users, reason) => `${agent} \u0111\u1EC1 xu\u1EA5t cho skill ${name} (${file}) ngh\u1EC9: ${reason}
|
|
50
|
+
Duy\u1EC7t \u0111\u1EC3 chuy\u1EC3n n\xF3 sang ${retired}, n\u01A1i n\xF3 v\u1EABn \u0111\u01B0\u1EE3c gi\u1EEF v\xE0 c\xF3 th\u1EC3 kh\xF4i ph\u1EE5c, v\xE0 b\u1ECF n\xF3 kh\u1ECFi ${roles ? `c\xE1c vai \u0111ang d\xF9ng: ${roles}` : "role-skills.json (kh\xF4ng vai n\xE0o d\xF9ng)"}. Kh\xF4ng thay \u0111\u1ED5i g\xEC kh\xE1c.` + (users ? ` N\xF3 v\u1EABn \u0111\u01B0\u1EE3c n\xEAu trong agent.json c\u1EE7a ${users}; n\xF3 ch\u1EC9 \u0111\u01B0\u1EE3c cho ngh\u1EC9 khi c\xE1c agent \u0111\xF3 th\xF4i n\xEAu n\xF3.` : ""),
|
|
46
51
|
lessonCurate: (agent, changes) => `${agent} \u0111\u1EC1 xu\u1EA5t r\xE0 so\xE1t file b\xE0i h\u1ECDc. Duy\u1EC7t \u0111\u1EC3 \xE1p d\u1EE5ng c\xF9ng l\xFAc m\u1ECDi thay \u0111\u1ED5i d\u01B0\u1EDBi \u0111\xE2y; kh\xF4ng thay \u0111\u1ED5i g\xEC kh\xE1c.
|
|
47
52
|
|
|
48
53
|
${changes}`,
|
|
@@ -59,6 +64,7 @@ ${changes}`,
|
|
|
59
64
|
permission: (agent, what, byRule, profile, mode, always) => `${agent} mu\u1ED1n ${viWhat(what)}. ` + (byRule ? `H\u1ED3 s\u01A1 quy\u1EC1n ${profile} c\u1EE7a n\xF3 y\xEAu c\u1EA7u h\u1ECFi b\u1EA1n m\u1ED7i l\u1EA7n.` : `Ch\u1EBF \u0111\u1ED9 ${mode} c\u1EE7a n\xF3 kh\xF4ng cho ph\xE9p vi\u1EC7c n\xE0y.`) + (always ? ` Lu\xF4n cho ph\xE9p s\u1EBD th\xEAm ${always} v\xE0o h\u1ED3 s\u01A1 ${profile}.` : ""),
|
|
60
65
|
limitReached: (runtime, resetsAt, other, autoResume, kind) => `${runtime} \u0111\xE3 h\u1EBFt h\u1EA1n m\u1EE9c s\u1EED d\u1EE5ng${resetsAt ? `; h\u1EA1n m\u1EE9c \u0111\u1EB7t l\u1EA1i l\xFAc ${resetsAt}` : ""}. ALP t\u1EA1m d\u1EEBng giao vi\u1EC7c cho c\xE1c agent ${runtime} v\xE0 t\u1EA1m gi\u1EEF vi\u1EC7c c\u1EE7a ch\xFAng${other ? `; c\xE1c agent ${other} v\u1EABn l\xE0m ti\u1EBFp` : ""}. ${autoResume ? `ALP h\u1ECFi ${runtime} m\u1ED7i ph\xFAt v\xE0 t\u1EF1 ch\u1EA1y l\u1EA1i ngay khi c\xF3 h\u1EA1n m\u1EE9c.` : `ALP h\u1ECFi ${runtime} m\u1ED7i ph\xFAt v\xE0 b\xE1o khi c\xF3 h\u1EA1n m\u1EE9c tr\u1EDF l\u1EA1i; khi \u0111\xF3 ch\u1EA1y alp resume ${kind}.`}`,
|
|
61
66
|
limitLifted: (runtime, kind) => `${runtime} b\xE1o \u0111\xE3 c\xF3 h\u1EA1n m\u1EE9c tr\u1EDF l\u1EA1i. Ch\u1EA1y alp resume ${kind} \u0111\u1EC3 l\xE0m ti\u1EBFp vi\u1EC7c c\u1EE7a n\xF3.`,
|
|
67
|
+
compacting: () => "\u0110ang compact context c\u1EE7a main: main vi\u1EBFt checkpoint tr\u01B0\u1EDBc.",
|
|
62
68
|
compacted: (native) => `Context c\u1EE7a main \u0111\xE3 \u0111\u01B0\u1EE3c compact${native ? "" : " sang m\u1ED9t cu\u1ED9c h\u1ED9i tho\u1EA1i m\u1EDBi"}; main gi\u1EEF checkpoint v\xE0 l\xE0m ti\u1EBFp.`,
|
|
63
69
|
compactFailed: (reason) => `Compact context c\u1EE7a main th\u1EA5t b\u1EA1i (${reason}); ALP s\u1EBD th\u1EED l\u1EA1i sau.`,
|
|
64
70
|
usageWarning: (runtime, used, resetsAt) => `${runtime} \u0111\xE3 d\xF9ng ${used} h\u1EA1n m\u1EE9c c\u1EE7a k\u1EF3 n\xE0y${resetsAt ? `, k\u1EF3 \u0111\u1EB7t l\u1EA1i l\xFAc ${resetsAt}` : ""}.`,
|
package/dist/live.d.ts
CHANGED
|
@@ -37,8 +37,8 @@ export type LiveEntry = {
|
|
|
37
37
|
/** The alpd process that wrote the entry; another epoch means an earlier alpd. */
|
|
38
38
|
epoch: string;
|
|
39
39
|
};
|
|
40
|
-
/** The book of running assignments, in `file` when given, else in memory. */
|
|
41
|
-
export declare function createLiveBook(file?: string): {
|
|
40
|
+
/** The book of running assignments, in `file` when given, else in memory; `onError` hears of each failed write. */
|
|
41
|
+
export declare function createLiveBook(file?: string, onError?: (error: unknown) => void): {
|
|
42
42
|
all: () => LiveEntry[];
|
|
43
43
|
get: (assignmentId: string) => LiveEntry | undefined;
|
|
44
44
|
put(entry: LiveEntry): Promise<void>;
|
package/dist/live.js
CHANGED
|
@@ -4,8 +4,10 @@ import { mkdir, rename, writeFile } from "node:fs/promises";
|
|
|
4
4
|
import { randomBytes } from "node:crypto";
|
|
5
5
|
import path from "node:path";
|
|
6
6
|
import { createLogger } from "@anhlp/alp-core/log";
|
|
7
|
+
import { tell } from "./write-error.js";
|
|
7
8
|
var valid = (entry) => !!entry && typeof entry === "object" && ["assignmentId", "rootId", "parentId", "agent", "project", "runtime", "model", "threadId", "mode", "isolation", "epoch"].every((key) => typeof entry[key] === "string") && Array.isArray(entry.ancestry) && !!entry.spec && typeof entry.spec === "object" && typeof entry.startedAt === "number";
|
|
8
|
-
function createLiveBook(file) {
|
|
9
|
+
function createLiveBook(file, onError = () => {
|
|
10
|
+
}) {
|
|
9
11
|
let entries = [];
|
|
10
12
|
if (file) {
|
|
11
13
|
try {
|
|
@@ -22,7 +24,10 @@ function createLiveBook(file) {
|
|
|
22
24
|
const temporary = `${file}.${process.pid}.${randomBytes(4).toString("hex")}.tmp`;
|
|
23
25
|
await writeFile(temporary, body, { mode: 384 });
|
|
24
26
|
await rename(temporary, file);
|
|
25
|
-
}).catch((error) =>
|
|
27
|
+
}).catch((error) => {
|
|
28
|
+
tell(onError, error);
|
|
29
|
+
createLogger({ component: "runtime" }).error("could not save the live assignments", { code: "ALP_PERSISTENCE_WRITE_FAILED", operation: "live assignments", error });
|
|
30
|
+
});
|
|
26
31
|
return writes;
|
|
27
32
|
};
|
|
28
33
|
return {
|