@anhlp/alp-runtime 0.0.1-beta.6 → 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 +42 -0
- package/dist/claude-transport.js +52 -2
- package/dist/contracts.d.ts +23 -1
- package/dist/index.d.ts +5 -4
- 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.d.ts +1 -0
- package/dist/resolve.js +6 -4
- package/dist/runtime.js +258 -34
- 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 +85 -5
- package/src/contracts.ts +19 -0
- package/src/index.ts +5 -4
- 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 +11 -5
- package/src/runtime.ts +277 -30
- 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/src/session-config.ts
CHANGED
|
@@ -6,7 +6,7 @@ import { models, thinkingOptionsFor } from './catalog.js';
|
|
|
6
6
|
import { claudeSandboxAvailable, SKILL_PLUGIN } from './claude-transport.js';
|
|
7
7
|
import { languageInstruction } from './language.js';
|
|
8
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, ISSUE_TOOL, SCHEDULE_TOOL, mainOf, taskActions, taskTool } from './tools.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';
|
|
10
10
|
|
|
11
11
|
import { COMPACT_SHARE } from './runtime-context.js';
|
|
12
12
|
|
|
@@ -83,7 +83,7 @@ export function modelProfileNote(mapping: ResolvedSession, targets: string[]) {
|
|
|
83
83
|
const options = (profile: import('@anhlp/alp-core/types').AgentModelConfig) => anyModel(profile)
|
|
84
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('; ')}`
|
|
85
85
|
: option(profileModel(profile)!, profile.effort);
|
|
86
|
-
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. ' +
|
|
87
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('. ') + '.'];
|
|
88
88
|
}
|
|
89
89
|
|
|
@@ -193,7 +193,15 @@ export function nativeSessionConfig(
|
|
|
193
193
|
...modelProfileNote(mapping, targets),
|
|
194
194
|
// The team's house rules (ALPD §42); Phở and Cafe's are the text this line held before teams.
|
|
195
195
|
`Profile: ${mapping.workflow.mode}; fixed for this session.${mapping.houseRules ? ` ${mapping.houseRules}` : ''}`,
|
|
196
|
-
|
|
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(' '),
|
|
197
205
|
...(supervised
|
|
198
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. ' +
|
|
199
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.']
|
|
@@ -266,7 +274,7 @@ export function nativeSessionConfig(
|
|
|
266
274
|
description:
|
|
267
275
|
'Complete brief: objective, scope, constraints, verification, handoff.',
|
|
268
276
|
},
|
|
269
|
-
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 ')}.` : ''}` },
|
|
270
278
|
thinking: { type: 'string', description: 'Effort supported by the selected model.' },
|
|
271
279
|
modelReason: { type: 'string', description: 'Why this model suits the task.' },
|
|
272
280
|
mode: {
|
|
@@ -292,7 +300,7 @@ export function nativeSessionConfig(
|
|
|
292
300
|
...(targets.length ? [WAIT_TOOL, CANCEL_TOOL, MERGE_TOOL, DISCARD_TOOL, RESOLVE_TOOL, VERIFY_TOOL, RECALL_TOOL] : []),
|
|
293
301
|
...(targets.length || parentAgent ? [SEND_TOOL] : []),
|
|
294
302
|
...(parentAgent ? [HANDOFF_TOOL] : []),
|
|
295
|
-
...(supervised ? [LESSON_TOOL, LESSON_CURATE_TOOL, SKILL_TOOL] : []),
|
|
303
|
+
...(supervised ? [LESSON_TOOL, LESSON_CURATE_TOOL, SKILL_TOOL, SKILL_RETIRE_TOOL] : []),
|
|
296
304
|
...(!parentAgent && mapping.agent.name === mainOf(mapping) ? [ISSUE_TOOL, SCHEDULE_TOOL] : []),
|
|
297
305
|
ASK_TOOL,
|
|
298
306
|
PIN_TOOL,
|
package/src/session-state.ts
CHANGED
|
@@ -88,6 +88,8 @@ export type Session = {
|
|
|
88
88
|
brief?: string;
|
|
89
89
|
/** The skills it has used, each logged once (ALPD §59). */
|
|
90
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>;
|
|
91
93
|
/** Why the running turn is being stopped, so its end parks the assignment instead of ending it. */
|
|
92
94
|
parkReason?: string;
|
|
93
95
|
parkPause?: ParkPause;
|
|
@@ -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/tools.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
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
5
|
import { PIN_KINDS, PIN_PATH_CHARS, PIN_PATHS } from './board.js';
|
|
5
6
|
import { POUR_VARS } from './input-limits.js';
|
|
@@ -304,6 +305,22 @@ export const SKILL_TOOL = {
|
|
|
304
305
|
},
|
|
305
306
|
};
|
|
306
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
|
+
|
|
307
324
|
export const ISSUE_TOOL = {
|
|
308
325
|
type: 'function',
|
|
309
326
|
name: 'alp_issue',
|
|
@@ -351,11 +368,15 @@ export const mainOf = (mapping: Pick<ResolvedSession, 'team'>) => mapping.team?.
|
|
|
351
368
|
export const roleOf = (mapping: Pick<ResolvedSession, 'team'>, agent: string) =>
|
|
352
369
|
mapping.team ? mapping.team.members[agent]?.role : ({ lead: 'lead', peer: 'peer', oracle: 'advisor', reviewer: 'reviewer' } as Record<string, string>)[agent];
|
|
353
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
|
+
|
|
354
375
|
/** What each role may do with the task graph: main changes it, the others read it. */
|
|
355
376
|
export function taskActions(mapping: Pick<ResolvedSession, 'agent' | 'team'>, parentAgent?: string, role?: 'supervisor'): TaskAction[] {
|
|
356
377
|
if (role === 'supervisor') return ['show', 'list'];
|
|
357
378
|
if (!parentAgent && mapping.agent.name === mainOf(mapping)) return [...TASK_ACTIONS];
|
|
358
|
-
return
|
|
379
|
+
return readOnlyMember(mapping, mapping.agent.name) ? ['show'] : ['show', 'ready'];
|
|
359
380
|
}
|
|
360
381
|
|
|
361
382
|
export const taskLinks = (description: string) => ({
|