@volter/supercode-orchestrator 0.4.7 → 0.4.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/activation.mjs +34 -1
- package/adapters/rh2.mjs +9 -2
- package/bin/orchestrator.mjs +2 -2
- package/index.d.ts +8 -0
- package/index.mjs +2 -2
- package/kanban-worker.mjs +3 -3
- package/loop.mjs +5 -3
- package/orchestration.mjs +11 -0
- package/package.json +1 -1
package/activation.mjs
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
// subfolder named by its id, pointed at through the harness's own env var.
|
|
4
4
|
|
|
5
5
|
import { join, relative, resolve } from 'node:path';
|
|
6
|
+
import { homedir } from 'node:os';
|
|
6
7
|
import { mkdirSync, readFileSync, readdirSync, lstatSync, rmSync, writeFileSync, existsSync } from 'node:fs';
|
|
7
8
|
import { CLAUDE_BRIDGE, linkTo, skillSources } from './hermes-home.mjs';
|
|
8
9
|
|
|
@@ -40,7 +41,10 @@ export function activationEnv({ root, profile, surfaceKey, vault }) {
|
|
|
40
41
|
const env = {};
|
|
41
42
|
const worker = profile.worker;
|
|
42
43
|
const homeVar = HOME_ENV[worker.harness];
|
|
43
|
-
|
|
44
|
+
// `home: user` keeps the user's own harness home (their CLAUDE.md, skills, hooks, plugins, MCP servers and login);
|
|
45
|
+
// the profile's persona and skills come in beside it through the launch (userHomeArguments).
|
|
46
|
+
if (worker.home === 'user') env.HOME = homedir();
|
|
47
|
+
else if (homeVar) env[homeVar] = join(profile.dir, worker.harness);
|
|
44
48
|
for (const [k, v] of Object.entries(worker.env ?? {})) env[k] = resolveRef(v, vault);
|
|
45
49
|
env[ORCH_ENV.root] = root;
|
|
46
50
|
env[ORCH_ENV.profile] = profile.name;
|
|
@@ -91,6 +95,28 @@ export function materializePersona(profile) {
|
|
|
91
95
|
*/
|
|
92
96
|
export const HOME_SKILLS = Object.freeze({ codex: 'skills', 'claude-code': 'skills' });
|
|
93
97
|
|
|
98
|
+
/** The harnesses a worker can run in the user's own home, with the profile brought in beside it. */
|
|
99
|
+
export const USER_HOME_HARNESSES = Object.freeze(new Set(['claude-code']));
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* The launch arguments that bring a profile's skills in beside the user's own Claude home (`home: user`): its
|
|
103
|
+
* skills folder as a session plugin (Claude Code's `--plugin-dir`; the folder carries the plugin manifest
|
|
104
|
+
* materializeSkills writes). Nothing for a worker in the profile's home.
|
|
105
|
+
*/
|
|
106
|
+
export function userHomeArguments(profile) {
|
|
107
|
+
const worker = profile.worker;
|
|
108
|
+
if (worker?.home !== 'user') return [];
|
|
109
|
+
if (!USER_HOME_HARNESSES.has(worker.harness)) throw new Error(`worker.home: user is not available for ${worker.harness} workers`);
|
|
110
|
+
return ['--plugin-dir', join(profile.dir, worker.harness)];
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/** The persona a worker in the user's own home carries in its system prompt (its home's CLAUDE.md is the user's). */
|
|
114
|
+
export function userHomePersona(profile) {
|
|
115
|
+
if (profile.worker?.home !== 'user') return '';
|
|
116
|
+
const persona = join(profile.dir, 'AGENTS.md');
|
|
117
|
+
return existsSync(persona) ? readFileSync(persona, 'utf8').trim() : '';
|
|
118
|
+
}
|
|
119
|
+
|
|
94
120
|
export function materializeSkills(profile) {
|
|
95
121
|
const worker = profile.worker;
|
|
96
122
|
const sub = worker && HOME_SKILLS[worker.harness];
|
|
@@ -98,6 +124,13 @@ export function materializeSkills(profile) {
|
|
|
98
124
|
const sources = skillSources(profile.dir);
|
|
99
125
|
const into = join(profile.dir, worker.harness, sub);
|
|
100
126
|
mkdirSync(into, { recursive: true });
|
|
127
|
+
// In the user's own home the folder is loaded as a session plugin, which needs its manifest.
|
|
128
|
+
if (worker.home === 'user') {
|
|
129
|
+
const manifest = join(profile.dir, worker.harness, '.claude-plugin', 'plugin.json');
|
|
130
|
+
const text = `${JSON.stringify({ name: profile.name, description: `The ${profile.name} profile's skills` }, null, 2)}\n`;
|
|
131
|
+
mkdirSync(join(profile.dir, worker.harness, '.claude-plugin'), { recursive: true });
|
|
132
|
+
if (!existsSync(manifest) || readFileSync(manifest, 'utf8') !== text) writeFileSync(manifest, text);
|
|
133
|
+
}
|
|
101
134
|
for (const [name, from] of sources) linkTo(join(into, name), relative(into, from));
|
|
102
135
|
for (const entry of readdirSync(into)) {
|
|
103
136
|
const path = join(into, entry);
|
package/adapters/rh2.mjs
CHANGED
|
@@ -45,11 +45,12 @@ const CLOCK_SKEW_MS = 60_000;
|
|
|
45
45
|
const ECHO_MEMORY = 500;
|
|
46
46
|
|
|
47
47
|
export class Rh2Adapter {
|
|
48
|
-
constructor({ platform = 'rh2', profile = 'default', channel = null, vault = new Map(), log = () => {}, fetchImpl = globalThis.fetch, sleep = (ms) => new Promise((r) => setTimeout(r, ms)) } = {}) {
|
|
48
|
+
constructor({ platform = 'rh2', profile = 'default', channel = null, vault = new Map(), refreshVault = () => false, log = () => {}, fetchImpl = globalThis.fetch, sleep = (ms) => new Promise((r) => setTimeout(r, ms)) } = {}) {
|
|
49
49
|
this.platform = platform;
|
|
50
50
|
this.profile = profile;
|
|
51
51
|
this.channel = channel;
|
|
52
52
|
this.vault = vault;
|
|
53
|
+
this.refreshVault = refreshVault;
|
|
53
54
|
this.log = log;
|
|
54
55
|
this.fetch = fetchImpl;
|
|
55
56
|
this.sleep = sleep;
|
|
@@ -110,7 +111,13 @@ export class Rh2Adapter {
|
|
|
110
111
|
async get(path, params = {}) {
|
|
111
112
|
const url = new URL(`${this.apiUrl()}/api/v3${path}`);
|
|
112
113
|
for (const [k, v] of Object.entries(params)) url.searchParams.set(k, String(v));
|
|
113
|
-
|
|
114
|
+
let res = await this.fetch(url, { headers: this.headers() });
|
|
115
|
+
// A refused credential may have been replaced in the home's `.env` since it was read: read it again and, when
|
|
116
|
+
// it changed, retry with it, so replacing the bot's session never needs a restart.
|
|
117
|
+
if (res.status === 401 && this.refreshVault()) {
|
|
118
|
+
this.log('info', `${this.platform}: credential refused; retrying with the one now in the home's .env`);
|
|
119
|
+
res = await this.fetch(url, { headers: this.headers() });
|
|
120
|
+
}
|
|
114
121
|
if (!res.ok) {
|
|
115
122
|
const error = new Error(`GET ${path} -> HTTP ${res.status}: ${(await res.text()).slice(0, 200)}`);
|
|
116
123
|
error.status = res.status;
|
package/bin/orchestrator.mjs
CHANGED
|
@@ -61,7 +61,7 @@ import { adoptHome } from '../hermes-home.mjs';
|
|
|
61
61
|
import { hermesAccess } from '../hermes-cli.mjs';
|
|
62
62
|
|
|
63
63
|
import {
|
|
64
|
-
load, save, step, importFrom, exportTo, closeWorld, Orchestrator, LoopbackAdapter,
|
|
64
|
+
load, save, refreshVault, step, importFrom, exportTo, closeWorld, Orchestrator, LoopbackAdapter,
|
|
65
65
|
ChatSdkAdapter, ApiServerAdapter, Rh2Adapter,
|
|
66
66
|
TICK_MS, accessPolicy, applyOperator, performRemoveProfileDir, OPERATOR_OPS,
|
|
67
67
|
} from '../index.mjs';
|
|
@@ -80,7 +80,7 @@ const ADAPTERS = {
|
|
|
80
80
|
loopback: (platform, profile) => new LoopbackAdapter({ platform, profile }),
|
|
81
81
|
'chat-sdk': (platform, profile, ctx) => new ChatSdkAdapter({ platform, profile, profileDir: ctx.state.profiles[profile]?.dir ?? null, channel: ctx.channel, vault: ctx.vault, log: ctx.log }),
|
|
82
82
|
api_server: (platform, profile, ctx) => new ApiServerAdapter({ platform, profile, channel: ctx.channel, vault: ctx.vault, state: ctx.state, log: ctx.log }),
|
|
83
|
-
rh2: (platform, profile, ctx) => new Rh2Adapter({ platform, profile, channel: ctx.channel, vault: ctx.vault, log: ctx.log }),
|
|
83
|
+
rh2: (platform, profile, ctx) => new Rh2Adapter({ platform, profile, channel: ctx.channel, vault: ctx.vault, refreshVault: () => refreshVault(ctx.state, ctx.vault), log: ctx.log }),
|
|
84
84
|
};
|
|
85
85
|
|
|
86
86
|
/// The selector a `platforms:` block resolves through: its `extra.adapter`
|
package/index.d.ts
CHANGED
|
@@ -195,6 +195,12 @@ export function materializePersona(profile: Profile): Path | null;
|
|
|
195
195
|
export const HOME_ENV: Readonly<Record<HarnessId, string>>;
|
|
196
196
|
/** Links each skill the profile has into the worker's config home `skills/` (Codex, Claude Code); answers that folder, or null. */
|
|
197
197
|
export function materializeSkills(profile: Profile): Path | null;
|
|
198
|
+
/** Harnesses whose worker can run in the user's own home (`worker.home: user`). */
|
|
199
|
+
export const USER_HOME_HARNESSES: ReadonlySet<string>;
|
|
200
|
+
/** `--plugin-dir <profile>/<harness>` for a worker in the user's own home; nothing otherwise. */
|
|
201
|
+
export function userHomeArguments(profile: { dir: string; worker?: { harness: string; home?: 'profile' | 'user' } }): string[];
|
|
202
|
+
/** The profile's persona text for a worker in the user's own home; empty otherwise. */
|
|
203
|
+
export function userHomePersona(profile: { dir: string; worker?: { harness: string; home?: 'profile' | 'user' } }): string;
|
|
198
204
|
export const HOME_SKILLS: Readonly<Record<HarnessId, string>>;
|
|
199
205
|
export const HOME_PERSONA: Readonly<Record<HarnessId, Readonly<Record<string, 'link' | 'bridge'>>>>;
|
|
200
206
|
export const ORCH_ENV: Readonly<{ root: string; profile: string; surface: string }>;
|
|
@@ -440,6 +446,8 @@ export function emptyRuntime(): RuntimeState;
|
|
|
440
446
|
export function canonicalJson(value: unknown): string;
|
|
441
447
|
export function persistedView(state: OrchestratorState): Omit<OrchestratorState, 'runtime'>;
|
|
442
448
|
export function parseDotenv(text: string): Map<string, string>;
|
|
449
|
+
/** Read every profile's `.env` into `vault` again, in place; true when a value changed. */
|
|
450
|
+
export function refreshVault(state: { profiles: Record<string, { dir: string }> }, vault: Map<string, string>): boolean;
|
|
443
451
|
|
|
444
452
|
export const CHAT_TYPES: Set<ChatType>;
|
|
445
453
|
export const END_REASONS: Set<EndReason>;
|
package/index.mjs
CHANGED
|
@@ -3,11 +3,11 @@ export {
|
|
|
3
3
|
renderSurfaceKey, parseSurfaceKey, surfaceKeyString, parseTarget, renderTarget, resolveRoute, routeSpecificity,
|
|
4
4
|
emptyState, emptyProfile, emptyRuntime, canonicalJson, persistedView, decodeContextFrom,
|
|
5
5
|
} from './ir.mjs';
|
|
6
|
-
export { load, save, compile, importFrom, exportTo, closeWorld, retainWorld, releaseWorld, stateOf, parseDotenv, supercodeCommand } from './orchestration.mjs';
|
|
6
|
+
export { load, save, compile, importFrom, exportTo, closeWorld, retainWorld, releaseWorld, stateOf, parseDotenv, supercodeCommand, refreshVault } from './orchestration.mjs';
|
|
7
7
|
export { step, expired, leaseId, accessPolicy, dmBehavior } from './reducer.mjs';
|
|
8
8
|
export * as events from './events.mjs';
|
|
9
9
|
export { parseCommand, frame, COMMANDS, REPLY } from './commands.mjs';
|
|
10
|
-
export { activationEnv, activationCwd, materializePersona, materializeSkills, HOME_ENV, HOME_PERSONA, HOME_SKILLS, ORCH_ENV } from './activation.mjs';
|
|
10
|
+
export { activationEnv, activationCwd, materializePersona, materializeSkills, HOME_ENV, HOME_PERSONA, HOME_SKILLS, ORCH_ENV, USER_HOME_HARNESSES, userHomeArguments, userHomePersona } from './activation.mjs';
|
|
11
11
|
export { Orchestrator, normalizeWorkerEvent, webhookPort, TICK_MS } from './loop.mjs';
|
|
12
12
|
export {
|
|
13
13
|
cronTick, dueJobs, nextRunAt, parseCron, scheduleError, claimFire, finishFire, advanceSchedule, resolveTarget,
|
package/kanban-worker.mjs
CHANGED
|
@@ -12,7 +12,7 @@ import { existsSync, statSync } from 'node:fs';
|
|
|
12
12
|
import { basename, dirname, join, resolve } from 'node:path';
|
|
13
13
|
import { SupercodeHarnessClient } from '@volter/supercode-harness-sdk';
|
|
14
14
|
import { load } from './orchestration.mjs';
|
|
15
|
-
import { INSTRUCTION_ARGUMENTS, activationCwd, activationEnv, sandboxArguments, approvalPolicy, limitArguments, materializePersona, materializeSkills, modelArguments, turnCounter } from './activation.mjs';
|
|
15
|
+
import { INSTRUCTION_ARGUMENTS, activationCwd, activationEnv, sandboxArguments, approvalPolicy, limitArguments, materializePersona, materializeSkills, modelArguments, turnCounter, userHomeArguments, userHomePersona } from './activation.mjs';
|
|
16
16
|
import { workerRoute } from './worker-route.mjs';
|
|
17
17
|
import { KANBAN_ENV, untrustedServerVerdict, hermesApproval, hermesInstall, hermesToolEnv, kanbanPrompt, memorySnapshot, mirrorSession } from './hermes-cli.mjs';
|
|
18
18
|
import { mountOrchestratorMcp } from './mcp/mount.mjs';
|
|
@@ -68,7 +68,7 @@ export async function runKanbanWorker(argv, env = process.env) {
|
|
|
68
68
|
// Hermes's system prompt for a dispatched worker: the home's memory, the task protocol, the task's skills
|
|
69
69
|
const memory = await memorySnapshot(profile.dir).catch(() => '');
|
|
70
70
|
const board = await kanbanPrompt(profile.dir, { skills: args.skills, task: taskId, env: task });
|
|
71
|
-
const instructions = [memory, board.guidance, board.skills].filter(Boolean).join('\n\n');
|
|
71
|
+
const instructions = [userHomePersona(profile), memory, board.guidance, board.skills].filter(Boolean).join('\n\n');
|
|
72
72
|
|
|
73
73
|
const client = new SupercodeHarnessClient(env.SUPERCODE_BIN ? { command: env.SUPERCODE_BIN } : {});
|
|
74
74
|
try {
|
|
@@ -85,7 +85,7 @@ async function runTurn({ client, profile, harness, worker, route, root, vault, s
|
|
|
85
85
|
const reasoning = args.reasoning && harness === 'codex' ? ['-c', `model_reasoning_effort=${JSON.stringify(args.reasoning)}`] : [];
|
|
86
86
|
const launch = {
|
|
87
87
|
program: base.program,
|
|
88
|
-
arguments: [...(base.arguments ?? []), ...modelArguments(worker), ...route.args, ...(instructions && INSTRUCTION_ARGUMENTS[harness] ? INSTRUCTION_ARGUMENTS[harness](instructions) : []), ...reasoning, ...sandboxArguments(profile, harness), ...limitArguments(profile, worker, (level, line) => say(line))],
|
|
88
|
+
arguments: [...(base.arguments ?? []), ...modelArguments(worker), ...route.args, ...(instructions && INSTRUCTION_ARGUMENTS[harness] ? INSTRUCTION_ARGUMENTS[harness](instructions) : []), ...userHomeArguments(profile), ...reasoning, ...sandboxArguments(profile, harness), ...limitArguments(profile, worker, (level, line) => say(line))],
|
|
89
89
|
env: { ...(base.env ?? {}), ...runEnv },
|
|
90
90
|
};
|
|
91
91
|
const mount = mountOrchestratorMcp({ root, profile, harness, surfaceKey, launch, vault, task });
|
package/loop.mjs
CHANGED
|
@@ -9,7 +9,7 @@ import { basename, join, dirname } from 'node:path';
|
|
|
9
9
|
import { step, leaseId } from './reducer.mjs';
|
|
10
10
|
import * as events from './events.mjs';
|
|
11
11
|
import { save, retainWorld, releaseWorld } from './orchestration.mjs';
|
|
12
|
-
import { INSTRUCTION_ARGUMENTS, NAME_ARGUMENTS, activationEnv, activationCwd, approvalPolicy, sandboxArguments, limitArguments, materializePersona, materializeSkills, modelArguments, turnCounter } from './activation.mjs';
|
|
12
|
+
import { INSTRUCTION_ARGUMENTS, NAME_ARGUMENTS, activationEnv, activationCwd, approvalPolicy, sandboxArguments, limitArguments, materializePersona, materializeSkills, modelArguments, turnCounter, userHomeArguments, userHomePersona } from './activation.mjs';
|
|
13
13
|
import { workerRoute } from './worker-route.mjs';
|
|
14
14
|
import { hermesAccess, hermesApproval, untrustedServerVerdict, hermesToolEnv, memorySnapshot, mirrorSession, mirrorState, recordIncident, sealMirror } from './hermes-cli.mjs';
|
|
15
15
|
import { hermesSessionKey } from './ir.mjs';
|
|
@@ -323,9 +323,11 @@ export class Orchestrator {
|
|
|
323
323
|
const env = { ...tools, ...activationEnv({ root: this.state.root, profile, surfaceKey: keyString, vault: this.vault }), ...route.env };
|
|
324
324
|
// the home's memory, as Hermes's agent carries it into a session (row 13)
|
|
325
325
|
const memory = INSTRUCTION_ARGUMENTS[worker.harness] ? await memorySnapshot(profile.dir).catch((error) => { this.log('warn', `memory ${keyString}: ${error.message}`); return ''; }) : '';
|
|
326
|
-
|
|
326
|
+
// a worker in the user's own home carries its persona there too (its config home's CLAUDE.md is the user's)
|
|
327
|
+
const instructionText = [userHomePersona(profile), memory].filter(Boolean).join('\n\n');
|
|
328
|
+
const instructions = instructionText && INSTRUCTION_ARGUMENTS[worker.harness] ? INSTRUCTION_ARGUMENTS[worker.harness](instructionText) : [];
|
|
327
329
|
const naming = NAME_ARGUMENTS[worker.harness]?.(basename(this.state.root)) ?? [];
|
|
328
|
-
launch = await this.resolveLaunch(profile, { ...worker, model: route.model }, env, [...route.args, ...instructions, ...naming]);
|
|
330
|
+
launch = await this.resolveLaunch(profile, { ...worker, model: route.model }, env, [...route.args, ...instructions, ...naming, ...userHomeArguments(profile)]);
|
|
329
331
|
} catch (error) {
|
|
330
332
|
this.enqueue(events.worker({ profile: profileName, keyString, runtime_id: null, ev: { kind: 'error', message: `start failed: ${error.message}` }, at: this.clock() }));
|
|
331
333
|
return;
|
package/orchestration.mjs
CHANGED
|
@@ -116,6 +116,17 @@ function readVault(orchestration) {
|
|
|
116
116
|
return vault;
|
|
117
117
|
}
|
|
118
118
|
|
|
119
|
+
/**
|
|
120
|
+
* Read every profile's `.env` into `vault` again, in place, so each reader holding it (a channel adapter) sees a
|
|
121
|
+
* credential replaced there without a restart. True when a value changed.
|
|
122
|
+
*/
|
|
123
|
+
export function refreshVault(state, vault) {
|
|
124
|
+
const fresh = readVault(state);
|
|
125
|
+
let changed = false;
|
|
126
|
+
for (const [k, v] of fresh) if (vault.get(k) !== v) { vault.set(k, v); changed = true; }
|
|
127
|
+
return changed;
|
|
128
|
+
}
|
|
129
|
+
|
|
119
130
|
/** An orchestration value as the loop's state: the persisted half plus an empty runtime half. */
|
|
120
131
|
export function stateOf(orchestration) {
|
|
121
132
|
return { ...orchestration, runtime: emptyRuntime() };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@volter/supercode-orchestrator",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.9",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "The orchestrator runtime over the Volter Harness ontology: one typed operational model whose folder is its serialization, read and written through the harness orchestration doors (docs/ORCHESTRATOR-IR.md)",
|
|
6
6
|
"exports": {
|