@anhlp/alp-runtime 0.0.1-beta.7 → 0.0.1-beta.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/acp-transport.js +2 -0
- package/dist/antigravity-transport.d.ts +10 -2
- package/dist/antigravity-transport.js +26 -4
- package/dist/assignment-results.d.ts +5 -2
- package/dist/assignment-results.js +27 -15
- package/dist/catalog.js +2 -1
- package/dist/claude-transport.d.ts +33 -2
- package/dist/claude-transport.js +48 -9
- package/dist/contracts.d.ts +12 -1
- package/dist/index.d.ts +4 -3
- package/dist/index.js +9 -2
- package/dist/language.d.ts +2 -0
- package/dist/language.js +6 -0
- package/dist/live.d.ts +2 -2
- package/dist/live.js +7 -2
- package/dist/model-catalog.d.ts +87 -1
- package/dist/model-catalog.js +151 -6
- package/dist/model-probes.d.ts +1 -1
- package/dist/model-probes.js +2 -2
- package/dist/recall.d.ts +2 -2
- package/dist/recall.js +4 -3
- package/dist/resolve.js +4 -4
- package/dist/runtime.js +243 -33
- package/dist/session-config.d.ts +75 -6
- package/dist/session-config.js +9 -5
- package/dist/session-state.d.ts +2 -0
- package/dist/skill-resources.d.ts +30 -0
- package/dist/skill-resources.js +55 -0
- package/dist/tools.d.ts +27 -1
- package/dist/tools.js +20 -1
- package/dist/write-error.d.ts +2 -0
- package/dist/write-error.js +10 -0
- package/package.json +4 -4
- package/src/acp-transport.ts +3 -0
- package/src/antigravity-transport.ts +39 -8
- package/src/assignment-results.ts +23 -15
- package/src/catalog.ts +3 -1
- package/src/claude-transport.ts +87 -10
- package/src/contracts.ts +12 -0
- package/src/index.ts +4 -3
- package/src/language.ts +10 -0
- package/src/live.ts +7 -3
- package/src/model-catalog.ts +156 -6
- package/src/model-probes.ts +2 -2
- package/src/recall.ts +4 -3
- package/src/resolve.ts +9 -5
- package/src/runtime.ts +255 -29
- package/src/session-config.ts +13 -5
- package/src/session-state.ts +2 -0
- package/src/skill-resources.ts +73 -0
- package/src/tools.ts +22 -1
- package/src/write-error.ts +4 -0
|
@@ -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) => ({
|