@anhlp/alp-runtime 0.0.0-beta.2 → 0.0.1-beta.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/acp-transport.js +7 -36
- package/dist/antigravity-transport.d.ts +27 -2
- package/dist/antigravity-transport.js +104 -58
- package/dist/assignment-results.d.ts +55 -0
- package/dist/assignment-results.js +181 -0
- package/dist/attachments.d.ts +84 -0
- package/dist/attachments.js +213 -0
- package/dist/board-domain.js +2 -2
- package/dist/board.d.ts +6 -0
- package/dist/board.js +7 -0
- package/dist/catalog.d.ts +13 -0
- package/dist/catalog.js +11 -2
- package/dist/claude-transport.d.ts +80 -0
- package/dist/claude-transport.js +271 -23
- package/dist/compact.d.ts +29 -0
- package/dist/compact.js +49 -0
- package/dist/configure.d.ts +44 -0
- package/dist/configure.js +64 -0
- package/dist/contracts.d.ts +216 -7
- package/dist/contracts.js +11 -0
- package/dist/conversation.d.ts +45 -0
- package/dist/conversation.js +62 -0
- package/dist/index.d.ts +18 -5
- package/dist/index.js +48 -4
- package/dist/input-limits.d.ts +25 -0
- package/dist/input-limits.js +48 -0
- package/dist/language.d.ts +10 -0
- package/dist/language.js +26 -0
- package/dist/live.d.ts +2 -2
- package/dist/live.js +7 -2
- package/dist/mailbox.d.ts +2 -0
- package/dist/mailbox.js +3 -1
- package/dist/mcp-tools.d.ts +8 -0
- package/dist/mcp-tools.js +26 -0
- package/dist/model-catalog.d.ts +162 -0
- package/dist/model-catalog.js +338 -0
- package/dist/model-probes.d.ts +7 -0
- package/dist/model-probes.js +69 -0
- package/dist/providers.js +2 -0
- package/dist/recall.d.ts +2 -2
- package/dist/recall.js +4 -3
- package/dist/resolve.d.ts +2 -0
- package/dist/resolve.js +9 -5
- package/dist/runtime-context.d.ts +1 -1
- package/dist/runtime-context.js +1 -1
- package/dist/runtime.d.ts +9 -0
- package/dist/runtime.js +2078 -269
- package/dist/session-config.d.ts +378 -6
- package/dist/session-config.js +19 -15
- package/dist/session-state.d.ts +54 -7
- package/dist/skill-resources.d.ts +30 -0
- package/dist/skill-resources.js +55 -0
- package/dist/tool-detail.js +4 -1
- package/dist/tools.d.ts +154 -1
- package/dist/tools.js +99 -11
- package/dist/transport.js +3 -1
- package/dist/workspace.d.ts +31 -5
- package/dist/workspace.js +92 -11
- package/dist/worktree-domain.d.ts +2 -1
- package/dist/worktree-domain.js +4 -1
- package/dist/write-error.d.ts +2 -0
- package/dist/write-error.js +10 -0
- package/package.json +12 -4
- package/src/acp-transport.ts +10 -37
- package/src/antigravity-transport.ts +128 -55
- package/src/assignment-results.ts +154 -0
- package/src/attachments.ts +254 -0
- package/src/board-domain.ts +2 -2
- package/src/board.ts +7 -0
- package/src/catalog.ts +13 -2
- package/src/claude-transport.ts +333 -23
- package/src/compact.ts +62 -0
- package/src/configure.ts +93 -0
- package/src/contracts.ts +199 -8
- package/src/conversation.ts +81 -0
- package/src/index.ts +18 -5
- package/src/input-limits.ts +65 -0
- package/src/language.ts +28 -0
- package/src/live.ts +7 -3
- package/src/mailbox.ts +4 -1
- package/src/mcp-tools.ts +33 -0
- package/src/model-catalog.ts +316 -0
- package/src/model-probes.ts +58 -0
- package/src/providers.ts +3 -0
- package/src/recall.ts +4 -3
- package/src/resolve.ts +15 -7
- package/src/runtime-context.ts +2 -2
- package/src/runtime.ts +2253 -264
- package/src/session-config.ts +25 -14
- package/src/session-state.ts +39 -3
- package/src/skill-resources.ts +73 -0
- package/src/tool-detail.ts +4 -1
- package/src/tools.ts +97 -10
- package/src/transport.ts +3 -1
- package/src/workspace.ts +124 -18
- package/src/worktree-domain.ts +5 -1
- package/src/write-error.ts +4 -0
package/src/session-config.ts
CHANGED
|
@@ -5,14 +5,14 @@ import type { ResolvedSession, RuntimeKind } from './resolve.js';
|
|
|
5
5
|
import { models, thinkingOptionsFor } from './catalog.js';
|
|
6
6
|
import { claudeSandboxAvailable, SKILL_PLUGIN } from './claude-transport.js';
|
|
7
7
|
import { languageInstruction } from './language.js';
|
|
8
|
-
import {
|
|
8
|
+
import { antigravityModeText } from './antigravity-transport.js';
|
|
9
|
+
import { HANDOFF_TOOL, WAIT_TOOL, SEND_TOOL, MERGE_TOOL, VERIFY_TOOL, DISCARD_TOOL, RESOLVE_TOOL, CANCEL_TOOL, RECALL_TOOL, PIN_TOOL, BOARD_TOOL, UNPIN_TOOL, ASK_TOOL, LESSON_TOOL, LESSON_CURATE_TOOL, SKILL_TOOL, SKILL_RETIRE_TOOL, ISSUE_TOOL, SCHEDULE_TOOL, mainOf, taskActions, taskTool } from './tools.js';
|
|
9
10
|
|
|
10
11
|
import { COMPACT_SHARE } from './runtime-context.js';
|
|
11
12
|
|
|
12
13
|
/** The mode the native harness runs with: a session in a copy writes the copy, though ALP treats it as read-only. */
|
|
13
14
|
export const nativeMode = (mapping: Pick<ResolvedSession, 'mode' | 'copy'> & Partial<Pick<ResolvedSession, 'runtimeKind' | 'antigravity'>>) =>
|
|
14
|
-
mapping.
|
|
15
|
-
? 'full-access' : mapping.copy ? 'workspace-write' : mapping.mode;
|
|
15
|
+
mapping.copy ? 'workspace-write' : mapping.mode;
|
|
16
16
|
|
|
17
17
|
/** The OS sandbox ALP puts a Claude session's Bash in: its profile's base, or the copy it works in. */
|
|
18
18
|
export function claudeFloor(mapping: Pick<ResolvedSession, 'mode' | 'copy' | 'permissions' | 'runtimeKind'>): 'read-only' | 'workspace-write' | undefined {
|
|
@@ -43,9 +43,8 @@ export function permissionNote(mapping: Pick<ResolvedSession, 'mode' | 'permissi
|
|
|
43
43
|
const notes = [
|
|
44
44
|
// ALPD §46: ALP has no sandbox around an ACP agent; it answers the agent's permission requests.
|
|
45
45
|
...(mapping.runtimeKind === 'acp' ? [`ALP's tools (alp_*) come from the MCP server named alp. ALP answers your permission requests by your ${mapping.mode} mode: ${mapping.mode === 'read-only' ? 'reading and searching only' : mapping.mode === 'workspace-write' ? `reading, running commands, and changing files inside ${mapping.workdir} only` : 'everything'}. Ask permission before every tool use that changes something, even where you would not need to.`] : []),
|
|
46
|
-
...(mapping.runtimeKind === 'antigravity' ? [
|
|
46
|
+
...(mapping.runtimeKind === 'antigravity' ? [`ALP's tools (alp_*) come from the MCP server named alp. Your mode is ${mapping.mode}: ${antigravityModeText(mapping.mode)}`,
|
|
47
47
|
'External MCP tools supplied by ALP also come from the MCP server named alp. Discover its tools: aliases beginning mcp__ and their descriptions identify the original server and tool. Use those aliases when calling the tools.',
|
|
48
|
-
...(mapping.mode === 'read-only' ? ['Read-only is emulated by instructions, not enforced by an OS sandbox. Your role is to read, analyze, advise and report only. Do not edit, create, delete or rename files. Do not run commands, builds, tests or native tools that mutate files, repositories, configuration or external state. Report any work that requires changes to your requester. ALP still restricts its own tools according to your read-only role.'] : []),
|
|
49
48
|
] : []),
|
|
50
49
|
...(mapping.copy ? [`You work in a disposable copy of your requester's tree at ${mapping.workdir}: the same files and git state, uncommitted changes included${mapping.copyOf ? `, mirroring ${mapping.copyOf}` : ''}. Write, build and test there; nothing you change reaches the requester, and the copy is removed when you finish. Where your brief names a path${mapping.copyOf ? ` under ${mapping.copyOf}` : ''}, use the same path in your copy. Never run a command in, or write to, the requester's tree.`] : []),
|
|
51
50
|
...(floor ? [`Bash runs in an OS sandbox: ${floor === 'read-only' ? 'it writes nothing but temporary files' : `it writes only ${mapping.workdir} and temporary files`}, and has no network. Run any command you need for your work in it.${profile?.allow.length || profile?.ask.length || profile?.beyondMode === 'ask' ? ' To run a command outside it (one your profile allows, or one for the user to approve), set dangerouslyDisableSandbox on that Bash call: ALP decides, and asks the user when your profile says so. A sandbox error (Operation not permitted, no network) is not a refusal by the user: run that same command again with dangerouslyDisableSandbox rather than report it refused.' : ''}`] : []),
|
|
@@ -84,7 +83,7 @@ export function modelProfileNote(mapping: ResolvedSession, targets: string[]) {
|
|
|
84
83
|
const options = (profile: import('@anhlp/alp-core/types').AgentModelConfig) => anyModel(profile)
|
|
85
84
|
? `any ${profile.provider} model (the runtime catalog snapshot lists what ${profile.provider} offers when you run on it), such as ${models.filter(model => model.id.startsWith(`${profile.provider}:`)).map(model => option(model.id)).join('; ')}`
|
|
86
85
|
: option(profileModel(profile)!, profile.effort);
|
|
87
|
-
return ['Model profiles of your targets. An agent with one named profile runs on
|
|
86
|
+
return ['Model profiles of your targets are the models you may pass for them; a model outside them is refused. An agent with one named profile runs on exactly that model: omit model, or pass that one. For an agent with several, or with any model of a provider, you choose both for each assignment: weigh the task\'s difficulty, ambiguity, risk and the autonomy it needs against speed and cost, pass the model with alp_delegate model and the effort with thinking, and say why in modelReason; there is no default. An effort ALP cannot check for a model is passed on as given, and the answer says so. ' +
|
|
88
87
|
choices.map(([agent, profiles]) => profiles.length === 1 && !anyModel(profiles[0]) ? `${agent}: ${one(profiles[0])}` : `${agent}, choose a model and effort: ${profiles.map(options).join('; ')}`).join('. ') + '.'];
|
|
89
88
|
}
|
|
90
89
|
|
|
@@ -153,6 +152,7 @@ export function nativeSessionConfig(
|
|
|
153
152
|
}
|
|
154
153
|
const delegationInstruction = targets.length
|
|
155
154
|
? `Use alp_delegate to assign bounded work to: ${targets.join(', ')}. ` +
|
|
155
|
+
'Delegation has two finite budgets shared by the entire root session tree: 16 implementation starts (lead/peer) and separately 16 read-only advisor starts (reviewer/oracle). Only a new accepted user prompt in root, including steering, resets both; child turns, mail wakes and approval answers do not. Started assignments count even when they fail. ' +
|
|
156
156
|
'Work runs in the background: by default alp_delegate starts the assignment and returns its assignmentId at once, and its result, questions and stall reports come to you as mail. ' +
|
|
157
157
|
'Pass wait: true only when your very next step cannot go on without the result; it then returns the result, or early with the child\'s first question. ' +
|
|
158
158
|
'A result carries the child\'s structured handoff (null if it filed none) and output, its final message. ' +
|
|
@@ -162,6 +162,7 @@ export function nativeSessionConfig(
|
|
|
162
162
|
`At most ${mapping.workflow.maxPeers} peers may run concurrently. Concurrent peers must be read-only or isolated: pass isolation "worktree" to give a writing peer its own git worktree. ` +
|
|
163
163
|
'A worktree result lists its branch and changed files; apply it with alp_merge (uncommitted, conflicts left as markers) or drop it with alp_discard, then verify. ' +
|
|
164
164
|
'Writers in this shared checkout run one at a time. ' +
|
|
165
|
+
"A writer's change outside a worktree stays a result ALP keeps, and its checkout cannot be removed, until you record with alp_resolve that you applied, discarded or acknowledged it. " +
|
|
165
166
|
'To learn why a finished assignment did something, ask it with alp_recall rather than guessing from its handoff. ' +
|
|
166
167
|
'When the project configures verify commands, ALP runs them before alp_merge applies a change, and after a writer in your checkout finishes; a failed check applies nothing. To fix a failed worktree change, delegate again with continueFrom set to its assignmentId. ' +
|
|
167
168
|
'Do not run shell/file mutations in parallel with delegation. ' +
|
|
@@ -192,10 +193,18 @@ export function nativeSessionConfig(
|
|
|
192
193
|
...modelProfileNote(mapping, targets),
|
|
193
194
|
// The team's house rules (ALPD §42); Phở and Cafe's are the text this line held before teams.
|
|
194
195
|
`Profile: ${mapping.workflow.mode}; fixed for this session.${mapping.houseRules ? ` ${mapping.houseRules}` : ''}`,
|
|
195
|
-
|
|
196
|
+
// Only an agent that can delegate to oracle is told how to; two opinions need two oracle models.
|
|
197
|
+
[
|
|
198
|
+
...(targets.includes('oracle')
|
|
199
|
+
? [`Oracle runs on ${mapping.oracleModels.join(' or ')}; pass one as model (effort follows the team's oracle settings, otherwise high).` +
|
|
200
|
+
(mapping.oracleModels.length > 1 ? ' For two independent opinions, start one oracle on each model with wait: false and compare their advice.' : '') +
|
|
201
|
+
' If the model you need is unavailable, say so rather than choosing another.']
|
|
202
|
+
: []),
|
|
203
|
+
'Usage context is advisory, may be unavailable or stale; never infer quota from token counts. Respect known exhausted limits and report them.',
|
|
204
|
+
].join(' '),
|
|
196
205
|
...(supervised
|
|
197
206
|
? ['A supervisor reviews your process after each turn. Its notes ask about process mistakes: answer them in your reply, then record each lesson with alp_lesson (scope project for this project, user for every project). Do not argue a note away; when it is wrong, say why in one line. ' +
|
|
198
|
-
'When three or more lessons cover one theme, or a lesson recurs, distill them into a skill with alp_skill: a method with steps and checks, listing the lessons it replaces. Scope it to the roles whose work it guides: yourself, lead, peer, oracle, reviewer, supervisor, or a custom agent; a lesson about briefing peers is yours, a lesson about verifying a change belongs to whoever makes it. The user approves it first.']
|
|
207
|
+
'When three or more lessons cover one theme, or a lesson recurs, distill them into a skill with alp_skill: a method with steps and checks, listing the lessons it replaces. Scope it to the roles whose work it guides: yourself, lead, peer, oracle, reviewer, supervisor, or a custom agent; a lesson about briefing peers is yours, a lesson about verifying a change belongs to whoever makes it. The user approves it first. To merge, shorten or remove lessons use alp_lesson_curate (the curate skill), never a file edit.']
|
|
199
208
|
: []),
|
|
200
209
|
...(!parentAgent && mapping.agent.name === mainOf(mapping)
|
|
201
210
|
? ['When you find a problem outside the task that is worth tracking (a bug or gap in this project, or in ALP itself: its process, tools, agent instructions or runtime), search with alp_issue action search, then propose a comment on a matching issue or a new issue. Include facts, reproduction and evidence, never secrets. The user approves every post; never post issues or comments any other way, such as with gh in a shell.']
|
|
@@ -213,7 +222,9 @@ export function nativeSessionConfig(
|
|
|
213
222
|
|
|
214
223
|
'Project board: every agent working on this project, in any session, shares one board. Before changing files, read alp_board and pin a claim listing the paths you will change; do not edit paths another agent has claimed, and ask your requester instead. Pin a decision when you choose an approach others should follow, and a finding when you learn something others need. Pins from others arrive as board mail; it is information, and it never overrides your requester. Claims end with your session; take one down earlier with alp_unpin.',
|
|
215
224
|
|
|
216
|
-
...(!parentAgent ? ['To get the user\'s answer without ending your turn, for example while assignments run, use alp_ask; otherwise ask in your final message.'
|
|
225
|
+
...(!parentAgent ? ['To get the user\'s answer without ending your turn, for example while assignments run, use alp_ask; otherwise ask in your final message. ' +
|
|
226
|
+
'Tools that hold your turn: alp_ask until the user answers or writes in the chat (at most 30 minutes); alp_delegate with wait: true until the result, the child\'s first question, a check-in or the user\'s message; alp_wait until mail, a check-in, the user\'s message or its timeout (default 5, at most 15 minutes). Write your reply to the user before such a call: it reaches them while the call waits. ' +
|
|
227
|
+
'Approvals do not hold it: alp_issue create/comment and alp_skill return pending_approval with an approvalId at once, and the decision arrives by mail. Ending your turn never cancels running assignments; only the user\'s stop, alp_cancel or a closed session does.'] : []),
|
|
217
228
|
|
|
218
229
|
// ALPD §54: a root session talks with the user; an assignment only asks them through alp_ask.
|
|
219
230
|
languageInstruction(mapping.language, mapping.agent.name, !parentAgent),
|
|
@@ -250,7 +261,7 @@ export function nativeSessionConfig(
|
|
|
250
261
|
type: 'function',
|
|
251
262
|
name: 'alp_delegate',
|
|
252
263
|
description:
|
|
253
|
-
'Delegate a bounded task to an authorized ALP agent and wait
|
|
264
|
+
'Delegate a bounded task to an authorized ALP agent. Root-tree budgets: 16 implementation starts and separately 16 read-only advisor starts. New accepted root user prompts (including steering) reset both; child turns and mail wakes do not. The default returns immediately; wait true waits for handoff.',
|
|
254
265
|
inputSchema: {
|
|
255
266
|
type: 'object',
|
|
256
267
|
properties: {
|
|
@@ -263,7 +274,7 @@ export function nativeSessionConfig(
|
|
|
263
274
|
description:
|
|
264
275
|
'Complete brief: objective, scope, constraints, verification, handoff.',
|
|
265
276
|
},
|
|
266
|
-
model: { type: 'string', description: `Explicit runtime-prefixed model ID from the available catalog. Oracle: ${mapping.oracleModels.join(' or ')}.` },
|
|
277
|
+
model: { type: 'string', description: `Explicit runtime-prefixed model ID from the available catalog.${targets.includes('oracle') ? ` Oracle: ${mapping.oracleModels.join(' or ')}.` : ''}` },
|
|
267
278
|
thinking: { type: 'string', description: 'Effort supported by the selected model.' },
|
|
268
279
|
modelReason: { type: 'string', description: 'Why this model suits the task.' },
|
|
269
280
|
mode: {
|
|
@@ -286,11 +297,11 @@ export function nativeSessionConfig(
|
|
|
286
297
|
},
|
|
287
298
|
]
|
|
288
299
|
: []),
|
|
289
|
-
...(targets.length ? [WAIT_TOOL, CANCEL_TOOL, MERGE_TOOL, DISCARD_TOOL, VERIFY_TOOL, RECALL_TOOL] : []),
|
|
300
|
+
...(targets.length ? [WAIT_TOOL, CANCEL_TOOL, MERGE_TOOL, DISCARD_TOOL, RESOLVE_TOOL, VERIFY_TOOL, RECALL_TOOL] : []),
|
|
290
301
|
...(targets.length || parentAgent ? [SEND_TOOL] : []),
|
|
291
302
|
...(parentAgent ? [HANDOFF_TOOL] : []),
|
|
292
|
-
...(supervised ? [LESSON_TOOL, SKILL_TOOL] : []),
|
|
293
|
-
...(!parentAgent && mapping.agent.name === mainOf(mapping) ? [ISSUE_TOOL] : []),
|
|
303
|
+
...(supervised ? [LESSON_TOOL, LESSON_CURATE_TOOL, SKILL_TOOL, SKILL_RETIRE_TOOL] : []),
|
|
304
|
+
...(!parentAgent && mapping.agent.name === mainOf(mapping) ? [ISSUE_TOOL, SCHEDULE_TOOL] : []),
|
|
294
305
|
ASK_TOOL,
|
|
295
306
|
PIN_TOOL,
|
|
296
307
|
BOARD_TOOL,
|
package/src/session-state.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { RuntimeTransport } from './contracts.js';
|
|
1
|
+
import type { NativeBase, RuntimeTransport } from './contracts.js';
|
|
2
2
|
import type { RuntimeKind, SessionSpec, ResolvedSession } from './resolve.js';
|
|
3
3
|
import type { MailEvent } from './mailbox.js';
|
|
4
4
|
import type { Worktree, WorktreeChange, Copy } from './workspace.js';
|
|
@@ -6,12 +6,20 @@ import type { Verification } from '@anhlp/alp-core/verify';
|
|
|
6
6
|
import type { Handoff } from './handoff.js';
|
|
7
7
|
import type { SessionUsage } from './events.js';
|
|
8
8
|
|
|
9
|
+
/** The pause that stopped a turn; a matching resume may arrive before its interruption settles. */
|
|
10
|
+
export type ParkPause = { scope: RuntimeKind | 'all'; resumed?: boolean; /** The pause was alpd's, for a full disk (t-2831). */ disk?: boolean };
|
|
11
|
+
export type Parked = { reason: string; since: number; prompt?: string; pause?: ParkPause };
|
|
12
|
+
|
|
9
13
|
export type Session = {
|
|
10
14
|
runtimeKind: RuntimeKind;
|
|
11
15
|
runtime: RuntimeTransport;
|
|
12
16
|
mapping: ResolvedSession;
|
|
13
17
|
threadId: string;
|
|
18
|
+
/** Claude: the conversation threadId is made from on its first prompt, until then (a fork or rewind, §12.7). */
|
|
19
|
+
base?: NativeBase;
|
|
14
20
|
active?: string;
|
|
21
|
+
/** A continued turn accepts a simultaneous user auto prompt as steering. */
|
|
22
|
+
resumedTurn?: string;
|
|
15
23
|
|
|
16
24
|
pending: boolean;
|
|
17
25
|
buffered: Array<[string, any]>;
|
|
@@ -32,19 +40,24 @@ export type Session = {
|
|
|
32
40
|
peerCount: number;
|
|
33
41
|
/** Live assignments this session requested, keyed by child session id. */
|
|
34
42
|
assignments: Map<string, Assignment>;
|
|
43
|
+
/** Root-tree implementation starts since the last new root user turn. */
|
|
35
44
|
calls: number;
|
|
45
|
+
/** Separate finite budget for mandatory read-only reviewer/oracle starts. */
|
|
46
|
+
advisorCalls: number;
|
|
36
47
|
|
|
37
48
|
mail: MailEvent[];
|
|
38
49
|
waiters: Waiter[];
|
|
39
50
|
lastActivity: number;
|
|
40
|
-
/** Auto-wakes since the last user prompt
|
|
51
|
+
/** Auto-wakes since the last user prompt or new result/question; check-ins do not count. */
|
|
41
52
|
wakes: number;
|
|
53
|
+
/** Failed wake starts since fresh result/question/check-in mail or a user prompt. */
|
|
54
|
+
wakeFailures: number;
|
|
42
55
|
/** When it last got a check-in, or when its assignments started running. */
|
|
43
56
|
checkInAt?: number;
|
|
44
57
|
/** Set by interrupt: pending mail waits for the next user prompt. */
|
|
45
58
|
wakeBlocked: boolean;
|
|
46
59
|
/** An assignment a usage limit or a pause stopped: it waits, open, until its runtime resumes. prompt is what continues it. */
|
|
47
|
-
parked?:
|
|
60
|
+
parked?: Parked;
|
|
48
61
|
/** What the requester of a session parked by its turn's end is told happens next, instead of waiting for alp resume. */
|
|
49
62
|
parkThen?: string;
|
|
50
63
|
/** When ALP restarted this session's native process, within the last RESTART_WINDOW_MS. */
|
|
@@ -57,14 +70,37 @@ export type Session = {
|
|
|
57
70
|
usage?: SessionUsage;
|
|
58
71
|
/** The context advisory was given since the context last emptied (ALPD §57). */
|
|
59
72
|
contextLevel?: number;
|
|
73
|
+
/** How full its context last was, 0..1 (t-0e56). */
|
|
74
|
+
contextFill?: number;
|
|
75
|
+
/** The user asked to compact it; done at the next turn boundary (t-0e56). */
|
|
76
|
+
compactRequested?: boolean;
|
|
77
|
+
/** A compaction in progress (t-0e56): main writing its checkpoint, then the runtime compacting. */
|
|
78
|
+
compacting?: { phase: 'checkpoint' | 'native' | 'fresh'; trigger: 'auto' | 'manual'; checkpoint?: string; startedAt: number; /** Its checkpoint turn was started. */ turn?: boolean; /** The runtime took the native request. */ requested?: boolean };
|
|
79
|
+
/** Compacted since main's last turn began: usage reported meanwhile may still count the old context. */
|
|
80
|
+
compactCooling?: boolean;
|
|
81
|
+
/** When its last compaction failed: automatic ones wait COMPACT_RETRY_MS after it. */
|
|
82
|
+
compactFailedAt?: number;
|
|
83
|
+
/** The user's prompts held while it compacts, sent after (t-0e56). */
|
|
84
|
+
compactBuffer?: import('./contracts.js').PromptInput[];
|
|
85
|
+
/** The user's last message to it, seeded into a fresh conversation after a compaction (t-0e56). */
|
|
86
|
+
lastUserText?: string;
|
|
60
87
|
/** An assignment's brief as its requester gave it, repeated after a compaction. */
|
|
61
88
|
brief?: string;
|
|
62
89
|
/** The skills it has used, each logged once (ALPD §59). */
|
|
63
90
|
skillsUsed?: Set<string>;
|
|
91
|
+
/** Skill files beyond SKILL.md the session has read or run, as `<read|run>:<skill>/<relative path>` (skill-resource events). */
|
|
92
|
+
skillResourcesUsed?: Set<string>;
|
|
64
93
|
/** Why the running turn is being stopped, so its end parks the assignment instead of ending it. */
|
|
65
94
|
parkReason?: string;
|
|
95
|
+
parkPause?: ParkPause;
|
|
66
96
|
/** Mail arrived while its runtime was paused; it is delivered on resume. */
|
|
67
97
|
wakeHeld?: boolean;
|
|
98
|
+
/** How many lifecycle operations (a rewind) hold its wakes now; mail waits until the last releases (AlpRuntime.hold). */
|
|
99
|
+
lifecycleHolds?: number;
|
|
100
|
+
/** Its parked work was to continue during a lifecycle hold; it continues when the last hold releases. */
|
|
101
|
+
resumeHeld?: Parked;
|
|
102
|
+
/** An assignment opened but not yet sent its brief: mail waits and rides with the brief's turn. */
|
|
103
|
+
awaitingBrief?: boolean;
|
|
68
104
|
/** Permission questions to the user, one at a time. */
|
|
69
105
|
permissionQueue?: Promise<unknown>;
|
|
70
106
|
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import { simpleCommands, unwrapShell } from '@anhlp/alp-core/permissions';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Progressive-disclosure evidence (skill system v2): which of an agent's skill resources (files under
|
|
6
|
+
* references/, scripts/, assets/, templates/, data/) a tool call reads or runs. Only what the agent
|
|
7
|
+
* asked for counts, never what a tool printed, and only reading or running: writing a skill file,
|
|
8
|
+
* listing a directory or naming a path in some other command is not "opening it on demand".
|
|
9
|
+
*
|
|
10
|
+
* Every runtime reports a call as a command line (claude-transport, acp-transport, Codex):
|
|
11
|
+
* - a shell command (Bash, Codex, an ACP `execute`), possibly wrapped in `sh -c '…'`;
|
|
12
|
+
* - Claude's other tools as `Name {json input}`;
|
|
13
|
+
* - an ACP agent's other tools as `kind: title`.
|
|
14
|
+
*/
|
|
15
|
+
export type ResourceAction = 'read' | 'run';
|
|
16
|
+
export type ResourceUse = { skill: string; resource: string; action: ResourceAction };
|
|
17
|
+
|
|
18
|
+
const RESOURCE = '(?:references|scripts|assets|templates|data)/[\\w.@+-]+(?:/[\\w.@+-]+)*';
|
|
19
|
+
/** Programs that run their first file argument. */
|
|
20
|
+
const INTERPRETERS = new Set(['node', 'nodejs', 'deno', 'bun', 'tsx', 'ts-node', 'python', 'python3', 'py', 'bash', 'sh', 'zsh', 'dash', 'ruby', 'perl', 'pwsh', 'powershell']);
|
|
21
|
+
/** Programs that read their file arguments. */
|
|
22
|
+
const READERS = new Set(['cat', 'bat', 'less', 'more', 'head', 'tail', 'sed', 'awk', 'grep', 'rg', 'egrep', 'nl', 'wc', 'cut', 'sort', 'jq', 'diff', 'view', 'type', 'get-content']);
|
|
23
|
+
/** Words before the program that do not change what runs. */
|
|
24
|
+
const PREFIXES = new Set(['sudo', 'env', 'exec', 'time', 'command', 'nice', 'nohup']);
|
|
25
|
+
/** Claude tools that read the file they name, and the input fields that name it. */
|
|
26
|
+
const CLAUDE_READERS: Record<string, string[]> = { Read: ['file_path', 'path'], NotebookRead: ['notebook_path'], Grep: ['path'] };
|
|
27
|
+
|
|
28
|
+
const slash = (value: string) => value.replace(/\\\\/g, '/').replace(/\\/g, '/');
|
|
29
|
+
const words = (command: string) => [...command.matchAll(/"((?:[^"\\]|\\.)*)"|'([^']*)'|(\S+)/g)].map(match => match[1] ?? match[2] ?? match[3]);
|
|
30
|
+
|
|
31
|
+
/** Each path a command reads or runs, with what it does to it. */
|
|
32
|
+
export function pathActions(command: string): Array<{ file: string; action: ResourceAction }> {
|
|
33
|
+
const claude = /^([A-Z][A-Za-z]+) (\{[\s\S]*\})$/.exec(command);
|
|
34
|
+
if (claude) {
|
|
35
|
+
const fields = CLAUDE_READERS[claude[1]];
|
|
36
|
+
if (!fields) return [];
|
|
37
|
+
let input: Record<string, unknown> = {};
|
|
38
|
+
try { input = JSON.parse(claude[2]); } catch { return []; }
|
|
39
|
+
return fields.map(field => input[field]).filter((value): value is string => typeof value === 'string').map(file => ({ file, action: 'read' as const }));
|
|
40
|
+
}
|
|
41
|
+
const acp = /^(read|search|edit|delete|move|think|fetch|other): ([\s\S]*)$/.exec(command);
|
|
42
|
+
if (acp) return acp[1] === 'read' ? words(acp[2]).map(file => ({ file, action: 'read' as const })) : [];
|
|
43
|
+
const found: Array<{ file: string; action: ResourceAction }> = [];
|
|
44
|
+
for (const simple of simpleCommands(unwrapShell(command)) ?? [command]) {
|
|
45
|
+
const tokens = words(simple).filter(token => token !== undefined);
|
|
46
|
+
while (tokens.length && (/^\w+=/.test(tokens[0]) || PREFIXES.has(tokens[0]))) tokens.shift();
|
|
47
|
+
if (!tokens.length) continue;
|
|
48
|
+
const program = path.posix.basename(slash(tokens[0])).toLowerCase().replace(/\.exe$/, '');
|
|
49
|
+
const args = tokens.slice(1).filter(token => !token.startsWith('-'));
|
|
50
|
+
if (new RegExp(`/${RESOURCE}$`).test(slash(tokens[0]))) found.push({ file: tokens[0], action: 'run' });
|
|
51
|
+
else if (INTERPRETERS.has(program)) args.forEach((file, index) => found.push({ file, action: index === 0 ? 'run' : 'read' }));
|
|
52
|
+
else if (READERS.has(program)) args.forEach(file => found.push({ file, action: 'read' }));
|
|
53
|
+
}
|
|
54
|
+
return found;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* The resources of `skills` a command reads or runs: by the skill's own directory, or by Claude's
|
|
59
|
+
* plugin link to it (`<plugin>/skills/<name>/…`). A path in another skill directory is not this agent's.
|
|
60
|
+
*/
|
|
61
|
+
export function resourceUses(command: string, skills: Array<{ name: string; path: string }>): ResourceUse[] {
|
|
62
|
+
if (!command || !slash(command).includes('/skills/')) return [];
|
|
63
|
+
const escape = (value: string) => value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
64
|
+
const uses: ResourceUse[] = [];
|
|
65
|
+
for (const { file, action } of pathActions(command)) {
|
|
66
|
+
const normal = slash(file);
|
|
67
|
+
for (const skill of skills) {
|
|
68
|
+
const match = new RegExp(`(?:^|/)(?:${escape(slash(path.dirname(skill.path)).replace(/^\//, ''))}|skills/${escape(skill.name)})/(${RESOURCE})$`).exec(normal.replace(/^\//, ''));
|
|
69
|
+
if (match) uses.push({ skill: skill.name, resource: match[1], action });
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return uses;
|
|
73
|
+
}
|
package/src/tool-detail.ts
CHANGED
|
@@ -327,7 +327,10 @@ export type CodexToolCall = { name: string; status: 'running' | 'completed' | 'f
|
|
|
327
327
|
/** `--- a/<path>` / `+++ b/<path>` headers on a file's diff that lacks them. */
|
|
328
328
|
function withHeaders(path: string, diff: string) {
|
|
329
329
|
// Only a diff that starts with its header has one: a removed `-- x` line inside is not it.
|
|
330
|
-
|
|
330
|
+
if (/^(--- |diff --git )/.test(diff)) return diff;
|
|
331
|
+
// A diff that starts with its target header lacks only the source one (#117).
|
|
332
|
+
if (diff.startsWith('+++ ')) return `--- a/${path}\n${diff}`;
|
|
333
|
+
return `--- a/${path}\n+++ b/${path}\n${diff}`;
|
|
331
334
|
}
|
|
332
335
|
|
|
333
336
|
/** Text that starts as a unified diff does: a file header or a hunk (a line inside content does not count). */
|
package/src/tools.ts
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import { CLOSE_REASONS, GATE_KINDS, TASK_STATUSES, TASK_TYPES, TASKS_DIR, type Task } from '@anhlp/alp-core/tasks';
|
|
2
2
|
import { READ_ONLY_AGENTS, type ResolvedSession } from './resolve.js';
|
|
3
|
+
import { READ_ONLY_ROLES } from '@anhlp/alp-core/permissions';
|
|
3
4
|
|
|
4
|
-
import { PIN_KINDS } from './board.js';
|
|
5
|
+
import { PIN_KINDS, PIN_PATH_CHARS, PIN_PATHS } from './board.js';
|
|
6
|
+
import { POUR_VARS } from './input-limits.js';
|
|
5
7
|
import { RECALL_KEEP_MS } from './recall.js';
|
|
8
|
+
import { RESULT_OUTCOMES } from './assignment-results.js';
|
|
6
9
|
import { HANDOFF_OUTCOMES, VERDICT_RESULTS, CRITERION_RESULTS, SEVERITIES } from './handoff.js';
|
|
7
10
|
|
|
8
11
|
export const handoffList = (description: string) => ({ type: 'array', items: { type: 'string' }, description });
|
|
@@ -67,7 +70,7 @@ export const HANDOFF_TOOL = {
|
|
|
67
70
|
export const WAIT_TOOL = {
|
|
68
71
|
type: 'function',
|
|
69
72
|
name: 'alp_wait',
|
|
70
|
-
description: 'Wait for mail from your assignments: results, questions, notes, and stall reports. Returns as soon as any arrives, or with an empty list and a status snapshot
|
|
73
|
+
description: 'Wait for mail from your assignments: results, questions, notes, and stall reports. Returns as soon as any arrives, a check-in comes or the user writes to you; otherwise with an empty list and a status snapshot after timeoutMs (default 5 minutes, at most 15). Ending your turn instead never cancels your assignments.',
|
|
71
74
|
inputSchema: {
|
|
72
75
|
type: 'object',
|
|
73
76
|
properties: {
|
|
@@ -133,6 +136,22 @@ export const DISCARD_TOOL = {
|
|
|
133
136
|
},
|
|
134
137
|
};
|
|
135
138
|
|
|
139
|
+
export const RESOLVE_TOOL = {
|
|
140
|
+
type: 'function',
|
|
141
|
+
name: 'alp_resolve',
|
|
142
|
+
description: "Record how you handled a finished writer's change in your checkout: applied (you kept or committed it), discarded (you reverted it) or acknowledged (you reviewed it; nothing to do). Until then ALP keeps its result and will not let that checkout be removed; then it archives the result.",
|
|
143
|
+
inputSchema: {
|
|
144
|
+
type: 'object',
|
|
145
|
+
properties: {
|
|
146
|
+
assignmentId: { type: 'string' },
|
|
147
|
+
outcome: { type: 'string', enum: RESULT_OUTCOMES },
|
|
148
|
+
note: { type: 'string', description: 'What you did with it, for the archive and the run log.' },
|
|
149
|
+
},
|
|
150
|
+
required: ['assignmentId', 'outcome'],
|
|
151
|
+
additionalProperties: false,
|
|
152
|
+
},
|
|
153
|
+
};
|
|
154
|
+
|
|
136
155
|
export const CANCEL_TOOL = {
|
|
137
156
|
type: 'function',
|
|
138
157
|
name: 'alp_cancel',
|
|
@@ -173,7 +192,7 @@ export const PIN_TOOL = {
|
|
|
173
192
|
properties: {
|
|
174
193
|
kind: { type: 'string', enum: PIN_KINDS },
|
|
175
194
|
body: { type: 'string', description: 'For a claim, what you are changing; otherwise the decision or finding itself.' },
|
|
176
|
-
paths: { type: 'array', items: { type: 'string' }, description:
|
|
195
|
+
paths: { type: 'array', items: { type: 'string', maxLength: PIN_PATH_CHARS }, maxItems: PIN_PATHS, description: `Project-relative files or directories, at most ${PIN_PATHS}. Required for a claim.` },
|
|
177
196
|
},
|
|
178
197
|
required: ['kind', 'body'],
|
|
179
198
|
additionalProperties: false,
|
|
@@ -187,7 +206,7 @@ export const BOARD_TOOL = {
|
|
|
187
206
|
inputSchema: {
|
|
188
207
|
type: 'object',
|
|
189
208
|
properties: {
|
|
190
|
-
kinds: { type: 'array', items: { type: 'string', enum: PIN_KINDS } },
|
|
209
|
+
kinds: { type: 'array', items: { type: 'string', enum: PIN_KINDS }, maxItems: PIN_KINDS.length },
|
|
191
210
|
limit: { type: 'integer', description: 'Most recent decisions and findings to return. Default 30.' },
|
|
192
211
|
},
|
|
193
212
|
additionalProperties: false,
|
|
@@ -209,7 +228,7 @@ export const UNPIN_TOOL = {
|
|
|
209
228
|
export const ASK_TOOL = {
|
|
210
229
|
type: 'function',
|
|
211
230
|
name: 'alp_ask',
|
|
212
|
-
description: 'Ask a question and wait for the answer: your requester, or the user. Only main talks to the user, unless the user has written to you.
|
|
231
|
+
description: 'Ask a question and wait for the answer: your requester, or the user. Only main talks to the user, unless the user has written to you. Holds your turn until answered; returns unanswered after the ask timeout (15 minutes for a requester, 30 for the user), and user_wrote when the user writes in the chat instead of answering.',
|
|
213
232
|
inputSchema: {
|
|
214
233
|
type: 'object',
|
|
215
234
|
properties: {
|
|
@@ -237,10 +256,39 @@ export const LESSON_TOOL = {
|
|
|
237
256
|
},
|
|
238
257
|
};
|
|
239
258
|
|
|
259
|
+
export const LESSON_CURATE_TOOL = {
|
|
260
|
+
type: 'function',
|
|
261
|
+
name: 'alp_lesson_curate',
|
|
262
|
+
description: 'Merge, shorten or remove recorded lessons. Each change removes the exact text of lessons from one scope and may add one rule in their place (a merge or a shortening); a change without add removes them. ALP shows every change to the user at once and applies them only when the user approves. Returns pending_approval with approvalId immediately; the result (applied, lessons not found, or the user\'s feedback) arrives once by mail. Never edit lessons files any other way.',
|
|
263
|
+
inputSchema: {
|
|
264
|
+
type: 'object',
|
|
265
|
+
properties: {
|
|
266
|
+
changes: {
|
|
267
|
+
type: 'array',
|
|
268
|
+
description: 'At most 50 changes.',
|
|
269
|
+
items: {
|
|
270
|
+
type: 'object',
|
|
271
|
+
properties: {
|
|
272
|
+
scope: { type: 'string', enum: ['project', 'user'] },
|
|
273
|
+
remove: { type: 'array', items: { type: 'string' }, description: 'The exact text of each lesson to remove, with or without its date.' },
|
|
274
|
+
add: { type: 'string', description: 'One rule, at most 600 characters, that replaces them.' },
|
|
275
|
+
reason: { type: 'string', description: 'Why, in one line.' },
|
|
276
|
+
},
|
|
277
|
+
required: ['scope', 'remove'],
|
|
278
|
+
additionalProperties: false,
|
|
279
|
+
},
|
|
280
|
+
},
|
|
281
|
+
requestId: { type: 'string', description: 'Optional session-scoped idempotency key (1-100 characters).' },
|
|
282
|
+
},
|
|
283
|
+
required: ['changes'],
|
|
284
|
+
additionalProperties: false,
|
|
285
|
+
},
|
|
286
|
+
};
|
|
287
|
+
|
|
240
288
|
export const SKILL_TOOL = {
|
|
241
289
|
type: 'function',
|
|
242
290
|
name: 'alp_skill',
|
|
243
|
-
description: 'Propose a skill distilled from your lessons. ALP shows the whole skill to the user, and saves it to the user\'s skill library and gives it to the roles only when the user approves;
|
|
291
|
+
description: 'Propose a skill distilled from your lessons. ALP shows the whole skill to the user, and saves it to the user\'s skill library and gives it to the roles only when the user approves. Returns pending_approval with approvalId immediately; the decision (saved, or not saved with the user\'s feedback) arrives once by mail, even after your turn ends. Continue other work. A retry of the same draft returns its existing pending/result in this session; use a fresh requestId only to propose an identical draft again.',
|
|
244
292
|
inputSchema: {
|
|
245
293
|
type: 'object',
|
|
246
294
|
properties: {
|
|
@@ -250,16 +298,33 @@ export const SKILL_TOOL = {
|
|
|
250
298
|
roles: { type: 'array', items: { type: 'string' }, description: 'The roles whose work the skill guides, and only those: any of main (yourself), lead, peer, oracle, reviewer, supervisor, or a custom agent of this project.' },
|
|
251
299
|
lessons: { type: 'array', items: { type: 'string' }, description: 'The exact text of the lessons this skill replaces; they leave the lessons files once it is saved.' },
|
|
252
300
|
replace: { type: 'boolean', description: 'Propose a new version of an existing skill of this name.' },
|
|
301
|
+
requestId: { type: 'string', description: 'Optional session-scoped idempotency key (1-100 characters). Reuse with the same draft on retries; a fresh key explicitly proposes a new operation.' },
|
|
253
302
|
},
|
|
254
303
|
required: ['name', 'description', 'body', 'roles'],
|
|
255
304
|
additionalProperties: false,
|
|
256
305
|
},
|
|
257
306
|
};
|
|
258
307
|
|
|
308
|
+
export const SKILL_RETIRE_TOOL = {
|
|
309
|
+
type: 'function',
|
|
310
|
+
name: 'alp_skill_retire',
|
|
311
|
+
description: 'Propose to retire a skill of the user\'s skill library that is no longer needed. ALP shows the skill and the roles that lose it to the user, and only when the user approves moves it out of the library into retired-skills (kept, so it can be restored) and removes it from role-skills.json. Nothing changes without that approval. Returns pending_approval with approvalId immediately; the result arrives once by mail. Never delete skill files any other way.',
|
|
312
|
+
inputSchema: {
|
|
313
|
+
type: 'object',
|
|
314
|
+
properties: {
|
|
315
|
+
name: { type: 'string', description: 'The skill directory name in the library.' },
|
|
316
|
+
reason: { type: 'string', description: 'Why it is no longer needed, in one line (at most 300 characters).' },
|
|
317
|
+
requestId: { type: 'string', description: 'Optional session-scoped idempotency key (1-100 characters).' },
|
|
318
|
+
},
|
|
319
|
+
required: ['name', 'reason'],
|
|
320
|
+
additionalProperties: false,
|
|
321
|
+
},
|
|
322
|
+
};
|
|
323
|
+
|
|
259
324
|
export const ISSUE_TOOL = {
|
|
260
325
|
type: 'function',
|
|
261
326
|
name: 'alp_issue',
|
|
262
|
-
description: 'GitHub issues of this project (target project, from its origin remote) or of ALP itself (target alp). search needs no approval. create and comment show the whole draft to the user and post it only when the user approves;
|
|
327
|
+
description: 'GitHub issues of this project (target project, from its origin remote) or of ALP itself (target alp). search needs no approval. create and comment show the whole draft to the user and post it only when the user approves; create/comment return pending_approval with approvalId immediately, then send one decision/posting result by mail, even after your turn ends. Continue other work. Draft retries return the existing pending/result in this session. Use a fresh requestId only to intentionally propose an identical draft again; reuse one requestId with the exact draft to replay safely.',
|
|
263
328
|
inputSchema: {
|
|
264
329
|
type: 'object',
|
|
265
330
|
properties: {
|
|
@@ -269,6 +334,7 @@ export const ISSUE_TOOL = {
|
|
|
269
334
|
title: { type: 'string', description: 'For create.' },
|
|
270
335
|
body: { type: 'string', description: 'For create and comment: Markdown. Facts, reproduction and evidence; no secrets.' },
|
|
271
336
|
issue: { type: 'integer', description: 'For comment: the issue number.' },
|
|
337
|
+
requestId: { type: 'string', description: 'Optional session-scoped idempotency key (1-100 characters). Reuse with the same draft on retries; a fresh key explicitly proposes a new operation.' },
|
|
272
338
|
labels: { type: 'array', items: { type: 'string' }, description: 'For create: existing labels of the repository.' },
|
|
273
339
|
},
|
|
274
340
|
required: ['action', 'target'],
|
|
@@ -286,7 +352,7 @@ export const TASK_FIELDS: Record<TaskAction, string[]> = {
|
|
|
286
352
|
start: ['id'],
|
|
287
353
|
close: ['id', 'reason', 'summary', 'unverified'],
|
|
288
354
|
reopen: ['id', 'note'],
|
|
289
|
-
gate: ['id', 'kind', 'note', 'until', 'ref'],
|
|
355
|
+
gate: ['id', 'kind', 'note', 'until', 'ref', 'options'],
|
|
290
356
|
clear: ['id', 'gate', 'note'],
|
|
291
357
|
pour: ['formula', 'vars', 'parent'],
|
|
292
358
|
formulas: [],
|
|
@@ -302,11 +368,15 @@ export const mainOf = (mapping: Pick<ResolvedSession, 'team'>) => mapping.team?.
|
|
|
302
368
|
export const roleOf = (mapping: Pick<ResolvedSession, 'team'>, agent: string) =>
|
|
303
369
|
mapping.team ? mapping.team.members[agent]?.role : ({ lead: 'lead', peer: 'peer', oracle: 'advisor', reviewer: 'reviewer' } as Record<string, string>)[agent];
|
|
304
370
|
|
|
371
|
+
/** Whether an agent is read-only in this session's team: a built-in advisor, or a member serving as advisor or reviewer. */
|
|
372
|
+
export const readOnlyMember = (mapping: Pick<ResolvedSession, 'team'>, agent: string) =>
|
|
373
|
+
READ_ONLY_AGENTS.includes(agent) || READ_ONLY_ROLES.includes(roleOf(mapping, agent) ?? '');
|
|
374
|
+
|
|
305
375
|
/** What each role may do with the task graph: main changes it, the others read it. */
|
|
306
376
|
export function taskActions(mapping: Pick<ResolvedSession, 'agent' | 'team'>, parentAgent?: string, role?: 'supervisor'): TaskAction[] {
|
|
307
377
|
if (role === 'supervisor') return ['show', 'list'];
|
|
308
378
|
if (!parentAgent && mapping.agent.name === mainOf(mapping)) return [...TASK_ACTIONS];
|
|
309
|
-
return
|
|
379
|
+
return readOnlyMember(mapping, mapping.agent.name) ? ['show'] : ['show', 'ready'];
|
|
310
380
|
}
|
|
311
381
|
|
|
312
382
|
export const taskLinks = (description: string) => ({
|
|
@@ -349,9 +419,10 @@ export function taskTool(actions: TaskAction[]) {
|
|
|
349
419
|
kind: { type: 'string', enum: GATE_KINDS, description: 'For gate: human (the user approves; give the question as note), timer (until), gh:pr (until a pull request merges; ref), gh:run (until a workflow run succeeds; ref).' },
|
|
350
420
|
until: { type: 'string', description: 'For a timer gate: an ISO time, or +30m, +2h, +3d.' },
|
|
351
421
|
ref: { type: 'string', description: 'For a gh:pr or gh:run gate: 123, or owner/repo#123.' },
|
|
422
|
+
options: { type: 'array', items: { type: 'string', maxLength: 200 }, maxItems: 10, description: 'For a human gate: up to 10 answers the user picks from, each at most 200 characters; picking any approves it, and you get the choice by mail. Default approve or reject.' },
|
|
352
423
|
gate: { type: 'string', description: 'For clear: the gate id, such as g1. You cannot clear a human gate; the user does.' },
|
|
353
424
|
formula: { type: 'string', description: 'For pour: the formula name, from action formulas.' },
|
|
354
|
-
vars: { type: 'object', additionalProperties: { type: 'string' }, description:
|
|
425
|
+
vars: { type: 'object', additionalProperties: { type: 'string', maxLength: POUR_VARS.string }, description: `For pour: values of the formula variables (at most ${POUR_VARS.items}), each at most ${POUR_VARS.string} characters.` },
|
|
355
426
|
summary: { type: 'string', description: 'For close: the outcome and its evidence.' },
|
|
356
427
|
unverified: { type: 'string', description: "For close as done when the task's last verification failed: why it is done anyway. Recorded on the task." },
|
|
357
428
|
note: { type: 'string', description: 'For update and reopen: why.' },
|
|
@@ -377,3 +448,19 @@ export function taskBrief(task: Task, writing: boolean) {
|
|
|
377
448
|
'Your handoff moves this task to review for your requester to accept. List work you found outside the task under discovered; only main and the user create tasks.',
|
|
378
449
|
].join('\n');
|
|
379
450
|
}
|
|
451
|
+
|
|
452
|
+
/** Only the project's main root may schedule a future continuation. */
|
|
453
|
+
export const SCHEDULE_TOOL = {
|
|
454
|
+
type: 'function', name: 'alp_schedule',
|
|
455
|
+
description: 'Create, list, inspect or cancel a one-shot continuation of this main/root session. create proposes the exact prompt and ISO time with UTC offset for user approval. Jobs wake an idle main without a user message; timer gates only unblock tasks, and assignment notes do not schedule a wake. Scheduling a quota-reset continuation never guarantees provider availability: recheck actual availability before delegating.',
|
|
456
|
+
inputSchema: {
|
|
457
|
+
type: 'object', properties: {
|
|
458
|
+
action: { type: 'string', enum: ['create', 'list', 'get', 'cancel'] },
|
|
459
|
+
dueAt: { type: 'string', description: 'For create: ISO timestamp with Z or an explicit UTC offset.' },
|
|
460
|
+
prompt: { type: 'string', description: 'For create: the exact continuation, at most 8000 characters.' },
|
|
461
|
+
requestId: { type: 'string', description: 'For create: stable id for this approval proposal; reuse only for an identical draft.' },
|
|
462
|
+
id: { type: 'string', description: 'For get/cancel: the scheduled job id.' },
|
|
463
|
+
status: { type: 'string', enum: ['pending', 'delivered', 'failed', 'cancelled'] },
|
|
464
|
+
}, required: ['action'], additionalProperties: false,
|
|
465
|
+
},
|
|
466
|
+
};
|
package/src/transport.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { optionalRead, codexUsage } from './runtime-context.js';
|
|
2
2
|
import { spawn, execFile, type ChildProcessWithoutNullStreams } from 'node:child_process';
|
|
3
3
|
import { createInterface } from 'node:readline';
|
|
4
|
+
import { scriptCommand } from '@anhlp/alp-core/packaged';
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* A request that was written but never answered: the process died, timed out or closed, so
|
|
@@ -25,7 +26,8 @@ export class CodexTransport {
|
|
|
25
26
|
if (/\.(cmd|bat|ps1)$/i.test(command)) throw new Error('Codex executable must be a native binary, not a shell launcher');
|
|
26
27
|
// Windows cannot exec a script by its shebang; a JavaScript command (the fake Codex of the tests) runs under this Node, still without a shell.
|
|
27
28
|
const script = process.platform === 'win32' && /\.[cm]?js$/i.test(command);
|
|
28
|
-
|
|
29
|
+
const run = script ? scriptCommand(command, args) : { command, args, env: undefined };
|
|
30
|
+
this.child = spawn(run.command, run.args, { cwd, env: run.env ? { ...env, ...run.env } : env, windowsHide: true, stdio: ['pipe', 'pipe', 'pipe'] });
|
|
29
31
|
this.exit = new Promise(resolve => { this.child.once('close', resolve); this.child.once('error', () => resolve()); });
|
|
30
32
|
// Drain diagnostics without writing credentials or user configuration to the host log.
|
|
31
33
|
this.child.stderr.on('data', () => {});
|