@stage-labs/metro 0.1.0-beta.327 → 0.1.0-beta.328
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/package.json +1 -1
- package/runtime/node_modules/@metro-labs/daemon/src/claude/memory.ts +1 -1
- package/runtime/node_modules/@metro-labs/daemon/src/claude/setup.ts +6 -2
- package/runtime/runtime.json +1 -1
- package/runtime/sdk-runner/runner.json +1 -1
- package/runtime/sdk-runner/src/app.ts +1 -1
- package/runtime/sdk-runner/src/runner.ts +19 -9
- package/runtime/sdk-runner/src/session-watch.ts +2 -2
- package/skills/METRO.md +2 -2
package/package.json
CHANGED
|
@@ -28,5 +28,5 @@ export function inSessionScope(command: [string, string[]], host: ScopeHost = re
|
|
|
28
28
|
const asAgent = file === 'sudo' && args[0] === '-n' && args[1] === '-u' && args[3] === '--';
|
|
29
29
|
if (!host.metro || !host.systemd || !asAgent) return command;
|
|
30
30
|
const limit = sessionMemoryLimit(host.total);
|
|
31
|
-
return helperArgv(['as-agent-scope', String(limit), String(
|
|
31
|
+
return helperArgv(['as-agent-scope', String(limit), String(limit), ...args.slice(4)]);
|
|
32
32
|
}
|
|
@@ -41,7 +41,7 @@ Keep the change to what the task asks for. A pre-existing bug, a performance pro
|
|
|
41
41
|
|
|
42
42
|
Never call AskUserQuestion or ExitPlanMode. They are blocked by policy, because nobody is watching the terminal around the clock and a blocking prompt stalls indefinitely. When you hit an ambiguity: do everything that does not depend on it, then choose the most reasonable interpretation, state the assumption explicitly in your report, and continue.
|
|
43
43
|
|
|
44
|
-
Your final message is a report to the orchestrator, not a message to a human. It
|
|
44
|
+
Your final message is a report to the orchestrator, not a message to a human. It stays in the orchestrator's context for the rest of the conversation and makes every later answer slower, so keep it short: about 150 words at most, self-contained. Lead with the outcome, then the key evidence for what you claim to have verified, such as the test result or the file you changed. Put anything longer, such as full logs, tables or detailed findings, in a file under ~/work and give its path. Report failures faithfully: if a test failed, say so with its key line of output; if you skipped a step, say that too.
|
|
45
45
|
`;
|
|
46
46
|
|
|
47
47
|
export interface SetupDeps {
|
|
@@ -129,7 +129,10 @@ export function setSystemPrompt(text: string, agents = agentsDir()): void {
|
|
|
129
129
|
writeAtomic(promptPath(agents), `${trimmed}\n`, 0o600);
|
|
130
130
|
}
|
|
131
131
|
|
|
132
|
-
const PRIOR_WORKER: ReadonlySet<string> = new Set([
|
|
132
|
+
const PRIOR_WORKER: ReadonlySet<string> = new Set([
|
|
133
|
+
'08a0cd8710df285d6512245246bb8b658b7cfc7f3e89490514ee5376779eb2ef',
|
|
134
|
+
'9db999a7bb7cf1d6c12a679520e21c78d038999d5454d7abbc6b87a87c136c54',
|
|
135
|
+
]);
|
|
133
136
|
const PRIOR_METRO: ReadonlySet<string> = new Set([
|
|
134
137
|
'0b3d122ed95beff09d579cf912cd4238e1db524c41fce4b314de57d6ff5908ad',
|
|
135
138
|
'36f4fb57f231a119d717b5e3d6ccb654f94960fcca708683f376679aead8df25',
|
|
@@ -142,6 +145,7 @@ const PRIOR_METRO: ReadonlySet<string> = new Set([
|
|
|
142
145
|
'256c711a6175266c216e32c88b7190d0f98f5e6b702abe03220b422aba426574',
|
|
143
146
|
'9e164a956437d60d30ea1984115a17d303940d191f5efed04954f244fc89d48f',
|
|
144
147
|
'8b6d7c5a9bc8d02d5e3ae5e5931b36aba9f3d0eb7fd38b371294c2abaa0c94ee',
|
|
148
|
+
'8b8f21cb1b7608540d8b5ed9557e1644b03ce4809a7f320ba134f28129f08ddb',
|
|
145
149
|
]);
|
|
146
150
|
const PRIOR_STAGE: ReadonlySet<string> = new Set([
|
|
147
151
|
'dd7d30474765de3865ddc87c1cf3220161ded09502027cdff18597e5df0aab43',
|
package/runtime/runtime.json
CHANGED
|
@@ -63,7 +63,7 @@ async function connected(cfg: RunnerConfig, hooks: AppHooks, release: () => Prom
|
|
|
63
63
|
tools = metroTools(link);
|
|
64
64
|
const resume = store.resumable();
|
|
65
65
|
log.info({ resume, model: cfg.model, mode: cfg.permissionMode }, 'sdk-runner: starting the Agent SDK session');
|
|
66
|
-
const approvals = approvalsThrough(link, (id, ask) => { hooks.activity?.approval(id, ask); }, (tool, input) => runner.calls.approval(tool, input));
|
|
66
|
+
const approvals = approvalsThrough(link, (id, ask) => { hooks.activity?.approval(id, ask); runner.approval(id, ask); }, (tool, input) => runner.calls.approval(tool, input));
|
|
67
67
|
runner.start(runnerOptions(cfg, tools, approvals, resume, hooks.env));
|
|
68
68
|
return { runner, link, done: runner.run(hooks.observe), stop };
|
|
69
69
|
} catch (err) {
|
|
@@ -7,7 +7,6 @@ import { isRecord } from '@metro-labs/core/is-record';
|
|
|
7
7
|
import type { AutomationStore } from '@metro-labs/core/automation-store';
|
|
8
8
|
import type { Activity } from './activity.js';
|
|
9
9
|
import { Automation } from './automation.js';
|
|
10
|
-
import { ActivityTasks } from './activity-tasks.js';
|
|
11
10
|
import { RunnerCalls } from './calls.js';
|
|
12
11
|
import { channelText, type ChannelEvent } from './channel-text.js';
|
|
13
12
|
import type { RunnerConfig } from './config.js';
|
|
@@ -21,7 +20,8 @@ import { METRO_SERVER, type MetroTools } from './tool-proxy.js';
|
|
|
21
20
|
import { debugFailure, failureSummary, SessionError, StartupDiagnostics } from './errors.js';
|
|
22
21
|
|
|
23
22
|
const STARTUP_WAIT = 'CLAUDE_CODE_MCP_STARTUP_WAIT_MS';
|
|
24
|
-
export const COMPACT_AT =
|
|
23
|
+
export const COMPACT_AT = 80_000;
|
|
24
|
+
const URGENT_FACTOR = 1.5;
|
|
25
25
|
export const COMPACT_IDLE_MS = 60_000;
|
|
26
26
|
|
|
27
27
|
const MODEL_PINS: ReadonlySet<string> = new Set(['ANTHROPIC_MODEL', 'CLAUDE_CODE_SUBAGENT_MODEL']);
|
|
@@ -97,7 +97,6 @@ export class Runner {
|
|
|
97
97
|
private readonly recovery: TaskRecovery;
|
|
98
98
|
private readonly watch: SessionWatch;
|
|
99
99
|
private readonly diagnostics = new StartupDiagnostics();
|
|
100
|
-
private readonly tasks = new ActivityTasks(() => undefined);
|
|
101
100
|
private readonly skillWork = new SkillWork();
|
|
102
101
|
private compactTimer: ReturnType<typeof setTimeout> | null = null;
|
|
103
102
|
private session: Query | null = null;
|
|
@@ -108,11 +107,12 @@ export class Runner {
|
|
|
108
107
|
private model: string | null = null;
|
|
109
108
|
private switching: Promise<void> = Promise.resolve();
|
|
110
109
|
private ended = false;
|
|
110
|
+
private readonly mainAsks = new Set<string>();
|
|
111
111
|
private readonly interrupted: number;
|
|
112
112
|
private interruptionReported = false;
|
|
113
113
|
|
|
114
114
|
constructor(private readonly parts: RunnerParts) {
|
|
115
|
-
this.watch = new SessionWatch(parts.readOnly);
|
|
115
|
+
this.watch = new SessionWatch(parts.readOnly, () => this.mainAsks.size > 0);
|
|
116
116
|
this.inbox = new Inbox((unanswered) => { this.keep(unanswered); }, {
|
|
117
117
|
ready: () => { parts.skills?.check(); return this.watch.admitting && parts.skills?.busy !== true; },
|
|
118
118
|
dispatch: (message) => { this.automation?.dispatched(message.uuid); this.watch.dispatched(message.uuid); },
|
|
@@ -167,6 +167,12 @@ export class Runner {
|
|
|
167
167
|
return this.session;
|
|
168
168
|
}
|
|
169
169
|
|
|
170
|
+
approval(id: string, ask: { worker: string | null } | null): void {
|
|
171
|
+
if (ask === null) this.mainAsks.delete(id);
|
|
172
|
+
else if (ask.worker === null) this.mainAsks.add(id);
|
|
173
|
+
this.inbox.notify();
|
|
174
|
+
}
|
|
175
|
+
|
|
170
176
|
switchModel(model: string | null): Promise<void> {
|
|
171
177
|
this.queueModel(model);
|
|
172
178
|
return this.switching;
|
|
@@ -178,7 +184,6 @@ export class Runner {
|
|
|
178
184
|
for await (const message of this.session) {
|
|
179
185
|
if (this.ended) break;
|
|
180
186
|
this.cancelCompact();
|
|
181
|
-
if (message.type === 'system') this.tasks.observe(message);
|
|
182
187
|
const m: Record<string, unknown> = { ...message };
|
|
183
188
|
this.recovery.observe(m);
|
|
184
189
|
this.automation?.observe(m);
|
|
@@ -186,8 +191,8 @@ export class Runner {
|
|
|
186
191
|
this.observeWork(m);
|
|
187
192
|
this.note(m);
|
|
188
193
|
this.parts.activity?.observe(message);
|
|
189
|
-
this.inbox.notify();
|
|
190
194
|
this.maybeCompact();
|
|
195
|
+
this.inbox.notify();
|
|
191
196
|
observe?.(message);
|
|
192
197
|
}
|
|
193
198
|
} catch (err) {
|
|
@@ -318,14 +323,19 @@ export class Runner {
|
|
|
318
323
|
return this.ended || this.parts.skills?.busy === true || this.compactAsked !== null || !this.watch.safe || !this.watch.admitting;
|
|
319
324
|
}
|
|
320
325
|
|
|
326
|
+
private get compactUrgent(): boolean {
|
|
327
|
+
return this.watch.context >= (this.parts.compactAt ?? COMPACT_AT) * URGENT_FACTOR;
|
|
328
|
+
}
|
|
329
|
+
|
|
321
330
|
private compactReady(resuming = false): boolean {
|
|
322
|
-
const
|
|
331
|
+
const waiting = this.inbox.pending > 0 && !this.compactUrgent;
|
|
332
|
+
const busy = this.maintenanceBusy || (!resuming && (this.calls.live || waiting));
|
|
323
333
|
return compactDue({ context: this.watch.context, floor: this.compactFloor, limit: this.parts.compactAt ?? COMPACT_AT, busy });
|
|
324
334
|
}
|
|
325
335
|
|
|
326
336
|
private maybeCompact(resuming = false): void {
|
|
327
337
|
if (!this.compactReady(resuming)) return;
|
|
328
|
-
if (resuming) { this.askCompact(
|
|
338
|
+
if (resuming || this.compactUrgent) { this.askCompact(resuming); return; }
|
|
329
339
|
this.compactTimer = setTimeout(() => {
|
|
330
340
|
this.compactTimer = null;
|
|
331
341
|
if (this.compactReady()) this.askCompact(false);
|
|
@@ -335,7 +345,7 @@ export class Runner {
|
|
|
335
345
|
|
|
336
346
|
private askCompact(resuming: boolean): void {
|
|
337
347
|
this.compactAsked = this.inbox.compact();
|
|
338
|
-
log.info({ context: this.watch.context, resuming }, 'sdk-runner: compacting at a safe
|
|
348
|
+
log.info({ context: this.watch.context, resuming, urgent: this.compactUrgent, waiting: this.inbox.pending }, 'sdk-runner: compacting at a safe boundary');
|
|
339
349
|
}
|
|
340
350
|
|
|
341
351
|
private cancelCompact(): void {
|
|
@@ -35,7 +35,7 @@ export class SessionWatch {
|
|
|
35
35
|
private lastContext = 0;
|
|
36
36
|
private streamUsage: Record<string, unknown> = {};
|
|
37
37
|
|
|
38
|
-
constructor(private readonly readOnly: (tool: string) => boolean) {}
|
|
38
|
+
constructor(private readonly readOnly: (tool: string) => boolean, private readonly mainAsking: () => boolean = () => true) {}
|
|
39
39
|
|
|
40
40
|
get compacting(): boolean {
|
|
41
41
|
return this.compactingNow;
|
|
@@ -52,7 +52,7 @@ export class SessionWatch {
|
|
|
52
52
|
get safe(): boolean { return !this.busy && !this.writing && !this.compacting; }
|
|
53
53
|
|
|
54
54
|
get admitting(): boolean {
|
|
55
|
-
return this.awaitingInput === null && !this.requiresAction && !this.compacting;
|
|
55
|
+
return this.awaitingInput === null && !(this.requiresAction && this.mainAsking()) && !this.compacting;
|
|
56
56
|
}
|
|
57
57
|
|
|
58
58
|
dispatched(uuid?: string): void {
|
package/skills/METRO.md
CHANGED
|
@@ -22,7 +22,7 @@ You are the main thread of a Claude Code session that is connected to chat throu
|
|
|
22
22
|
1. `tool_search` finds a tool and returns its full definition: `select:notion.search` for an exact name, words (`notion create page`) to rank, or `+linear issue` to require `linear` in the name. Each name is `<connector>.<tool>`.
|
|
23
23
|
2. `tool_call` runs it, with the name exactly as found and arguments that match its schema. After `tool_search` with `select:notion.search` returned `notion.search`: `{"calls": [{"tool": "notion.search", "arguments": {"query": "roadmap"}}]}`.
|
|
24
24
|
|
|
25
|
-
Put up to 10 independent calls in one `tool_call`; they run in parallel and come back in order, each under `[n] <tool>`.
|
|
25
|
+
Put up to 10 independent calls in one `tool_call`; they run in parallel and come back in order, each under `[n] <tool>`. Both steps run in a worker, never on this thread: `tool_search` answers carry full tool definitions, and anything on this thread stays in its context and slows every later answer. When a call answers `needs_approval`, the owner is asked in chat and on the page: tell the person what is waiting, then wait for the channel message `Approved: <tool> (<id>)` or `Denied: <tool> (<id>)`. After an approval, have a worker repeat the same call with `"approval": "<id>"` added to it.
|
|
26
26
|
|
|
27
27
|
**Finish what was asked.** You work on your own. Nobody is watching a screen, and a question sent to chat may go unanswered for hours, so asking "Shall I?" about work already requested simply stops it. Anything reversible that follows from the request, do. Stop only for a destructive action or a genuine change of scope. Before you end a turn, read your own last paragraph: if it is a plan, a question, a list of next steps or a promise ("I'll…", "Next…"), then the work is not done, so do it now, retries and missing information included. End the turn when the task is finished, or when you are truly blocked on something only the person can give you.
|
|
28
28
|
|
|
@@ -30,6 +30,6 @@ The exception is a person describing a problem, asking a question or thinking ou
|
|
|
30
30
|
|
|
31
31
|
**The whole request is the deliverable.** Do not quietly make it smaller, larger or different. Read an ambiguity the way a careful colleague would, make the ordinary judgement calls yourself, and name the assumption in your reply. If one part turns out to be blocked, finish every other part and say plainly what you left out and why: scaling the work down is the person's call, not yours. Something else you notice on the way is a suggestion at the end of the reply, not extra work to do now.
|
|
32
32
|
|
|
33
|
-
**Report like a relay.** A worker's report is the only evidence you have, so pass on what it verified and say plainly what it did not. Short messages on chat: lead with the outcome, one idea per sentence, no tool names, no file paths unless the person needs them. Send a file out with `create_upload` (the curl line it hands back runs in a worker) and then `send` with the upload id.
|
|
33
|
+
**Report like a relay.** A worker's report is the only evidence you have, so pass on what it verified and say plainly what it did not. Keep this thread small: ask workers for short reports, and give them file paths and details rather than pasting long text into their prompts. Short messages on chat: lead with the outcome, one idea per sentence, no tool names, no file paths unless the person needs them. Send a file out with `create_upload` (the curl line it hands back runs in a worker) and then `send` with the upload id.
|
|
34
34
|
|
|
35
35
|
**Keep going.** Long tasks run as background agents and loops; check in over chat when something lands rather than going quiet. The session is restarted by the daemon if it exits, so an interrupted task is resumed from chat, not from memory.
|