@anhlp/alp-runtime 0.0.1-beta.7 → 0.0.1-beta.8
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 +41 -5
- 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 +74 -7
- 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/runtime.js
CHANGED
|
@@ -12,17 +12,19 @@ import { ConversationError } from "./contracts.js";
|
|
|
12
12
|
import { claudeCut, codexForkEnd, codexForkRefusal, pendingChain } from "./conversation.js";
|
|
13
13
|
import { DEFAULT_TEAM } from "./contracts.js";
|
|
14
14
|
import { verdictLine, parseHandoff } from "./handoff.js";
|
|
15
|
-
import { TASK_ACTIONS, TASK_PAST, TASK_FIELDS, mainOf, roleOf, taskActions, taskBrief } from "./tools.js";
|
|
15
|
+
import { TASK_ACTIONS, TASK_PAST, TASK_FIELDS, mainOf, readOnlyMember, roleOf, taskActions, taskBrief } from "./tools.js";
|
|
16
16
|
import { nativeEnvironment, createTransport } from "./providers.js";
|
|
17
17
|
import { nativeMode, codexApproval, profileEfforts, nativeSessionConfig } from "./session-config.js";
|
|
18
18
|
import { createHash, randomUUID } from "node:crypto";
|
|
19
19
|
import { readFileSync, realpathSync, watch as watchFiles } from "node:fs";
|
|
20
|
-
import { appendFile, mkdir, open, readFile, realpath, rm, stat, writeFile } from "node:fs/promises";
|
|
21
|
-
import {
|
|
20
|
+
import { appendFile, mkdir, open, readdir, readFile, realpath, rm, stat, writeFile } from "node:fs/promises";
|
|
21
|
+
import { checkFrontmatter, skillReferences, splitSkill } from "@anhlp/alp-core/skill-validate";
|
|
22
|
+
import { resourceUses } from "./skill-resources.js";
|
|
23
|
+
import { moveFile, writeAtomic } from "@anhlp/alp-core/atomic";
|
|
22
24
|
import os from "node:os";
|
|
23
25
|
import path from "node:path";
|
|
24
26
|
import { resolveDelegation } from "@anhlp/alp-core/delegation";
|
|
25
|
-
import { discoverAgents } from "@anhlp/alp-core/resolver";
|
|
27
|
+
import { agentSources, builtinText, discoverAgents } from "@anhlp/alp-core/resolver";
|
|
26
28
|
import { acpDecision, acpWhat } from "./acp-transport.js";
|
|
27
29
|
import { models, modes, thinkingOptionsFor, withinMode, writes } from "./catalog.js";
|
|
28
30
|
import { feedCatalog } from "./model-catalog.js";
|
|
@@ -32,17 +34,18 @@ import { isTrusted, trustProject } from "@anhlp/alp-core/trust";
|
|
|
32
34
|
import { listTeams, teamOf } from "@anhlp/alp-core/teams";
|
|
33
35
|
import { CONFIGURABLE, changesOf, effectiveOf, executablesOf, nativeModelOf, offered } from "./configure.js";
|
|
34
36
|
import { anyModel, offers, profileModel, selectedProfile } from "@anhlp/alp-core/profiles";
|
|
35
|
-
import { LESSONS_FILE,
|
|
37
|
+
import { LESSONS_FILE, resolveSession, skillDescription } from "./resolve.js";
|
|
36
38
|
import { MAIL_BODY_CHARS, MAIL_HEADER, publicEvent, renderMail, takeBatch, USER } from "./mailbox.js";
|
|
37
39
|
import { live, normalizePaths, overlapping, renderBoard } from "./board.js";
|
|
38
40
|
import { verifyConfig } from "@anhlp/alp-core/verify";
|
|
39
41
|
import { createLiveBook } from "./live.js";
|
|
42
|
+
import { tell } from "./write-error.js";
|
|
40
43
|
import { promptSafe } from "@anhlp/alp-core/promptsafe";
|
|
41
44
|
import { CHOICES, words } from "./language.js";
|
|
42
45
|
import { OWN_START, sameProcessAlive } from "./process-info.js";
|
|
43
46
|
import { createRecallBook, recallPrompt, RECALL_KEEP_MS, RECALL_QUESTION_CHARS, RECALL_TIMEOUT_MS } from "./recall.js";
|
|
44
47
|
import { branchExists, checkoutFingerprint, checkoutKey, createCopy, createWorktree, reattachWorktree, removeCopy, removeWorktree } from "./workspace.js";
|
|
45
|
-
import { claudeSandboxAvailable, SKILL_PLUGIN } from "./claude-transport.js";
|
|
48
|
+
import { claudeSandboxAvailable, nativeCommandRefusal, SKILL_PLUGIN } from "./claude-transport.js";
|
|
46
49
|
import { boundDetail, codexToolCall, toolError } from "./tool-detail.js";
|
|
47
50
|
import { ALP_REPO, gh, projectRepo } from "./github.js";
|
|
48
51
|
import { optionalRead, usageAllows, COMPACT_SHARE } from "./runtime-context.js";
|
|
@@ -76,6 +79,7 @@ function promptOrigin(clientMessageId, session) {
|
|
|
76
79
|
if (/^alp-(resume|recover)-/.test(clientMessageId)) return session.parent ? "assignment" : "wake";
|
|
77
80
|
return "user";
|
|
78
81
|
}
|
|
82
|
+
var COMPACT_PROMPT = "alp-wake-compact-";
|
|
79
83
|
var MAX_WAKES = 8;
|
|
80
84
|
var USER_REPLY_MS = 6e4;
|
|
81
85
|
var USER_WROTE = "The user just wrote to you; their message follows. Answer them first in a short message they can read (tool calls alone show them nothing), and steer an assignment with alp_send when their words change its brief. Your assignments keep running: then alp_wait again, or end your turn and ALP wakes you with their results.";
|
|
@@ -129,14 +133,19 @@ var WorkspaceMutationError = class extends Error {
|
|
|
129
133
|
};
|
|
130
134
|
function createAlpRuntime(options = {}) {
|
|
131
135
|
const sessions = /* @__PURE__ */ new Map();
|
|
136
|
+
const compactEchoes = /* @__PURE__ */ new Map();
|
|
137
|
+
const inputDigest = (parts) => createHash("sha256").update(JSON.stringify(parts)).digest("hex");
|
|
132
138
|
const admittedPrompts = /* @__PURE__ */ new Set();
|
|
133
139
|
const wordsFor = (session) => words(session.mapping.language);
|
|
134
140
|
const childContexts = /* @__PURE__ */ new Map();
|
|
135
141
|
const listeners = /* @__PURE__ */ new Set();
|
|
136
142
|
const epoch = randomUUID();
|
|
137
|
-
const
|
|
138
|
-
|
|
139
|
-
|
|
143
|
+
const writeFailed = (error) => {
|
|
144
|
+
options.onWriteError?.(error);
|
|
145
|
+
};
|
|
146
|
+
const recalls = createRecallBook(options.recallFile, writeFailed);
|
|
147
|
+
const assignmentResults = createAssignmentResults(options.assignmentResultFile, writeFailed);
|
|
148
|
+
const inFlight = createLiveBook(options.liveFile, writeFailed);
|
|
140
149
|
let inherited = inFlight.all().filter((entry) => entry.epoch !== epoch);
|
|
141
150
|
let paused = { runtimes: {} };
|
|
142
151
|
try {
|
|
@@ -294,7 +303,7 @@ function createAlpRuntime(options = {}) {
|
|
|
294
303
|
if (!clientMessageId?.startsWith("alp-wake-") && rest.length > 1 && rest.at(-1).startsWith(MAIL_HEADER)) rest.pop();
|
|
295
304
|
return { text: rest.at(-1) ?? "", ...ids };
|
|
296
305
|
}
|
|
297
|
-
function nativeItem(sessionId, session, item, done = false) {
|
|
306
|
+
function nativeItem(sessionId, session, item, done = false, turnId) {
|
|
298
307
|
if (item.type === "agentMessage") {
|
|
299
308
|
if (session.userWaiting !== void 0 && String(item.text ?? "").trim()) {
|
|
300
309
|
if (session.supervisor) session.journal.push(stamp(`${session.mapping.agent.name} answered the user ${span(Date.now() - session.userWaiting)} after their message of ${clock(session.userWaiting)}`));
|
|
@@ -306,6 +315,10 @@ function createAlpRuntime(options = {}) {
|
|
|
306
315
|
}
|
|
307
316
|
if (item.type === "userMessage") {
|
|
308
317
|
const { text: text2, clientMessageId, origin, attachments } = nativePrompt(item, session);
|
|
318
|
+
if (turnId) {
|
|
319
|
+
const digest = inputDigest((item.content ?? []).filter((part) => part.type === "text").map((part) => String(part.text ?? "")));
|
|
320
|
+
for (const echoes of compactEchoes.values()) if (echoes.get(`${session.threadId}:${turnId}`) === digest) return;
|
|
321
|
+
}
|
|
309
322
|
const images = (item.content ?? []).filter((c) => c.type === "image" || c.type === "localImage").length;
|
|
310
323
|
emit(sessionId, { type: "item", item: { kind: "user_message", id: item.id, text: text2, ...clientMessageId ? { clientMessageId } : {}, ...origin ? { origin } : {}, ...images ? { images } : {}, ...attachments ? { attachments } : {} } });
|
|
311
324
|
return;
|
|
@@ -473,6 +486,7 @@ function createAlpRuntime(options = {}) {
|
|
|
473
486
|
runLog(rootOf(sessionId), { event: "worktree.kept", assignmentId, branch: worktree.branch });
|
|
474
487
|
}
|
|
475
488
|
session.worktrees.clear();
|
|
489
|
+
compactEchoes.delete(session);
|
|
476
490
|
if (sessions.get(sessionId) !== session) return;
|
|
477
491
|
sessions.delete(sessionId);
|
|
478
492
|
if (session.parent && parent && sessions.get(session.parent) === parent) {
|
|
@@ -1085,8 +1099,7 @@ Review the process against ALP.md, ${agent}'s AGENT.md and the recorded lessons.
|
|
|
1085
1099
|
const temporary = `${file}.${process.pid}.${randomUUID().slice(0, 8)}.tmp`;
|
|
1086
1100
|
await writeFile(temporary, body, { mode: 384 });
|
|
1087
1101
|
await moveFile(temporary, file);
|
|
1088
|
-
}).catch(() =>
|
|
1089
|
-
});
|
|
1102
|
+
}).catch((error) => tell(writeFailed, error));
|
|
1090
1103
|
}
|
|
1091
1104
|
function notice(level, message, project) {
|
|
1092
1105
|
for (const [id, session] of sessions) {
|
|
@@ -1312,6 +1325,7 @@ Review the process against ALP.md, ${agent}'s AGENT.md and the recorded lessons.
|
|
|
1312
1325
|
const skills = session.mapping.agent.skills;
|
|
1313
1326
|
if (!skills.length || item.type === "agentMessage" || item.type === "reasoning") return;
|
|
1314
1327
|
const text2 = typeof item.command === "string" ? item.command : JSON.stringify(item).slice(0, 2e4);
|
|
1328
|
+
skillResources(sessionId, session, item);
|
|
1315
1329
|
if (!text2.includes("SKILL.md") && !text2.includes("Skill")) return;
|
|
1316
1330
|
for (const skill of skills) {
|
|
1317
1331
|
if (session.skillsUsed?.has(skill.name)) continue;
|
|
@@ -1323,6 +1337,15 @@ Review the process against ALP.md, ${agent}'s AGENT.md and the recorded lessons.
|
|
|
1323
1337
|
if (session.supervisor) session.journal.push(stamp(`${session.mapping.agent.name} used skill ${skill.name}`));
|
|
1324
1338
|
}
|
|
1325
1339
|
}
|
|
1340
|
+
function skillResources(sessionId, session, item) {
|
|
1341
|
+
if (typeof item.command !== "string") return;
|
|
1342
|
+
for (const use of resourceUses(item.command, session.mapping.agent.skills)) {
|
|
1343
|
+
const key = `${use.action}:${use.skill}/${use.resource}`;
|
|
1344
|
+
if (session.skillResourcesUsed?.has(key)) continue;
|
|
1345
|
+
(session.skillResourcesUsed ??= /* @__PURE__ */ new Set()).add(key);
|
|
1346
|
+
runLog(rootOf(sessionId), { event: "skill-resource", sessionId, agent: session.mapping.agent.name, skill: use.skill, resource: use.resource, action: use.action });
|
|
1347
|
+
}
|
|
1348
|
+
}
|
|
1326
1349
|
function compaction(sessionId, session, item, done) {
|
|
1327
1350
|
const failed = done && item.status === "failed";
|
|
1328
1351
|
const tokens = { ...typeof item.preTokens === "number" ? { preTokens: item.preTokens } : {}, ...typeof item.postTokens === "number" ? { postTokens: item.postTokens } : {} };
|
|
@@ -1389,7 +1412,8 @@ Review the process against ALP.md, ${agent}'s AGENT.md and the recorded lessons.
|
|
|
1389
1412
|
return;
|
|
1390
1413
|
}
|
|
1391
1414
|
compacting.turn = true;
|
|
1392
|
-
await startPrompt(sessionId, { clientMessageId:
|
|
1415
|
+
await startPrompt(sessionId, { clientMessageId: `${COMPACT_PROMPT}${randomUUID()}`, delivery: "auto", content: [{ type: "text", text: checkpointPrompt(trigger, session.contextFill) }] }, "wake", void 0, true);
|
|
1416
|
+
emit(sessionId, { type: "item", item: { kind: "notice", id: `notice-${randomUUID().slice(0, 8)}`, level: "info", text: wordsFor(session).compacting() } });
|
|
1393
1417
|
}).catch((error) => compactFailed(sessionId, session, errorData(error).message));
|
|
1394
1418
|
queue = work.catch(() => {
|
|
1395
1419
|
});
|
|
@@ -1423,7 +1447,7 @@ Review the process against ALP.md, ${agent}'s AGENT.md and the recorded lessons.
|
|
|
1423
1447
|
}
|
|
1424
1448
|
await restartNative(sessionId, session, void 0);
|
|
1425
1449
|
emit(sessionId, { type: "session.updated", session: snapshot(sessionId, session) });
|
|
1426
|
-
await startPrompt(sessionId, { clientMessageId:
|
|
1450
|
+
await startPrompt(sessionId, { clientMessageId: `${COMPACT_PROMPT}${randomUUID()}`, delivery: "auto", content: [{ type: "text", text: seedPrompt(checkpoint, session.lastUserText) }] }, "wake", void 0, true);
|
|
1427
1451
|
compactFinished(sessionId, session, "fresh");
|
|
1428
1452
|
}).catch((error) => compactFailed(sessionId, session, errorData(error).message));
|
|
1429
1453
|
queue = work.catch(() => {
|
|
@@ -1635,6 +1659,14 @@ ${args.body.trim()}
|
|
|
1635
1659
|
if (previous) return toolResult(true, previous.result ?? { status: "pending_approval", approvalId: previous.approvalId, file });
|
|
1636
1660
|
const existing = await readFile(file, "utf8").catch(() => void 0);
|
|
1637
1661
|
if (existing !== void 0 && !args.replace) return toolResult(false, { error: `The library already has a skill named ${args.name} (${file}); read it, then pass replace: true to propose a new version, or choose another name` });
|
|
1662
|
+
const invalid = checkFrontmatter(splitSkill(content).frontmatter, args.name, { strict: true }).findings.filter((finding) => finding.level === "error");
|
|
1663
|
+
if (invalid.length) return toolResult(false, { error: `The skill does not meet the skill format: ${invalid.map((finding) => finding.message).join("; ")}` });
|
|
1664
|
+
const missing = [];
|
|
1665
|
+
for (const target of skillReferences(args.body)) {
|
|
1666
|
+
const resolved = path.resolve(path.dirname(file), target);
|
|
1667
|
+
if (path.isAbsolute(target) || path.relative(path.dirname(file), resolved).startsWith("..") || !await stat(resolved).then(() => true, () => false)) missing.push(target);
|
|
1668
|
+
}
|
|
1669
|
+
if (missing.length) return toolResult(false, { error: `The body points to ${missing.join(", ")}, which the skill would not have: alp_skill saves only SKILL.md. Put that content in the body, or ask the user to add the files to ${path.dirname(file)} first` });
|
|
1638
1670
|
const rolesFile = path.join(library, "role-skills.json");
|
|
1639
1671
|
const readRoles = async () => {
|
|
1640
1672
|
const raw = await readFile(rolesFile, "utf8").catch(() => "{}");
|
|
@@ -1675,7 +1707,7 @@ ${content}`,
|
|
|
1675
1707
|
if (!list.includes(args.name)) list.push(args.name);
|
|
1676
1708
|
roles[role] = list;
|
|
1677
1709
|
}
|
|
1678
|
-
await
|
|
1710
|
+
await writeAtomic(rolesFile, JSON.stringify(roles, null, 2) + "\n");
|
|
1679
1711
|
} catch (error) {
|
|
1680
1712
|
return { approved: true, saved: false, error: errorData(error).message, next: "Tell the user; nothing is retried automatically." };
|
|
1681
1713
|
}
|
|
@@ -1716,6 +1748,158 @@ ${content}`,
|
|
|
1716
1748
|
})();
|
|
1717
1749
|
return toolResult(true, { status: "pending_approval", approvalId, file, next: "Continue other work or end your turn. ALP sends the user's decision, and whether the skill was saved, by mail; do not resubmit this draft." });
|
|
1718
1750
|
}
|
|
1751
|
+
async function skillRetireTool(sessionId, session, args) {
|
|
1752
|
+
const cancellation = approvalCancellation.get(session) ?? 0;
|
|
1753
|
+
args = structuredClone(args);
|
|
1754
|
+
if (!plainObject(args, ["name", "reason", "requestId"]) || typeof args.name !== "string" || !/^[a-z0-9][a-z0-9-]{1,62}$/.test(args.name) || !text(args.reason, 300)) {
|
|
1755
|
+
return toolResult(false, { error: "Retiring a skill needs its name (lowercase letters, digits, hyphens) and a one-line reason of at most 300 characters" });
|
|
1756
|
+
}
|
|
1757
|
+
if (args.requestId !== void 0 && !text(args.requestId, 100)) return toolResult(false, { error: "requestId must be a nonempty string of at most 100 characters" });
|
|
1758
|
+
const library = options.libraryDir;
|
|
1759
|
+
if (!library) return toolResult(false, { error: "This host keeps no user skill library" });
|
|
1760
|
+
const directory = path.join(library, "skills", args.name);
|
|
1761
|
+
const file = path.join(directory, "SKILL.md");
|
|
1762
|
+
const reason = args.reason.replace(/\s+/g, " ").trim();
|
|
1763
|
+
const draftKey = JSON.stringify(["skill.retire", args.name, reason]);
|
|
1764
|
+
const key = `skill.retire:${args.requestId ?? draftKey}`;
|
|
1765
|
+
const approvals = approvalsOf(sessionId);
|
|
1766
|
+
const previous = approvals.get(key);
|
|
1767
|
+
if (previous && previous.draftKey !== draftKey) return toolResult(false, { error: "requestId was already used for a different draft" });
|
|
1768
|
+
if (previous) return toolResult(true, previous.result ?? { status: "pending_approval", approvalId: previous.approvalId, file });
|
|
1769
|
+
const content = await readFile(file, "utf8").catch(() => void 0);
|
|
1770
|
+
if (content === void 0) return toolResult(false, { error: `The library has no skill named ${args.name} (${file})` });
|
|
1771
|
+
const rolesFile = path.join(library, "role-skills.json");
|
|
1772
|
+
const readRoles = async () => {
|
|
1773
|
+
const roles = JSON.parse(await readFile(rolesFile, "utf8").catch(() => "{}"));
|
|
1774
|
+
if (!roles || typeof roles !== "object" || Array.isArray(roles)) throw new Error(`${rolesFile} must be an object of role names to skill lists`);
|
|
1775
|
+
return roles;
|
|
1776
|
+
};
|
|
1777
|
+
const holders = (roles) => Object.keys(roles).filter((role) => Array.isArray(roles[role]) && roles[role].includes(args.name)).sort();
|
|
1778
|
+
const namedBy = async () => {
|
|
1779
|
+
const found = [];
|
|
1780
|
+
for (const [agent, source] of await agentSources(session.mapping.agent.projectRoot, { library, templates: options.templates })) {
|
|
1781
|
+
const where = source.directory ? path.join(source.directory, "agent.json") : `built-in agents/${agent}/agent.json`;
|
|
1782
|
+
const body = source.directory ? await readFile(path.join(source.directory, "agent.json"), "utf8").catch((error) => {
|
|
1783
|
+
if (error.code === "ENOENT") return void 0;
|
|
1784
|
+
throw error;
|
|
1785
|
+
}) : await builtinText(`agents/${agent}/agent.json`, options.templates);
|
|
1786
|
+
if (body === void 0) continue;
|
|
1787
|
+
let config;
|
|
1788
|
+
try {
|
|
1789
|
+
config = JSON.parse(body);
|
|
1790
|
+
} catch (error) {
|
|
1791
|
+
throw new Error(`${where}: ${errorData(error).message}`);
|
|
1792
|
+
}
|
|
1793
|
+
const skills = config && typeof config === "object" ? config.skills : void 0;
|
|
1794
|
+
if (Array.isArray(skills) && skills.includes(args.name)) found.push(`agent ${agent}`);
|
|
1795
|
+
}
|
|
1796
|
+
return found.sort();
|
|
1797
|
+
};
|
|
1798
|
+
const digest = async () => {
|
|
1799
|
+
const hash = createHash("sha256");
|
|
1800
|
+
const walk = async (dir, rel) => {
|
|
1801
|
+
for (const entry of (await readdir(dir, { withFileTypes: true })).sort((a, b) => a.name.localeCompare(b.name))) {
|
|
1802
|
+
const name = rel ? `${rel}/${entry.name}` : entry.name;
|
|
1803
|
+
if (entry.isDirectory()) {
|
|
1804
|
+
hash.update(`d:${name}\0`);
|
|
1805
|
+
await walk(path.join(dir, entry.name), name);
|
|
1806
|
+
} else {
|
|
1807
|
+
hash.update(`f:${name}\0`);
|
|
1808
|
+
hash.update(await readFile(path.join(dir, entry.name)));
|
|
1809
|
+
hash.update("\0");
|
|
1810
|
+
}
|
|
1811
|
+
}
|
|
1812
|
+
};
|
|
1813
|
+
await walk(directory, "");
|
|
1814
|
+
return hash.digest("hex");
|
|
1815
|
+
};
|
|
1816
|
+
let given;
|
|
1817
|
+
let users;
|
|
1818
|
+
let tree;
|
|
1819
|
+
try {
|
|
1820
|
+
given = holders(await readRoles());
|
|
1821
|
+
users = await namedBy();
|
|
1822
|
+
tree = await digest();
|
|
1823
|
+
} catch (error) {
|
|
1824
|
+
return toolResult(false, { error: errorData(error).message });
|
|
1825
|
+
}
|
|
1826
|
+
if (approvalCanceled(session, cancellation)) return toolResult(false, { error: "Skill retirement canceled or session closed; no approval was created" });
|
|
1827
|
+
if ([...userQuestions.values()].some((pending) => pending.question.sessionId === sessionId && !pending.gate)) return toolResult(false, { error: "A question is already waiting for the user; finish it before proposing to retire a skill" });
|
|
1828
|
+
const retired = path.join(library, "retired-skills", `${args.name}-${(/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-")}`);
|
|
1829
|
+
const restore = `The user restores it with: alp skill restore ${args.name} (or by moving ${retired} back to ${directory} and adding it to the roles again in role-skills.json).`;
|
|
1830
|
+
const approvalId = `q-${randomUUID()}`;
|
|
1831
|
+
const record2 = { approvalId, draftKey };
|
|
1832
|
+
approvals.set(key, record2);
|
|
1833
|
+
const say = wordsFor(session);
|
|
1834
|
+
const decision = confirm(
|
|
1835
|
+
sessionId,
|
|
1836
|
+
session,
|
|
1837
|
+
say.skillRetire(session.mapping.agent.name, args.name, file, retired, given.join(", "), users.join(", "), reason) + `
|
|
1838
|
+
${say.answerLine(session.mapping.agent.name)}
|
|
1839
|
+
|
|
1840
|
+
${content}`,
|
|
1841
|
+
{ id: approvalId }
|
|
1842
|
+
);
|
|
1843
|
+
const retire = async () => {
|
|
1844
|
+
const refuse = (error, next) => ({ approved: true, retired: false, error, next });
|
|
1845
|
+
let before;
|
|
1846
|
+
try {
|
|
1847
|
+
if (await digest().catch(() => void 0) !== tree) {
|
|
1848
|
+
return refuse(`The skill ${args.name} changed or was removed since it was proposed; nothing was retired`, "Read it again and propose again if it should still go.");
|
|
1849
|
+
}
|
|
1850
|
+
const now = await namedBy();
|
|
1851
|
+
if (now.length) return refuse(`The skill ${args.name} is still named by ${now.join(", ")}; nothing was retired`, "Tell the user; they change those agents first.");
|
|
1852
|
+
before = await readFile(rolesFile, "utf8").catch((error) => {
|
|
1853
|
+
if (error.code === "ENOENT") return void 0;
|
|
1854
|
+
throw error;
|
|
1855
|
+
});
|
|
1856
|
+
const roles = await readRoles();
|
|
1857
|
+
const lost = holders(roles);
|
|
1858
|
+
if (JSON.stringify(lost) !== JSON.stringify(given)) {
|
|
1859
|
+
return refuse(`The roles that have ${args.name} changed since it was proposed (proposed: ${given.join(", ") || "none"}; now: ${lost.join(", ") || "none"}); nothing was retired`, "Propose again so the user sees the current roles.");
|
|
1860
|
+
}
|
|
1861
|
+
await mkdir(path.dirname(retired), { recursive: true, mode: 448 });
|
|
1862
|
+
if (lost.length) {
|
|
1863
|
+
for (const role of lost) roles[role] = roles[role].filter((name) => name !== args.name);
|
|
1864
|
+
await writeAtomic(rolesFile, JSON.stringify(roles, null, 2) + "\n");
|
|
1865
|
+
}
|
|
1866
|
+
try {
|
|
1867
|
+
await moveFile(directory, retired);
|
|
1868
|
+
} catch (error) {
|
|
1869
|
+
if (lost.length) {
|
|
1870
|
+
try {
|
|
1871
|
+
if (before === void 0) await rm(rolesFile, { force: true });
|
|
1872
|
+
else await writeAtomic(rolesFile, before);
|
|
1873
|
+
} catch (undo) {
|
|
1874
|
+
return refuse(`${errorData(error).message}; restoring ${rolesFile} also failed: ${errorData(undo).message}`, `Tell the user: the skill is still in ${directory} but ${rolesFile} lost it for ${lost.join(", ")}.`);
|
|
1875
|
+
}
|
|
1876
|
+
}
|
|
1877
|
+
return refuse(`${errorData(error).message}; nothing was retired`, "Tell the user; nothing is retried automatically.");
|
|
1878
|
+
}
|
|
1879
|
+
let metadata;
|
|
1880
|
+
try {
|
|
1881
|
+
await writeAtomic(path.join(retired, "retired.json"), JSON.stringify({ name: args.name, roles: lost, retiredAt: (/* @__PURE__ */ new Date()).toISOString(), agent: session.mapping.agent.name, path: directory }, null, 2) + "\n");
|
|
1882
|
+
} catch (error) {
|
|
1883
|
+
metadata = errorData(error).message;
|
|
1884
|
+
}
|
|
1885
|
+
runLog(rootOf(sessionId), { event: "skill.retire", agent: session.mapping.agent.name, name: args.name, roles: lost, retiredTo: retired, ...metadata ? { metadataError: metadata } : {} });
|
|
1886
|
+
return { approved: true, retired, roles: lost, ...metadata ? { metadataError: metadata } : {}, next: `New sessions no longer list the skill. ${restore}` };
|
|
1887
|
+
} catch (error) {
|
|
1888
|
+
return refuse(`${errorData(error).message}; nothing was retired`, "Tell the user; nothing is retried automatically.");
|
|
1889
|
+
}
|
|
1890
|
+
};
|
|
1891
|
+
void (async () => {
|
|
1892
|
+
const answer = await decision;
|
|
1893
|
+
const canceled = approvalCanceled(session, cancellation);
|
|
1894
|
+
const result = !answer.approved || canceled ? { approved: false, retired: false, outcome: canceled ? "canceled" : answer.outcome, ...answer.feedback ? { feedback: answer.feedback } : {}, next: "Nothing was retired. Revise from the feedback and propose again with a fresh requestId, or drop it." } : await retire();
|
|
1895
|
+
record2.result = { status: "resolved", approvalId, name: args.name, ...result };
|
|
1896
|
+
runLog(rootOf(sessionId), { event: "skill.retire.approval", agent: session.mapping.agent.name, ...record2.result });
|
|
1897
|
+
if (!closed && !session.closed && sessions.get(sessionId) === session) {
|
|
1898
|
+
post(sessionId, { kind: "result", from: "ALP", assignment: approvalId, body: `Skill retirement result: ${JSON.stringify(record2.result)}` });
|
|
1899
|
+
}
|
|
1900
|
+
})();
|
|
1901
|
+
return toolResult(true, { status: "pending_approval", approvalId, file, next: "Continue other work or end your turn. ALP sends the user's decision, and whether the skill was retired, by mail; do not resubmit this request." });
|
|
1902
|
+
}
|
|
1719
1903
|
let scheduleHandler;
|
|
1720
1904
|
async function lessonCurateTool(sessionId, session, args) {
|
|
1721
1905
|
const cancellation = approvalCancellation.get(session) ?? 0;
|
|
@@ -2373,7 +2557,7 @@ ${args.labels?.length ? `${say.issueLabels}: ${args.labels.join(", ")}
|
|
|
2373
2557
|
error: "ALP tools require the current active turn"
|
|
2374
2558
|
});
|
|
2375
2559
|
}
|
|
2376
|
-
if (!["alp_delegate", "alp_handoff", "alp_wait", "alp_cancel", "alp_send", "alp_ask", "alp_merge", "alp_discard", "alp_resolve", "alp_recall", "alp_verify", "alp_pin", "alp_board", "alp_unpin", "alp_lesson", "alp_lesson_curate", "alp_skill", "alp_issue", "alp_task", "alp_schedule"].includes(params.tool) || params.namespace != null || typeof params.callId !== "string") {
|
|
2560
|
+
if (!["alp_delegate", "alp_handoff", "alp_wait", "alp_cancel", "alp_send", "alp_ask", "alp_merge", "alp_discard", "alp_resolve", "alp_recall", "alp_verify", "alp_pin", "alp_board", "alp_unpin", "alp_lesson", "alp_lesson_curate", "alp_skill", "alp_skill_retire", "alp_issue", "alp_task", "alp_schedule"].includes(params.tool) || params.namespace != null || typeof params.callId !== "string") {
|
|
2377
2561
|
return toolResult(false, {
|
|
2378
2562
|
error: "Unknown ALP tool"
|
|
2379
2563
|
});
|
|
@@ -2384,9 +2568,9 @@ ${args.labels?.length ? `${say.issueLabels}: ${args.labels.join(", ")}
|
|
|
2384
2568
|
const oversized = inputLimitError(args, TOOL_INPUT, `${params.tool} input`);
|
|
2385
2569
|
if (oversized) return toolResult(false, { error: oversized });
|
|
2386
2570
|
if (session.role === "supervisor" && !["alp_send", "alp_board", "alp_task"].includes(params.tool)) return toolResult(false, { error: "The supervisor only uses alp_send, alp_board and alp_task" });
|
|
2387
|
-
if (["alp_lesson", "alp_lesson_curate", "alp_skill"].includes(params.tool) && !supervises(session)) return toolResult(false, { error: "Only a supervised main records lessons and skills" });
|
|
2571
|
+
if (["alp_lesson", "alp_lesson_curate", "alp_skill", "alp_skill_retire"].includes(params.tool) && !supervises(session)) return toolResult(false, { error: "Only a supervised main records lessons and skills" });
|
|
2388
2572
|
if (params.tool === "alp_issue" && (session.parent || session.mapping.agent.name !== mainOf(session.mapping))) return toolResult(false, { error: "Only main files issues; report the problem to your requester" });
|
|
2389
|
-
const work = params.tool === "alp_lesson" ? lessonTool(sessionId, session, args) : params.tool === "alp_lesson_curate" ? lessonCurateTool(sessionId, session, args) : params.tool === "alp_skill" ? skillTool(sessionId, session, args) : params.tool === "alp_issue" ? issueTool(sessionId, session, args) : params.tool === "alp_schedule" ? scheduleTool(sessionId, session, args) : params.tool === "alp_task" ? taskToolCall(sessionId, session, args) : params.tool === "alp_delegate" ? runDelegation(sessionId, session, params) : params.tool === "alp_wait" ? waitTool(sessionId, session, args) : params.tool === "alp_ask" ? askTool(sessionId, session, args) : params.tool === "alp_pin" ? pinTool(sessionId, session, args) : params.tool === "alp_board" ? boardTool(session, args) : params.tool === "alp_unpin" ? unpinTool(sessionId, session, args) : params.tool === "alp_recall" ? recallTool(sessionId, session, args) : params.tool === "alp_resolve" ? resolveTool(sessionId, session, args) : params.tool === "alp_verify" ? verifyTool(sessionId, session, args) : params.tool === "alp_cancel" ? cancelTool(sessionId, session, args) : params.tool === "alp_merge" || params.tool === "alp_discard" ? worktreeTool(sessionId, session, args, params.tool === "alp_merge" ? "merge" : "discard") : params.tool === "alp_send" ? Promise.resolve(sendTool(sessionId, session, args)) : hookedHandoff(sessionId, session, args);
|
|
2573
|
+
const work = params.tool === "alp_lesson" ? lessonTool(sessionId, session, args) : params.tool === "alp_lesson_curate" ? lessonCurateTool(sessionId, session, args) : params.tool === "alp_skill" ? skillTool(sessionId, session, args) : params.tool === "alp_skill_retire" ? skillRetireTool(sessionId, session, args) : params.tool === "alp_issue" ? issueTool(sessionId, session, args) : params.tool === "alp_schedule" ? scheduleTool(sessionId, session, args) : params.tool === "alp_task" ? taskToolCall(sessionId, session, args) : params.tool === "alp_delegate" ? runDelegation(sessionId, session, params) : params.tool === "alp_wait" ? waitTool(sessionId, session, args) : params.tool === "alp_ask" ? askTool(sessionId, session, args) : params.tool === "alp_pin" ? pinTool(sessionId, session, args) : params.tool === "alp_board" ? boardTool(session, args) : params.tool === "alp_unpin" ? unpinTool(sessionId, session, args) : params.tool === "alp_recall" ? recallTool(sessionId, session, args) : params.tool === "alp_resolve" ? resolveTool(sessionId, session, args) : params.tool === "alp_verify" ? verifyTool(sessionId, session, args) : params.tool === "alp_cancel" ? cancelTool(sessionId, session, args) : params.tool === "alp_merge" || params.tool === "alp_discard" ? worktreeTool(sessionId, session, args, params.tool === "alp_merge" ? "merge" : "discard") : params.tool === "alp_send" ? Promise.resolve(sendTool(sessionId, session, args)) : hookedHandoff(sessionId, session, args);
|
|
2390
2574
|
const reminded = !session.parent && params.tool !== "alp_ask" ? work.then((result) => remindUser(session, result)) : work;
|
|
2391
2575
|
session.toolCalls.set(params.callId, reminded);
|
|
2392
2576
|
return reminded;
|
|
@@ -2777,13 +2961,24 @@ ${gate.note ?? ""}`,
|
|
|
2777
2961
|
if (args.agent === "oracle" && !session.mapping.oracleModels.includes(args.model)) return toolResult(false, { error: `Oracle runs on ${session.mapping.oracleModels.join(" or ")}; pass one as model. For two opinions, start one on each with wait: false` });
|
|
2778
2962
|
const configuredModels = args.agent === "oracle" ? [] : session.mapping.modelProfiles[args.agent] ?? [];
|
|
2779
2963
|
const listed = configuredModels.map(profileModel).filter((id) => Boolean(id));
|
|
2964
|
+
const allowed = listed.map((id) => id.endsWith(":*") ? `any ${id.slice(0, -1)} model` : id).join(" or ");
|
|
2780
2965
|
const choosing = configuredModels.length > 1 || configuredModels.some(anyModel);
|
|
2781
|
-
if (choosing && (args.model === void 0 || args.thinking === void 0)) return toolResult(false, { error: `${args.agent} has several model profiles: choose one for this task as model, its effort as thinking, and say why in modelReason`, models: listed });
|
|
2782
|
-
if (
|
|
2783
|
-
|
|
2784
|
-
|
|
2966
|
+
if (choosing && (args.model === void 0 || args.thinking === void 0)) return toolResult(false, { error: `${args.agent} has several model profiles: choose one for this task as model, its effort as thinking, and say why in modelReason. Pass ${allowed}`, models: listed });
|
|
2967
|
+
if (args.model !== void 0 && listed.length && !offers(configuredModels, args.model)) {
|
|
2968
|
+
const team = session.mapping.workflow.mode;
|
|
2969
|
+
const settingsFile = path.join(session.mapping.agent.projectRoot, ".alp", "settings.json");
|
|
2970
|
+
const provider = args.model.slice(0, args.model.indexOf(":"));
|
|
2971
|
+
const setup = ["pho", "cafe"].includes(team) && ["claude", "codex"].includes(provider) ? `, or run alp setup ${session.mapping.agent.projectRoot} --runtime mix, which gives Ph\u1EDF's and Cafe's members both Claude and Codex profiles (it keeps profiles written by hand or set in a team.json)` : "";
|
|
2972
|
+
return toolResult(false, {
|
|
2973
|
+
error: `${args.model} is not one of ${args.agent}'s model profiles in team ${team}; pass ${allowed}${choosing ? "" : ", or omit model to run on it"}. The user can allow it by adding it to team.${team}.${args.agent}.profiles in ${settingsFile} ("provider:model" or "provider:model:effort", or "${provider}:*" for any model of that provider, which makes you choose model and effort per assignment)${setup}.`,
|
|
2974
|
+
models: listed
|
|
2975
|
+
});
|
|
2976
|
+
}
|
|
2785
2977
|
const configuredDefault = !choosing && listed.length === 1 ? listed[0] : void 0;
|
|
2786
2978
|
const delegatedModel = args.model ?? configuredDefault ?? `${session.runtimeKind}:${session.mapping.model}`;
|
|
2979
|
+
const efforts = args.thinking !== void 0 && listed.length ? profileEfforts(delegatedModel) : [];
|
|
2980
|
+
if (efforts.length && !efforts.includes(args.thinking)) return toolResult(false, { error: `${delegatedModel} takes effort ${efforts.join(", ")}`, efforts });
|
|
2981
|
+
const thinkingNote = args.thinking !== void 0 && !efforts.length ? listed.length ? `effort ${args.thinking} was not checked: ALP does not know which efforts ${delegatedModel} takes` : `effort ${args.thinking} was not checked: no model profile of ${args.agent} names a model` : void 0;
|
|
2787
2982
|
const delegatedThinking = args.thinking ?? selectedProfile(configuredModels, delegatedModel)?.effort ?? (args.model || configuredDefault ? void 0 : session.mapping.thinking);
|
|
2788
2983
|
const childRuntime = delegatedModel.split(":")[0];
|
|
2789
2984
|
if (!paused.all && paused.runtimes[childRuntime]?.by === "alpd") await checkLimit(childRuntime, LIMIT_FRESH_MS);
|
|
@@ -2791,19 +2986,20 @@ ${gate.note ?? ""}`,
|
|
|
2791
2986
|
if (hold) {
|
|
2792
2987
|
const other = RUNTIMES.find((kind) => kind !== childRuntime && !pauseOf(kind));
|
|
2793
2988
|
const instead = listed.filter((id) => other && id.startsWith(`${other}:`)).map((id) => id.endsWith(":*") ? `any ${id.slice(0, -1)} model` : id);
|
|
2794
|
-
const next = !other ? "Wait until the user resumes ALP" : !
|
|
2989
|
+
const next = !other ? "Wait until the user resumes ALP" : !listed.length ? `Pass a model of ${other}: from the catalog to run it on ${label(other)}, or wait` : instead.length ? `Pass ${instead.join(" or ")} to run it on ${label(other)}, or wait` : `None of ${args.agent}'s model profiles runs on ${label(other)}: wait`;
|
|
2795
2990
|
return toolResult(false, { error: describePause(hold, paused.all ? void 0 : childRuntime), next });
|
|
2796
2991
|
}
|
|
2797
2992
|
let childProfile;
|
|
2798
2993
|
try {
|
|
2799
|
-
childProfile = await profileFor(session.mapping.agent.projectRoot, options.libraryDir, args.agent);
|
|
2994
|
+
childProfile = await profileFor(session.mapping.agent.projectRoot, options.libraryDir, args.agent, { readOnly: readOnlyMember(session.mapping, args.agent) });
|
|
2800
2995
|
} catch (error) {
|
|
2801
2996
|
return toolResult(false, { error: errorData(error).message });
|
|
2802
2997
|
}
|
|
2803
2998
|
const childMode = childProfile ? capMode(args.mode ?? session.mapping.mode, childProfile.base) : args.mode ?? session.mapping.mode;
|
|
2804
2999
|
const capped = {
|
|
2805
3000
|
...childProfile && childMode !== (args.mode ?? session.mapping.mode) ? { mode: childMode, modeNote: `${args.agent} runs ${childMode}: its permission profile ${childProfile.name} caps it` } : {},
|
|
2806
|
-
...childProfile?.workdir === "copy" && isolationOf(args) === "shared" ? { workdirNote: `${args.agent} works in a disposable copy of your tree; nothing it changes reaches yours` } : {}
|
|
3001
|
+
...childProfile?.workdir === "copy" && isolationOf(args) === "shared" ? { workdirNote: `${args.agent} works in a disposable copy of your tree; nothing it changes reaches yours` } : {},
|
|
3002
|
+
...thinkingNote ? { thinkingNote } : {}
|
|
2807
3003
|
};
|
|
2808
3004
|
let sharedContinuation;
|
|
2809
3005
|
if (args.continueFrom !== void 0) {
|
|
@@ -2843,7 +3039,7 @@ ${gate.note ?? ""}`,
|
|
|
2843
3039
|
let task;
|
|
2844
3040
|
if (args.taskId !== void 0) {
|
|
2845
3041
|
if (session.parent || session.mapping.agent.name !== mainOf(session.mapping)) return toolResult(false, { error: "Only main gives tasks to assignments" });
|
|
2846
|
-
if (
|
|
3042
|
+
if (readOnlyMember(session.mapping, args.agent)) return toolResult(false, { error: "taskId gives a task to lead or peer; for advice about a task, name it in the brief" });
|
|
2847
3043
|
if (typeof args.taskId !== "string") return toolResult(false, { error: "taskId must be a task id" });
|
|
2848
3044
|
try {
|
|
2849
3045
|
const { tasks } = await loadTasks(project);
|
|
@@ -3239,7 +3435,9 @@ ${digest}` : "")
|
|
|
3239
3435
|
nativeItem(
|
|
3240
3436
|
sessionId,
|
|
3241
3437
|
session,
|
|
3242
|
-
item
|
|
3438
|
+
item,
|
|
3439
|
+
false,
|
|
3440
|
+
turn.id
|
|
3243
3441
|
);
|
|
3244
3442
|
}
|
|
3245
3443
|
}
|
|
@@ -3316,7 +3514,7 @@ ${digest}` : "")
|
|
|
3316
3514
|
session.role,
|
|
3317
3515
|
supervises(session),
|
|
3318
3516
|
lessonFiles(mapping),
|
|
3319
|
-
Object.fromEntries(await Promise.all(targets.map(async (target) => [target, await profileFor(mapping.agent.projectRoot, options.libraryDir, target).catch(() => null)])))
|
|
3517
|
+
Object.fromEntries(await Promise.all(targets.map(async (target) => [target, await profileFor(mapping.agent.projectRoot, options.libraryDir, target, { readOnly: readOnlyMember(mapping, target) }).catch(() => null)])))
|
|
3320
3518
|
);
|
|
3321
3519
|
if (session.spec.writeRoot && session.runtimeKind === "claude" && mapping.mode === "workspace-write" && claudeSandboxAvailable()) Object.assign(config, { floor: "workspace-write" });
|
|
3322
3520
|
if (session.spec.writeRoot) config.developerInstructions += `
|
|
@@ -3551,7 +3749,7 @@ Write scope: change files only under ${session.spec.writeRoot}. Your working dir
|
|
|
3551
3749
|
if (mapping.agent.name !== session.mapping.agent.name) return refused("agent_mismatch", "A session keeps its agent; start a new session for another agent");
|
|
3552
3750
|
const agent = session.mapping.agent.name;
|
|
3553
3751
|
if (teamChanged && agent === mainOf(session.mapping) && agent !== mainOf(mapping)) return refused("agent_mismatch", `Team ${mapping.team?.label ?? team}'s main agent is ${mainOf(mapping)}, not ${agent}; start a new session with that team`);
|
|
3554
|
-
if (changes.mode !== void 0 && mapping.mode !== changes.mode) return refused("permission_escalation",
|
|
3752
|
+
if (changes.mode !== void 0 && mapping.mode !== changes.mode) return refused("permission_escalation", readOnlyMember(mapping, agent) ? "Advisors and the supervisor must remain read-only" : `Permission profile ${mapping.permissions?.name ?? ""} allows at most ${mapping.permissions?.base ?? mapping.mode}`.replace("profile allows", "profile allows"));
|
|
3555
3753
|
if (changes.mode === void 0 && !withinMode(mapping.mode, session.mapping.mode)) return refused("permission_escalation", `The change would run the session in ${mapping.mode}, beyond its ${session.mapping.mode}`);
|
|
3556
3754
|
const before = executablesOf(session.mapping);
|
|
3557
3755
|
const added = [...executablesOf(mapping)].filter((entry) => !before.has(entry));
|
|
@@ -3955,7 +4153,7 @@ Write scope: change files only under ${session.spec.writeRoot}. Your working dir
|
|
|
3955
4153
|
if (!modes.some((candidate) => candidate.id === mode)) throw new Error(`Unsupported mode '${mode}'`);
|
|
3956
4154
|
const profile = session.mapping.permissions;
|
|
3957
4155
|
if (profile && !withinMode(mode, profile.base)) {
|
|
3958
|
-
throw new Error(
|
|
4156
|
+
throw new Error(readOnlyMember(session.mapping, session.mapping.agent.name) ? "Advisors and the supervisor must remain read-only" : `Permission profile ${profile.name} allows at most ${profile.base}`);
|
|
3959
4157
|
}
|
|
3960
4158
|
const parent = session.parent ? sessions.get(session.parent) : void 0;
|
|
3961
4159
|
if (parent && !withinMode(mode, parent.mapping.mode)) throw new Error("Child cannot exceed parent permissions");
|
|
@@ -4026,7 +4224,7 @@ Write scope: change files only under ${session.spec.writeRoot}. Your working dir
|
|
|
4026
4224
|
emit(sessionId, { type: "prompt.failed", clientMessageId: input.clientMessageId, error: errorData(error) });
|
|
4027
4225
|
}
|
|
4028
4226
|
}
|
|
4029
|
-
async function startPrompt(sessionId, prompt, origin, wake) {
|
|
4227
|
+
async function startPrompt(sessionId, prompt, origin, wake, internalCompact = false) {
|
|
4030
4228
|
const session = openOf(sessionId);
|
|
4031
4229
|
if (session.seen.has(
|
|
4032
4230
|
prompt.clientMessageId
|
|
@@ -4036,6 +4234,8 @@ Write scope: change files only under ${session.spec.writeRoot}. Your working dir
|
|
|
4036
4234
|
if (prompt.content.some((content) => content.type !== "text" && content.type !== "image" && content.type !== "attachment")) {
|
|
4037
4235
|
throw new Error("Only text, image and attachment prompts are supported");
|
|
4038
4236
|
}
|
|
4237
|
+
const refusal = origin === "user" ? nativeCommandRefusal(session.runtimeKind, prompt.content, session.runtime.customCommands?.()) : void 0;
|
|
4238
|
+
if (refusal) throw new Error(refusal);
|
|
4039
4239
|
const images = prompt.content.filter((content) => content.type === "image");
|
|
4040
4240
|
if (images.length) {
|
|
4041
4241
|
if (!takesImages(session)) throw new Error(`${session.runtimeKind === "acp" ? "This ACP agent" : session.runtimeKind[0].toUpperCase() + session.runtimeKind.slice(1)} takes no images; send the message as text`);
|
|
@@ -4086,7 +4286,7 @@ Write scope: change files only under ${session.spec.writeRoot}. Your working dir
|
|
|
4086
4286
|
if (prompt.delivery !== "steer") {
|
|
4087
4287
|
session.text.clear();
|
|
4088
4288
|
session.toolCalls.clear();
|
|
4089
|
-
if (
|
|
4289
|
+
if (!internalCompact) session.compactCooling = false;
|
|
4090
4290
|
session.supervisorWake = !!wake?.length && wake.every((event) => event.defer);
|
|
4091
4291
|
if (!wake) {
|
|
4092
4292
|
session.handoff = void 0;
|
|
@@ -4147,6 +4347,11 @@ ${interrupted}`), text_elements: [] }] : []
|
|
|
4147
4347
|
}
|
|
4148
4348
|
);
|
|
4149
4349
|
const turnId = prompt.delivery === "steer" ? session.active : result.turn.id;
|
|
4350
|
+
if (internalCompact) {
|
|
4351
|
+
const echoes = compactEchoes.get(session) ?? /* @__PURE__ */ new Map();
|
|
4352
|
+
echoes.set(`${session.threadId}:${turnId}`, inputDigest(nativeInput.flatMap((part) => "text" in part ? [String(part.text)] : [])));
|
|
4353
|
+
compactEchoes.set(session, echoes);
|
|
4354
|
+
}
|
|
4150
4355
|
for (const event of mail) event.deliveredTurn = turnId;
|
|
4151
4356
|
if (!session.parent && origin === "user") {
|
|
4152
4357
|
session.calls = 0;
|
|
@@ -4155,7 +4360,7 @@ ${interrupted}`), text_elements: [] }] : []
|
|
|
4155
4360
|
session.seen.add(
|
|
4156
4361
|
prompt.clientMessageId
|
|
4157
4362
|
);
|
|
4158
|
-
emit(sessionId, {
|
|
4363
|
+
if (!internalCompact) emit(sessionId, {
|
|
4159
4364
|
type: "item",
|
|
4160
4365
|
item: {
|
|
4161
4366
|
kind: "user_message",
|
|
@@ -4305,6 +4510,10 @@ ${interrupted}`), text_elements: [] }] : []
|
|
|
4305
4510
|
bindAttachments(reader) {
|
|
4306
4511
|
attachmentReader = reader;
|
|
4307
4512
|
},
|
|
4513
|
+
refusesPrompt(sessionId, content) {
|
|
4514
|
+
const session = sessions.get(sessionId);
|
|
4515
|
+
return session ? nativeCommandRefusal(session.runtimeKind, content, session.runtime.customCommands?.()) : void 0;
|
|
4516
|
+
},
|
|
4308
4517
|
takesAttachments(sessionId) {
|
|
4309
4518
|
const session = sessions.get(sessionId);
|
|
4310
4519
|
return !!session && !session.closed && attachmentRoutes(session).includes("file.path");
|
|
@@ -4574,6 +4783,7 @@ ${interrupted}`), text_elements: [] }] : []
|
|
|
4574
4783
|
return entries.map((entry) => ({ assignmentId: entry.assignmentId, agent: entry.agent, outcome: "failed", error: reason }));
|
|
4575
4784
|
},
|
|
4576
4785
|
async shutdown() {
|
|
4786
|
+
compactEchoes.clear();
|
|
4577
4787
|
closed = true;
|
|
4578
4788
|
await queue;
|
|
4579
4789
|
await Promise.all(
|