@nordhavnhq/runner 0.103.0 → 0.105.0
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/runtime/up.js +27 -8
- package/dist/tools/console.js +1 -1
- package/dist/tools/http.js +4 -4
- package/dist/version.json +3 -3
- package/node_modules/@nordhavnhq/runner-browser/dist/show.js +1 -1
- package/node_modules/@nordhavnhq/runner-browser/package.json +1 -1
- package/node_modules/@nordhavnhq/runner-runtime/dist/contract/batch.d.ts +7 -7
- package/node_modules/@nordhavnhq/runner-runtime/dist/contract/batch.js +16 -15
- package/node_modules/@nordhavnhq/runner-runtime/dist/contract/calls.d.ts +2 -2
- package/node_modules/@nordhavnhq/runner-runtime/dist/contract/calls.js +4 -3
- package/node_modules/@nordhavnhq/runner-runtime/dist/contract/loop.d.ts +17 -17
- package/node_modules/@nordhavnhq/runner-runtime/dist/contract/loop.js +35 -34
- package/node_modules/@nordhavnhq/runner-runtime/dist/contract/phases.d.ts +12 -12
- package/node_modules/@nordhavnhq/runner-runtime/dist/contract/phases.js +14 -13
- package/node_modules/@nordhavnhq/runner-runtime/dist/contract/pins.d.ts +3 -3
- package/node_modules/@nordhavnhq/runner-runtime/dist/contract/pins.js +9 -9
- package/node_modules/@nordhavnhq/runner-runtime/dist/contract/tool-names.d.ts +24 -5
- package/node_modules/@nordhavnhq/runner-runtime/dist/contract/tool-names.js +36 -9
- package/node_modules/@nordhavnhq/runner-runtime/dist/contract/version.d.ts +1 -1
- package/node_modules/@nordhavnhq/runner-runtime/dist/contract/version.js +1 -1
- package/node_modules/@nordhavnhq/runner-runtime/dist/contract/wire.d.ts +16 -8
- package/node_modules/@nordhavnhq/runner-runtime/dist/contract/wire.js +8 -0
- package/node_modules/@nordhavnhq/runner-runtime/dist/index.d.ts +1 -0
- package/node_modules/@nordhavnhq/runner-runtime/dist/index.js +1 -0
- package/node_modules/@nordhavnhq/runner-runtime/dist/runtime/auto-load.d.ts +3 -3
- package/node_modules/@nordhavnhq/runner-runtime/dist/runtime/auto-load.js +5 -4
- package/node_modules/@nordhavnhq/runner-runtime/dist/runtime/extract-json.d.ts +1 -1
- package/node_modules/@nordhavnhq/runner-runtime/dist/runtime/extract-json.js +1 -1
- package/node_modules/@nordhavnhq/runner-runtime/dist/runtime/handle-chat.js +6 -6
- package/node_modules/@nordhavnhq/runner-runtime/dist/runtime/handle-task.js +14 -14
- package/node_modules/@nordhavnhq/runner-runtime/dist/runtime/loop.d.ts +6 -6
- package/node_modules/@nordhavnhq/runner-runtime/dist/runtime/loop.js +12 -11
- package/node_modules/@nordhavnhq/runner-runtime/dist/runtime/phased-loop.js +2 -1
- package/node_modules/@nordhavnhq/runner-runtime/dist/runtime/run-tools.d.ts +1 -1
- package/node_modules/@nordhavnhq/runner-runtime/dist/runtime/run-tools.js +1 -1
- package/node_modules/@nordhavnhq/runner-runtime/dist/runtime/scratch-prompt.js +1 -1
- package/node_modules/@nordhavnhq/runner-runtime/dist/runtime/task-validation.d.ts +2 -2
- package/node_modules/@nordhavnhq/runner-runtime/dist/runtime/task-validation.js +2 -2
- package/node_modules/@nordhavnhq/runner-runtime/dist/runtime/unload-toolset.d.ts +5 -5
- package/node_modules/@nordhavnhq/runner-runtime/dist/runtime/unload-toolset.js +18 -17
- package/node_modules/@nordhavnhq/runner-runtime/dist/tools/delegate.d.ts +2 -2
- package/node_modules/@nordhavnhq/runner-runtime/dist/tools/delegate.js +3 -3
- package/node_modules/@nordhavnhq/runner-runtime/dist/tools/index.d.ts +3 -3
- package/node_modules/@nordhavnhq/runner-runtime/dist/tools/mcp.d.ts +1 -1
- package/node_modules/@nordhavnhq/runner-runtime/dist/tools/mcp.js +5 -4
- package/node_modules/@nordhavnhq/runner-runtime/package.json +1 -1
- package/package.json +3 -3
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* phases, each on the model that fits it.
|
|
5
5
|
*
|
|
6
6
|
* - PLAN, on the plan model: read and reproduce, change nothing, and end with
|
|
7
|
-
* `
|
|
7
|
+
* `os_submit_plan`. The studio stores the plan and the run goes on at
|
|
8
8
|
* once: it makes room in the budget for the estimate (up to the task's
|
|
9
9
|
* ceiling), and a schema migration only means the task ends in review.
|
|
10
10
|
* The plan phase has a ceiling of its own (`PLAN_MAX_ROUNDS`, nudged from
|
|
@@ -19,18 +19,18 @@
|
|
|
19
19
|
* switch is a new chain, never an edit of the old one (the transcript stays
|
|
20
20
|
* append-only within a chain, see loop.ts).
|
|
21
21
|
* - ESCALATED, on the plan model again, for a few rounds: asked for with
|
|
22
|
-
* `
|
|
22
|
+
* `os_escalate`, or on its own after two failing test runs in a row,
|
|
23
23
|
* `ESCALATE_AFTER_IDLE_ROUNDS` rounds without a file change, or a loop-guard
|
|
24
24
|
* trip. It ends with a short reply, and exec starts a fresh chain with it.
|
|
25
25
|
*
|
|
26
26
|
* Part of the agent contract (see `version.ts`), copied verbatim into the
|
|
27
27
|
* runner. The orchestration lives here, `runPhasedLoop`; each runtime hands in
|
|
28
28
|
* how ONE phase runs (its own loop, its own transport bound to the phase's
|
|
29
|
-
* slot), like `runBatch` takes how one call is made. No imports
|
|
30
|
-
* from loop.ts (the working-set ledger) is handed in too.
|
|
29
|
+
* slot), like `runBatch` takes how one call is made. No imports but the tool
|
|
30
|
+
* names: what it needs from loop.ts (the working-set ledger) is handed in too.
|
|
31
31
|
*/
|
|
32
|
-
export declare const SUBMIT_PLAN_TOOL
|
|
33
|
-
export declare const ESCALATE_TOOL
|
|
32
|
+
export declare const SUBMIT_PLAN_TOOL: "os_submit_plan";
|
|
33
|
+
export declare const ESCALATE_TOOL: "os_escalate";
|
|
34
34
|
/** The phase tools: offered only in a run with phases, handled by the loops. */
|
|
35
35
|
export declare const PHASE_TOOL_NAMES: ReadonlySet<string>;
|
|
36
36
|
/** A model the dispatch resolved for a phase (`resolveAgentSlotModel`). */
|
|
@@ -38,7 +38,7 @@ export interface PhaseModel {
|
|
|
38
38
|
aiProviderId: number;
|
|
39
39
|
model: string;
|
|
40
40
|
}
|
|
41
|
-
/** What `
|
|
41
|
+
/** What `os_submit_plan` takes, and what the exec phase starts from. */
|
|
42
42
|
export interface SubmittedPlan {
|
|
43
43
|
approach: string;
|
|
44
44
|
files: string[];
|
|
@@ -85,19 +85,19 @@ export declare const PLAN_PHASE_BLOCKED_TOOLS: ReadonlySet<string>;
|
|
|
85
85
|
export declare const PLAN_PHASE_BRIEF: string;
|
|
86
86
|
/** How the studio answers a plan that passed its gate; anything else is a gate that waits or a refusal. */
|
|
87
87
|
export declare const PLAN_PASSED_PREFIX = "Plan accepted.";
|
|
88
|
-
export declare const PLAN_NUDGE = "You are in the plan phase: submit your plan with `
|
|
88
|
+
export declare const PLAN_NUDGE = "You are in the plan phase: submit your plan with `os_submit_plan` to start the work. If nothing needs to change, reply once more with your proof and the run ends.";
|
|
89
89
|
/** What the planner is told as its rounds run out: after `PLAN_NUDGE_AFTER_ROUNDS`, and before its last one. */
|
|
90
90
|
export declare function planRoundsNudge(used: number, max: number): string;
|
|
91
91
|
export declare const EXEC_PHASE_BRIEF: string;
|
|
92
92
|
export declare function escalationBrief(reason: string): string;
|
|
93
93
|
/** Exec without a plan: the plan phase ran out of rounds before it submitted one. */
|
|
94
|
-
export declare const EXEC_WITHOUT_PLAN = "The plan phase ran out of rounds before it handed in a plan, so nobody checked one: find the change from what it found and read. When the change needs a database schema migration, ask a person with
|
|
94
|
+
export declare const EXEC_WITHOUT_PLAN = "The plan phase ran out of rounds before it handed in a plan, so nobody checked one: find the change from what it found and read. When the change needs a database schema migration, ask a person with os_ask before you make it.";
|
|
95
95
|
export declare const ESCALATION_ACK = "Escalated: after this round the planning model takes over on a fresh context with your reason, the plan and the files you worked with, and hands back what it found.";
|
|
96
|
-
export declare const ESCALATION_SPENT = "Not escalated: this run already escalated 2 times. Carry on with what you have, or ask a person with
|
|
96
|
+
export declare const ESCALATION_SPENT = "Not escalated: this run already escalated 2 times. Carry on with what you have, or ask a person with os_ask when only they can unblock you.";
|
|
97
97
|
export declare const ESCALATION_IN_ESCALATION = "You are the escalation: write your findings as a plain reply (no tool call) to hand back to the executor.";
|
|
98
98
|
export declare const PHASE_TOOL_NOT_HERE = "Not available in this phase.";
|
|
99
99
|
export declare function planPhaseRefusal(toolName: string): string;
|
|
100
|
-
/** The plan in a call's arguments, or what is wrong with it (`
|
|
100
|
+
/** The plan in a call's arguments, or what is wrong with it (`os_submit_plan`, both sides). */
|
|
101
101
|
export declare function readPlanArgs(raw: unknown): SubmittedPlan | string;
|
|
102
102
|
/** The plan as the exec phase and a person read it. */
|
|
103
103
|
export declare function renderPlan(plan: SubmittedPlan): string;
|
|
@@ -192,7 +192,7 @@ export interface PhasedLoopOpts<M extends PhaseMessage, R extends PhaseLoopResul
|
|
|
192
192
|
runPhase: (run: PhaseRun<M>) => Promise<R>;
|
|
193
193
|
/** Told when a phase starts (logging, activity). */
|
|
194
194
|
onPhase?: (phase: RunPhaseName, why: string) => void;
|
|
195
|
-
/** Loads tool groups into `registry` (`
|
|
195
|
+
/** Loads tool groups into `registry` (`os_load_toolset`): the plan's `toolGroups`, before the exec chain starts. */
|
|
196
196
|
loadToolGroups?: (groups: string[]) => Promise<void>;
|
|
197
197
|
}
|
|
198
198
|
/**
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* phases, each on the model that fits it.
|
|
5
5
|
*
|
|
6
6
|
* - PLAN, on the plan model: read and reproduce, change nothing, and end with
|
|
7
|
-
* `
|
|
7
|
+
* `os_submit_plan`. The studio stores the plan and the run goes on at
|
|
8
8
|
* once: it makes room in the budget for the estimate (up to the task's
|
|
9
9
|
* ceiling), and a schema migration only means the task ends in review.
|
|
10
10
|
* The plan phase has a ceiling of its own (`PLAN_MAX_ROUNDS`, nudged from
|
|
@@ -19,18 +19,19 @@
|
|
|
19
19
|
* switch is a new chain, never an edit of the old one (the transcript stays
|
|
20
20
|
* append-only within a chain, see loop.ts).
|
|
21
21
|
* - ESCALATED, on the plan model again, for a few rounds: asked for with
|
|
22
|
-
* `
|
|
22
|
+
* `os_escalate`, or on its own after two failing test runs in a row,
|
|
23
23
|
* `ESCALATE_AFTER_IDLE_ROUNDS` rounds without a file change, or a loop-guard
|
|
24
24
|
* trip. It ends with a short reply, and exec starts a fresh chain with it.
|
|
25
25
|
*
|
|
26
26
|
* Part of the agent contract (see `version.ts`), copied verbatim into the
|
|
27
27
|
* runner. The orchestration lives here, `runPhasedLoop`; each runtime hands in
|
|
28
28
|
* how ONE phase runs (its own loop, its own transport bound to the phase's
|
|
29
|
-
* slot), like `runBatch` takes how one call is made. No imports
|
|
30
|
-
* from loop.ts (the working-set ledger) is handed in too.
|
|
29
|
+
* slot), like `runBatch` takes how one call is made. No imports but the tool
|
|
30
|
+
* names: what it needs from loop.ts (the working-set ledger) is handed in too.
|
|
31
31
|
*/
|
|
32
|
-
|
|
33
|
-
export const
|
|
32
|
+
import { osTool } from './tool-names.js';
|
|
33
|
+
export const SUBMIT_PLAN_TOOL = osTool('submit_plan');
|
|
34
|
+
export const ESCALATE_TOOL = osTool('escalate');
|
|
34
35
|
/** The phase tools: offered only in a run with phases, handled by the loops. */
|
|
35
36
|
export const PHASE_TOOL_NAMES = new Set([SUBMIT_PLAN_TOOL, ESCALATE_TOOL]);
|
|
36
37
|
/** The agent slot each phase's inference runs on. */
|
|
@@ -68,13 +69,13 @@ const FILE_CHANGING_TOOLS = new Set(['runner_write_file', 'runner_edit_file']);
|
|
|
68
69
|
export const PLAN_PHASE_BRIEF = [
|
|
69
70
|
'## Plan first',
|
|
70
71
|
'This run plans before it works. You are in the PLAN phase: read and reproduce, change nothing (writing files and git changes are refused here).',
|
|
71
|
-
`Find the cause, then call \`
|
|
72
|
+
`Find the cause, then call \`os_submit_plan({ approach, files, repro, risks, estimate, toolGroups })\`: the approach in a few lines, the files you will change, the command or test that shows the bug (and later proves the fix), the risks, an estimate in model calls (and dollars when you can), and the tool groups the work needs beyond what you have now. Set \`schemaMigration: true\` when the plan changes a database schema. You have at most ${PLAN_MAX_ROUNDS} rounds for this: read what the plan needs, not everything.`,
|
|
72
73
|
'The next phase starts on a FRESH context with only this request, the plan, your pins, the list of files you read and what you read of the files in the plan, with the tool groups you named loaded: put everything the work needs into the plan.',
|
|
73
74
|
'When nothing needs to change (already fixed, nothing to do), do not submit a plan: end with your proof as your reply.',
|
|
74
75
|
].join('\n');
|
|
75
76
|
/** How the studio answers a plan that passed its gate; anything else is a gate that waits or a refusal. */
|
|
76
77
|
export const PLAN_PASSED_PREFIX = 'Plan accepted.';
|
|
77
|
-
export const PLAN_NUDGE = 'You are in the plan phase: submit your plan with `
|
|
78
|
+
export const PLAN_NUDGE = 'You are in the plan phase: submit your plan with `os_submit_plan` to start the work. If nothing needs to change, reply once more with your proof and the run ends.';
|
|
78
79
|
/** What the planner is told as its rounds run out: after `PLAN_NUDGE_AFTER_ROUNDS`, and before its last one. */
|
|
79
80
|
export function planRoundsNudge(used, max) {
|
|
80
81
|
return used >= max - 1
|
|
@@ -94,29 +95,29 @@ export function escalationBrief(reason) {
|
|
|
94
95
|
].join('\n');
|
|
95
96
|
}
|
|
96
97
|
/** Exec without a plan: the plan phase ran out of rounds before it submitted one. */
|
|
97
|
-
export const EXEC_WITHOUT_PLAN = 'The plan phase ran out of rounds before it handed in a plan, so nobody checked one: find the change from what it found and read. When the change needs a database schema migration, ask a person with
|
|
98
|
+
export const EXEC_WITHOUT_PLAN = 'The plan phase ran out of rounds before it handed in a plan, so nobody checked one: find the change from what it found and read. When the change needs a database schema migration, ask a person with os_ask before you make it.';
|
|
98
99
|
export const ESCALATION_ACK = 'Escalated: after this round the planning model takes over on a fresh context with your reason, the plan and the files you worked with, and hands back what it found.';
|
|
99
|
-
export const ESCALATION_SPENT = `Not escalated: this run already escalated ${MAX_ESCALATIONS} times. Carry on with what you have, or ask a person with
|
|
100
|
+
export const ESCALATION_SPENT = `Not escalated: this run already escalated ${MAX_ESCALATIONS} times. Carry on with what you have, or ask a person with os_ask when only they can unblock you.`;
|
|
100
101
|
export const ESCALATION_IN_ESCALATION = 'You are the escalation: write your findings as a plain reply (no tool call) to hand back to the executor.';
|
|
101
102
|
export const PHASE_TOOL_NOT_HERE = 'Not available in this phase.';
|
|
102
103
|
export function planPhaseRefusal(toolName) {
|
|
103
104
|
return `Not run: ${toolName} changes files or the repository, and this is the plan phase. Submit your plan with ${SUBMIT_PLAN_TOOL} first; the change is the next phase's work.`;
|
|
104
105
|
}
|
|
105
106
|
// ─── Reading the tools ──────────────────────────────────────────────────────
|
|
106
|
-
/** The plan in a call's arguments, or what is wrong with it (`
|
|
107
|
+
/** The plan in a call's arguments, or what is wrong with it (`os_submit_plan`, both sides). */
|
|
107
108
|
export function readPlanArgs(raw) {
|
|
108
109
|
const a = (raw ?? {});
|
|
109
110
|
const text = (v) => typeof v === 'string' ? v.trim() : '';
|
|
110
111
|
const approach = text(a.approach);
|
|
111
112
|
if (!approach)
|
|
112
|
-
return '
|
|
113
|
+
return 'os_submit_plan needs an `approach`: how you will do it, in a few lines.';
|
|
113
114
|
const files = Array.isArray(a.files)
|
|
114
115
|
? a.files.filter((f) => typeof f === 'string' && f.trim() !== '').map(f => f.trim())
|
|
115
116
|
: typeof a.files === 'string' ? a.files.split(/[,\n]/).map(f => f.trim()).filter(Boolean) : [];
|
|
116
117
|
const estimate = (a.estimate ?? {});
|
|
117
118
|
const calls = typeof estimate.calls === 'number' ? Math.round(estimate.calls) : typeof a.estimate === 'number' ? Math.round(a.estimate) : NaN;
|
|
118
119
|
if (!Number.isFinite(calls) || calls < 1)
|
|
119
|
-
return '
|
|
120
|
+
return 'os_submit_plan needs `estimate.calls`: how many more model calls the work will take.';
|
|
120
121
|
const usd = typeof estimate.usd === 'number' && estimate.usd > 0 ? estimate.usd : undefined;
|
|
121
122
|
const toolGroups = [...new Set(Array.isArray(a.toolGroups)
|
|
122
123
|
? a.toolGroups.filter((g) => typeof g === 'string' && g.trim() !== '').map(g => g.trim())
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* The durable Task context: skill playbooks an agent loaded and facts it pinned
|
|
3
|
-
* with `
|
|
3
|
+
* with `os_pin`, kept in the system prompt for the whole task so compaction
|
|
4
4
|
* never takes them. One channel both loops render the same way.
|
|
5
5
|
*
|
|
6
6
|
* Part of the agent contract (see `version.ts`), copied verbatim into the
|
|
@@ -10,13 +10,13 @@ export declare const SKILL_PIN_MAX_CHARS = 8000;
|
|
|
10
10
|
export declare const NOTE_PIN_MAX_CHARS = 2000;
|
|
11
11
|
export declare const MAX_PINNED_NOTES = 40;
|
|
12
12
|
/**
|
|
13
|
-
* Clip a `
|
|
13
|
+
* Clip a `os_get_skill` result to the durable pin budget, keeping whole
|
|
14
14
|
* sections in priority order instead of a blind head-slice. Falls back to the
|
|
15
15
|
* plain clip when the payload is not the expected shape.
|
|
16
16
|
*/
|
|
17
17
|
export declare function clipSkillPin(result: string, maxChars?: number): string;
|
|
18
18
|
export declare function pinSlugFromArgs(args: unknown): string;
|
|
19
|
-
/** Handle an in-loop `
|
|
19
|
+
/** Handle an in-loop `os_pin` call. Actions: `set` (default) stores/updates a
|
|
20
20
|
* labelled fact, `remove` drops one, `clear` empties the notes. Returns the
|
|
21
21
|
* short confirmation string fed back as the tool result. */
|
|
22
22
|
export declare function applyPin(args: unknown, notes: Map<string, string>): string;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* The durable Task context: skill playbooks an agent loaded and facts it pinned
|
|
3
|
-
* with `
|
|
3
|
+
* with `os_pin`, kept in the system prompt for the whole task so compaction
|
|
4
4
|
* never takes them. One channel both loops render the same way.
|
|
5
5
|
*
|
|
6
6
|
* Part of the agent contract (see `version.ts`), copied verbatim into the
|
|
@@ -15,7 +15,7 @@ function clipPin(text, maxChars) {
|
|
|
15
15
|
/**
|
|
16
16
|
* Section order for an over-budget skill pin, most load-bearing first.
|
|
17
17
|
*
|
|
18
|
-
* `
|
|
18
|
+
* `os_get_skill` serialises sections in authoring order (SKILL_SECTIONS),
|
|
19
19
|
* which puts `rules`, `outputFormat` and `qualityChecklist` last - so a plain
|
|
20
20
|
* head-clip spends the durable budget on `purpose`/`whenToUse` and throws away
|
|
21
21
|
* exactly the parts an agent needs late in a run. Measured on a real project:
|
|
@@ -39,7 +39,7 @@ const SKILL_PIN_PRIORITY = [
|
|
|
39
39
|
'whenNotToUse',
|
|
40
40
|
];
|
|
41
41
|
/**
|
|
42
|
-
* Clip a `
|
|
42
|
+
* Clip a `os_get_skill` result to the durable pin budget, keeping whole
|
|
43
43
|
* sections in priority order instead of a blind head-slice. Falls back to the
|
|
44
44
|
* plain clip when the payload is not the expected shape.
|
|
45
45
|
*/
|
|
@@ -92,14 +92,14 @@ export function clipSkillPin(result, maxChars = SKILL_PIN_MAX_CHARS) {
|
|
|
92
92
|
// skill when it needs a section that is not in front of it.
|
|
93
93
|
function droppedNote(keys) {
|
|
94
94
|
return keys.length
|
|
95
|
-
? `…[pin truncated: ${keys.join(', ')} not kept - call
|
|
95
|
+
? `…[pin truncated: ${keys.join(', ')} not kept - call os_get_skill again to re-read them]`
|
|
96
96
|
: '';
|
|
97
97
|
}
|
|
98
98
|
export function pinSlugFromArgs(args) {
|
|
99
99
|
const slug = args?.slug;
|
|
100
100
|
return typeof slug === 'string' ? slug.trim() : '';
|
|
101
101
|
}
|
|
102
|
-
/** Handle an in-loop `
|
|
102
|
+
/** Handle an in-loop `os_pin` call. Actions: `set` (default) stores/updates a
|
|
103
103
|
* labelled fact, `remove` drops one, `clear` empties the notes. Returns the
|
|
104
104
|
* short confirmation string fed back as the tool result. */
|
|
105
105
|
export function applyPin(args, notes) {
|
|
@@ -111,7 +111,7 @@ export function applyPin(args, notes) {
|
|
|
111
111
|
return 'Cleared all pinned notes from your Task context.';
|
|
112
112
|
}
|
|
113
113
|
if (!label)
|
|
114
|
-
return 'Error:
|
|
114
|
+
return 'Error: os_pin requires a "label".';
|
|
115
115
|
if (action === 'remove') {
|
|
116
116
|
return notes.delete(label)
|
|
117
117
|
? `Removed pinned note "${label}".`
|
|
@@ -119,9 +119,9 @@ export function applyPin(args, notes) {
|
|
|
119
119
|
}
|
|
120
120
|
const text = typeof a.text === 'string' ? a.text.trim() : '';
|
|
121
121
|
if (!text)
|
|
122
|
-
return 'Error:
|
|
122
|
+
return 'Error: os_pin (set) requires "text" - the fact to keep.';
|
|
123
123
|
if (!notes.has(label) && notes.size >= MAX_PINNED_NOTES) {
|
|
124
|
-
return `Error: pinned-note limit (${MAX_PINNED_NOTES}) reached. Remove one with
|
|
124
|
+
return `Error: pinned-note limit (${MAX_PINNED_NOTES}) reached. Remove one with os_pin({ action: "remove", label }) before pinning a new fact.`;
|
|
125
125
|
}
|
|
126
126
|
notes.set(label, clipPin(text, NOTE_PIN_MAX_CHARS));
|
|
127
127
|
return `Pinned "${label}". It is kept in your Task context for the rest of this task and survives compaction.`;
|
|
@@ -137,7 +137,7 @@ function renderTaskContext(skills, notes) {
|
|
|
137
137
|
return '';
|
|
138
138
|
const parts = [
|
|
139
139
|
TASK_CONTEXT_HEADING,
|
|
140
|
-
'This block stays in your system prompt for the whole task and survives context compaction - it is your reliable working memory for this task. Trust what is here instead of re-fetching or re-discovering it. It holds skill playbooks you loaded and facts you pinned with
|
|
140
|
+
'This block stays in your system prompt for the whole task and survives context compaction - it is your reliable working memory for this task. Trust what is here instead of re-fetching or re-discovering it. It holds skill playbooks you loaded and facts you pinned with os_pin (a new pin shows up here at the next compaction; until then it is in the conversation as your own os_pin call).',
|
|
141
141
|
];
|
|
142
142
|
if (skills.size > 0) {
|
|
143
143
|
parts.push('### Loaded skill playbooks');
|
|
@@ -1,17 +1,36 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Tool names the model got wrong: the error it gets back for a name it does
|
|
3
3
|
* not have, and the closest names it does have. A guessed name
|
|
4
|
-
* (`
|
|
4
|
+
* (`os_list_journal_entries` for `os_list_journal`) should cost one
|
|
5
5
|
* round, not three.
|
|
6
6
|
*
|
|
7
7
|
* Part of the agent contract (see `version.ts`), copied verbatim into the
|
|
8
8
|
* runner: both loops feed the same error back, and the studio's
|
|
9
|
-
* `
|
|
9
|
+
* `os_load_toolset` warnings use the same suggestions.
|
|
10
10
|
*/
|
|
11
|
+
/**
|
|
12
|
+
* The prefix of every tool the OS serves itself (`os_load_toolset`). The
|
|
13
|
+
* runner's own tools carry `runner_`, connector tools `connector_`. Code that
|
|
14
|
+
* checks for an OS tool goes through `osTool` / `isOsTool`, never a literal
|
|
15
|
+
* prefix. Before runner 0.105.0 the prefix was `studio_`.
|
|
16
|
+
*/
|
|
17
|
+
export declare const TOOL_PREFIX = "os_";
|
|
18
|
+
/**
|
|
19
|
+
* The first runner on the `os_` prefix (0.104.0 was released on `studio_`, so
|
|
20
|
+
* the rename ships as 0.105.0). Runners below it still call and check
|
|
21
|
+
* `studio_*` names, which this studio no longer serves: it refuses them at
|
|
22
|
+
* connect with `CLOSE_RUNNER_TOO_OLD` (wire.ts) instead of letting toolset
|
|
23
|
+
* loads, pins and task completion fail silently.
|
|
24
|
+
*/
|
|
25
|
+
export declare const TOOL_PREFIX_MIN_RUNNER_VERSION = "0.105.0";
|
|
26
|
+
/** The full name of an OS tool: `osTool('load_toolset')` is `os_load_toolset`. */
|
|
27
|
+
export declare function osTool<N extends string>(name: N): `${typeof TOOL_PREFIX}${N}`;
|
|
28
|
+
/** Whether a tool name is one the OS serves itself (`os_*`). */
|
|
29
|
+
export declare function isOsTool(name: string): boolean;
|
|
11
30
|
/**
|
|
12
31
|
* The error fed back to the model when it called a tool name it does not
|
|
13
32
|
* have. When the name exists in a group it has not loaded yet, nudge it toward
|
|
14
|
-
* `
|
|
33
|
+
* `os_load_toolset`; otherwise name the closest tools it does have.
|
|
15
34
|
*/
|
|
16
35
|
export declare function buildUnknownToolError(toolName: string, groupForToolName: ReadonlyMap<string, {
|
|
17
36
|
key: string;
|
|
@@ -19,8 +38,8 @@ export declare function buildUnknownToolError(toolName: string, groupForToolName
|
|
|
19
38
|
/**
|
|
20
39
|
* The names in `candidates` closest to `name`, best first: the ones sharing
|
|
21
40
|
* most of its words (`list`, `journal`), then the ones made mostly of its
|
|
22
|
-
* words (so `
|
|
23
|
-
* `
|
|
41
|
+
* words (so `os_list_journal` beats `os_list_time_entries` for
|
|
42
|
+
* `os_list_journal_entries`), then by edit distance. A name sharing too
|
|
24
43
|
* few words is only kept when it is a typo or two away. Empty when nothing is
|
|
25
44
|
* close: better no hint than a wrong one.
|
|
26
45
|
*/
|
|
@@ -1,31 +1,58 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Tool names the model got wrong: the error it gets back for a name it does
|
|
3
3
|
* not have, and the closest names it does have. A guessed name
|
|
4
|
-
* (`
|
|
4
|
+
* (`os_list_journal_entries` for `os_list_journal`) should cost one
|
|
5
5
|
* round, not three.
|
|
6
6
|
*
|
|
7
7
|
* Part of the agent contract (see `version.ts`), copied verbatim into the
|
|
8
8
|
* runner: both loops feed the same error back, and the studio's
|
|
9
|
-
* `
|
|
9
|
+
* `os_load_toolset` warnings use the same suggestions.
|
|
10
10
|
*/
|
|
11
|
+
/**
|
|
12
|
+
* The prefix of every tool the OS serves itself (`os_load_toolset`). The
|
|
13
|
+
* runner's own tools carry `runner_`, connector tools `connector_`. Code that
|
|
14
|
+
* checks for an OS tool goes through `osTool` / `isOsTool`, never a literal
|
|
15
|
+
* prefix. Before runner 0.105.0 the prefix was `studio_`.
|
|
16
|
+
*/
|
|
17
|
+
export const TOOL_PREFIX = 'os_';
|
|
18
|
+
/**
|
|
19
|
+
* The first runner on the `os_` prefix (0.104.0 was released on `studio_`, so
|
|
20
|
+
* the rename ships as 0.105.0). Runners below it still call and check
|
|
21
|
+
* `studio_*` names, which this studio no longer serves: it refuses them at
|
|
22
|
+
* connect with `CLOSE_RUNNER_TOO_OLD` (wire.ts) instead of letting toolset
|
|
23
|
+
* loads, pins and task completion fail silently.
|
|
24
|
+
*/
|
|
25
|
+
export const TOOL_PREFIX_MIN_RUNNER_VERSION = '0.105.0';
|
|
26
|
+
/** The full name of an OS tool: `osTool('load_toolset')` is `os_load_toolset`. */
|
|
27
|
+
export function osTool(name) {
|
|
28
|
+
return `${TOOL_PREFIX}${name}`;
|
|
29
|
+
}
|
|
30
|
+
/** Whether a tool name is one the OS serves itself (`os_*`). */
|
|
31
|
+
export function isOsTool(name) {
|
|
32
|
+
return name.startsWith(TOOL_PREFIX);
|
|
33
|
+
}
|
|
11
34
|
/**
|
|
12
35
|
* The error fed back to the model when it called a tool name it does not
|
|
13
36
|
* have. When the name exists in a group it has not loaded yet, nudge it toward
|
|
14
|
-
* `
|
|
37
|
+
* `os_load_toolset`; otherwise name the closest tools it does have.
|
|
15
38
|
*/
|
|
16
39
|
export function buildUnknownToolError(toolName, groupForToolName) {
|
|
17
40
|
const group = groupForToolName.get(toolName);
|
|
18
41
|
if (group) {
|
|
19
|
-
return `Tool "${toolName}" is in the "${group.key}" group but is not loaded yet. Call
|
|
42
|
+
return `Tool "${toolName}" is in the "${group.key}" group but is not loaded yet. Call os_load_toolset({ group: "${group.key}" }) (or { names: ["${toolName}"] }) and then retry on your next step.`;
|
|
20
43
|
}
|
|
21
44
|
const closest = closestToolNames(toolName, groupForToolName.keys());
|
|
22
45
|
const hint = closest.length
|
|
23
|
-
? ` Did you mean ${closest.map(n => `${n} ("${groupForToolName.get(n).key}" group)`).join(', ')}? Load the one you need with
|
|
46
|
+
? ` Did you mean ${closest.map(n => `${n} ("${groupForToolName.get(n).key}" group)`).join(', ')}? Load the one you need with os_load_toolset first.`
|
|
24
47
|
: ' Re-read the "Tool categories" block of your system prompt and pick a tool from there - do not invent names.';
|
|
25
48
|
return `Tool "${toolName}" does not exist.${hint}`;
|
|
26
49
|
}
|
|
27
|
-
/**
|
|
28
|
-
|
|
50
|
+
/**
|
|
51
|
+
* Prefixes every tool carries: they say where a tool runs, not what it does.
|
|
52
|
+
* `studio` is the prefix before `os`: a model that still guesses
|
|
53
|
+
* `studio_load_toolset` gets `os_load_toolset` as the closest name.
|
|
54
|
+
*/
|
|
55
|
+
const TOOL_NAME_NOISE = new Set([TOOL_PREFIX.slice(0, -1), 'studio', 'runner']);
|
|
29
56
|
/** The words of a tool name that carry meaning, plural folded to singular. */
|
|
30
57
|
function toolNameWords(name) {
|
|
31
58
|
return name.toLowerCase().split(/[^a-z0-9]+/)
|
|
@@ -51,8 +78,8 @@ function sameWord(a, b) {
|
|
|
51
78
|
/**
|
|
52
79
|
* The names in `candidates` closest to `name`, best first: the ones sharing
|
|
53
80
|
* most of its words (`list`, `journal`), then the ones made mostly of its
|
|
54
|
-
* words (so `
|
|
55
|
-
* `
|
|
81
|
+
* words (so `os_list_journal` beats `os_list_time_entries` for
|
|
82
|
+
* `os_list_journal_entries`), then by edit distance. A name sharing too
|
|
56
83
|
* few words is only kept when it is a typo or two away. Empty when nothing is
|
|
57
84
|
* close: better no hint than a wrong one.
|
|
58
85
|
*/
|
|
@@ -57,7 +57,7 @@ export interface AgentConfigPayload {
|
|
|
57
57
|
maxCostPerTurn?: number;
|
|
58
58
|
maxToolRounds?: number;
|
|
59
59
|
maxLoopMs?: number;
|
|
60
|
-
/** How long a `
|
|
60
|
+
/** How long a `os_call_agent` from this agent may run. The studio owns
|
|
61
61
|
* the clock; the runner forwards it on `delegate:request` and keeps a
|
|
62
62
|
* backstop just past it. */
|
|
63
63
|
delegateTimeoutMs?: number;
|
|
@@ -85,22 +85,22 @@ export interface AgentConfigPayload {
|
|
|
85
85
|
* phase on /api/mcp/inference, where the studio resolves the model. */
|
|
86
86
|
phases?: RunPhasesConfig;
|
|
87
87
|
/** Every inference call of this dispatch runs on this slot of the agent:
|
|
88
|
-
* `explore` for a read-only working copy (`
|
|
88
|
+
* `explore` for a read-only working copy (`os_call_agent` with
|
|
89
89
|
* `tier: 'explore'`). Absent = the agent's own model. */
|
|
90
90
|
inferenceSlot?: 'explore';
|
|
91
91
|
/** Tools the agent has registered for this turn. Studio ships only the
|
|
92
92
|
* bootstrap set plus anything previously loaded in this conversation via
|
|
93
|
-
* `
|
|
93
|
+
* `os_load_toolset`. Everything else lives in `toolGroups[].tools[]` as
|
|
94
94
|
* a cheap name+description index and is registered on demand. Tools with
|
|
95
95
|
* a non-null `mcpPath` are executed via HTTP against the studio's MCP
|
|
96
96
|
* endpoints; tools with null `mcpPath` run locally inside the runner.
|
|
97
97
|
* The long `Tool.instructions` text is intentionally NOT here - fetched
|
|
98
|
-
* on-demand via `
|
|
98
|
+
* on-demand via `os_get_tool_instructions`. */
|
|
99
99
|
toolDefs?: ToolDefPayload[];
|
|
100
100
|
/** Capability-grouped index of every tool the agent has access to,
|
|
101
101
|
* including ones not yet loaded. Each group carries its tools by name +
|
|
102
102
|
* short description so the LLM can decide what to load via
|
|
103
|
-
* `
|
|
103
|
+
* `os_load_toolset` without an extra round-trip. Only groups with at
|
|
104
104
|
* least one allowed tool ship. */
|
|
105
105
|
toolGroups?: ToolGroupPayload[];
|
|
106
106
|
[key: string]: unknown;
|
|
@@ -111,7 +111,7 @@ export interface ToolGroupPayload {
|
|
|
111
111
|
description: string;
|
|
112
112
|
/** Tools in this group the agent is allowed to use. Name + short
|
|
113
113
|
* description only - full schemas are fetched on demand via
|
|
114
|
-
* `
|
|
114
|
+
* `os_load_toolset` (or shipped directly in `toolDefs` when bootstrap
|
|
115
115
|
* or previously loaded in this conversation). */
|
|
116
116
|
tools: {
|
|
117
117
|
name: string;
|
|
@@ -223,7 +223,7 @@ export interface ChatDispatchFrame {
|
|
|
223
223
|
/** UID of this dispatch's queue entry. Echoed back on every MCP tool call so
|
|
224
224
|
* the studio's `mcp-project-scope` middleware can resolve the invocation
|
|
225
225
|
* project - which is what makes project-scoped secrets (`${secret:KEY}`,
|
|
226
|
-
*
|
|
226
|
+
* os_get_secret) resolve inside a project-linked chat, exactly like a
|
|
227
227
|
* task. Optional: an older studio that doesn't send it leaves chat secret
|
|
228
228
|
* resolution org-scoped (pre-fix behaviour). */
|
|
229
229
|
queueUid?: string;
|
|
@@ -286,7 +286,7 @@ export interface TaskDispatchFrame {
|
|
|
286
286
|
/** The task instruction shown to the agent as its first user message. */
|
|
287
287
|
userPrompt: string;
|
|
288
288
|
/** Pre-rendered mid-loop nudge replayed when a task with a result schema
|
|
289
|
-
* reaches a final answer without calling `
|
|
289
|
+
* reaches a final answer without calling `os_update_task`. Present iff
|
|
290
290
|
* the task carries a result schema - its presence is the "has result
|
|
291
291
|
* schema" flag. */
|
|
292
292
|
schemaReminder?: string;
|
|
@@ -345,6 +345,14 @@ export interface ChatSideQuestionFrame {
|
|
|
345
345
|
export declare const SIDE_QUESTION_FEATURE = "side-question";
|
|
346
346
|
/** The `error` of a side question the runtime holds no context for. */
|
|
347
347
|
export declare const SIDE_QUESTION_NO_CONTEXT = "no-context";
|
|
348
|
+
/**
|
|
349
|
+
* WebSocket close code: the runner's `config` frame reported a version below
|
|
350
|
+
* what this studio needs (`TOOL_PREFIX_MIN_RUNNER_VERSION`). The close reason
|
|
351
|
+
* (and the `error` frame before it) says which version to update to. Not
|
|
352
|
+
* fatal on the runner: it reconnects slowly, so its updater can still install
|
|
353
|
+
* the release the `connected` frame announced.
|
|
354
|
+
*/
|
|
355
|
+
export declare const CLOSE_RUNNER_TOO_OLD = 4012;
|
|
348
356
|
/**
|
|
349
357
|
* Studio → CLI: only sent for `routing: 'runtime'` agents - studio-routed
|
|
350
358
|
* provider titles are generated in-studio and broadcast as `chat:title`
|
|
@@ -19,6 +19,14 @@
|
|
|
19
19
|
export const SIDE_QUESTION_FEATURE = 'side-question';
|
|
20
20
|
/** The `error` of a side question the runtime holds no context for. */
|
|
21
21
|
export const SIDE_QUESTION_NO_CONTEXT = 'no-context';
|
|
22
|
+
/**
|
|
23
|
+
* WebSocket close code: the runner's `config` frame reported a version below
|
|
24
|
+
* what this studio needs (`TOOL_PREFIX_MIN_RUNNER_VERSION`). The close reason
|
|
25
|
+
* (and the `error` frame before it) says which version to update to. Not
|
|
26
|
+
* fatal on the runner: it reconnects slowly, so its updater can still install
|
|
27
|
+
* the release the `connected` frame announced.
|
|
28
|
+
*/
|
|
29
|
+
export const CLOSE_RUNNER_TOO_OLD = 4012;
|
|
22
30
|
export const KNOWN_DISPATCH_TYPES = new Set([
|
|
23
31
|
'connected',
|
|
24
32
|
'chat',
|
|
@@ -17,6 +17,7 @@ export * from './contract/own-files.js';
|
|
|
17
17
|
export * from './contract/processes.js';
|
|
18
18
|
export * from './contract/release-tag.js';
|
|
19
19
|
export * from './contract/version.js';
|
|
20
|
+
export { TOOL_PREFIX, osTool, isOsTool } from './contract/tool-names.js';
|
|
20
21
|
export * from './connection.js';
|
|
21
22
|
export * from './inference.js';
|
|
22
23
|
export * from './mcp.js';
|
|
@@ -19,6 +19,7 @@ export * from './contract/own-files.js';
|
|
|
19
19
|
export * from './contract/processes.js';
|
|
20
20
|
export * from './contract/release-tag.js';
|
|
21
21
|
export * from './contract/version.js';
|
|
22
|
+
export { TOOL_PREFIX, osTool, isOsTool } from './contract/tool-names.js';
|
|
22
23
|
// Studio transport + streaming.
|
|
23
24
|
export * from './connection.js';
|
|
24
25
|
export * from './inference.js';
|
|
@@ -5,11 +5,11 @@ import type { ToolContext } from '../tools/index.js';
|
|
|
5
5
|
*
|
|
6
6
|
* Mirrors the studio-side `autoLoadToolDef` in
|
|
7
7
|
* `apps/server/server/utils/internal-runtime/adapters.ts`: when the model
|
|
8
|
-
* invokes a real, granted `
|
|
8
|
+
* invokes a real, granted `os_*` tool whose schema hasn't been loaded into
|
|
9
9
|
* this dispatch's registry yet, pull it in-band instead of bouncing the model
|
|
10
|
-
* with "call
|
|
10
|
+
* with "call os_load_toolset and retry" (a wasted round).
|
|
11
11
|
*
|
|
12
|
-
* The load goes through the exact same path an explicit `
|
|
12
|
+
* The load goes through the exact same path an explicit `os_load_toolset`
|
|
13
13
|
* call uses: `executeMcpTool` special-cases that tool name, hits
|
|
14
14
|
* `/api/mcp/tools/load` (which re-applies authorisation and persists to
|
|
15
15
|
* `Conversation.loadedToolNames`), and merges the returned defs into the
|
|
@@ -1,14 +1,15 @@
|
|
|
1
|
+
import { osTool } from '../contract/tool-names.js';
|
|
1
2
|
import { executeMcpTool } from '../tools/mcp.js';
|
|
2
3
|
/**
|
|
3
4
|
* First-use auto-load (runner side).
|
|
4
5
|
*
|
|
5
6
|
* Mirrors the studio-side `autoLoadToolDef` in
|
|
6
7
|
* `apps/server/server/utils/internal-runtime/adapters.ts`: when the model
|
|
7
|
-
* invokes a real, granted `
|
|
8
|
+
* invokes a real, granted `os_*` tool whose schema hasn't been loaded into
|
|
8
9
|
* this dispatch's registry yet, pull it in-band instead of bouncing the model
|
|
9
|
-
* with "call
|
|
10
|
+
* with "call os_load_toolset and retry" (a wasted round).
|
|
10
11
|
*
|
|
11
|
-
* The load goes through the exact same path an explicit `
|
|
12
|
+
* The load goes through the exact same path an explicit `os_load_toolset`
|
|
12
13
|
* call uses: `executeMcpTool` special-cases that tool name, hits
|
|
13
14
|
* `/api/mcp/tools/load` (which re-applies authorisation and persists to
|
|
14
15
|
* `Conversation.loadedToolNames`), and merges the returned defs into the
|
|
@@ -20,7 +21,7 @@ import { executeMcpTool } from '../tools/mcp.js';
|
|
|
20
21
|
* unknown-tool error.
|
|
21
22
|
*/
|
|
22
23
|
export async function autoLoadToolDef(toolName, registry, ctx) {
|
|
23
|
-
const loadDef = registry.get('
|
|
24
|
+
const loadDef = registry.get(osTool('load_toolset'));
|
|
24
25
|
if (!loadDef)
|
|
25
26
|
return undefined;
|
|
26
27
|
try {
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* fool us, and respects backslash-escaped quotes.
|
|
5
5
|
*
|
|
6
6
|
* Used by handle-task.ts to pull validation outcome out of the
|
|
7
|
-
* `
|
|
7
|
+
* `os_update_task` tool output, which begins with a human-readable prefix
|
|
8
8
|
* ("Task updated:\n…") followed by JSON. Naive `JSON.parse(text.slice(text
|
|
9
9
|
* .indexOf('{')))` is fragile when the model appends commentary after the
|
|
10
10
|
* JSON or when the payload contains stringified inner objects.
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* fool us, and respects backslash-escaped quotes.
|
|
5
5
|
*
|
|
6
6
|
* Used by handle-task.ts to pull validation outcome out of the
|
|
7
|
-
* `
|
|
7
|
+
* `os_update_task` tool output, which begins with a human-readable prefix
|
|
8
8
|
* ("Task updated:\n…") followed by JSON. Naive `JSON.parse(text.slice(text
|
|
9
9
|
* .indexOf('{')))` is fragile when the model appends commentary after the
|
|
10
10
|
* JSON or when the payload contains stringified inner objects.
|