@volter/supercode-orchestrator 0.4.8 → 0.4.10

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 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
- if (homeVar) env[homeVar] = join(profile.dir, worker.harness);
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/apply/doors.mjs CHANGED
@@ -72,7 +72,7 @@ export function differs(want, live) {
72
72
  */
73
73
  function declaredOnly(spec, inference, rename) {
74
74
  const want = { schedule: spec.schedule };
75
- for (const field of ['prompt', 'skills', 'deliver', 'workdir', 'repeat', 'script', 'no_agent', 'monitor_script', 'monitor_url', 'toolsets', 'context_from']) {
75
+ for (const field of ['prompt', 'skills', 'deliver', 'attach_to_session', 'workdir', 'repeat', 'script', 'no_agent', 'monitor_script', 'monitor_url', 'toolsets', 'context_from']) {
76
76
  if (spec[field] !== undefined) want[rename[field] ?? field] = spec[field];
77
77
  }
78
78
  if (spec.model !== undefined) Object.assign(want, namedModel(spec, inference));
@@ -152,7 +152,7 @@ export function hermesDoor({ home, python = null, source = null, runner = null,
152
152
  id: job.id,
153
153
  name: job.name ?? null,
154
154
  managed: {
155
- schedule: job.schedule ?? null, prompt: job.prompt ?? null, skills: job.skills ?? null, deliver: job.deliver ?? null,
155
+ schedule: job.schedule ?? null, prompt: job.prompt ?? null, skills: job.skills ?? null, deliver: job.deliver ?? null, attach_to_session: job.attach_to_session ?? null,
156
156
  model: job.model ?? null, provider: job.provider ?? null, workdir: job.workdir ?? null, repeat: job.repeat?.times ?? null,
157
157
  script: job.script ?? null, no_agent: Boolean(job.no_agent), monitor_script: job.monitor_script ?? null,
158
158
  monitor_url: job.monitor_url ?? null, enabled_toolsets: job.enabled_toolsets ?? null, context_from: job.context_from ?? null,
@@ -234,7 +234,7 @@ export async function orchestratorDoor({ root, profile = 'default', load, socket
234
234
  id: job.id,
235
235
  name: job.residue?.name ?? null,
236
236
  managed: {
237
- schedule: job.schedule ?? null, prompt: job.prompt ?? null, skills: job.skills ?? null, deliver: deliver(job.deliver),
237
+ schedule: job.schedule ?? null, prompt: job.prompt ?? null, skills: job.skills ?? null, deliver: deliver(job.deliver), attach_to_session: job.attach_to_session ?? null,
238
238
  model: job.model ?? null, workdir: job.workdir ?? null, repeat: job.repeat?.times ?? null,
239
239
  script: job.residue?.script ?? null, no_agent: job.residue?.no_agent === true, monitor_script: job.residue?.monitor_script ?? null,
240
240
  monitor_url: job.residue?.monitor_url ?? null, context_from: job.context_from ?? null,
@@ -254,7 +254,7 @@ export async function orchestratorDoor({ root, profile = 'default', load, socket
254
254
  return row;
255
255
  };
256
256
  /** What jobs.update can change; a change to anything else is refused per record, never dropped. */
257
- const UPDATABLE = new Set(['schedule', 'prompt', 'deliver', 'model', 'workdir', 'script', 'no_agent', 'monitor_script', 'monitor_url']);
257
+ const UPDATABLE = new Set(['schedule', 'prompt', 'deliver', 'attach_to_session', 'model', 'workdir', 'script', 'no_agent', 'monitor_script', 'monitor_url']);
258
258
  return {
259
259
  target: 'orchestrator',
260
260
  list,
@@ -289,4 +289,4 @@ export async function orchestratorDoor({ root, profile = 'default', load, socket
289
289
  }
290
290
 
291
291
  /** The job fields the applier owns: the union both doors read (a door that has no such field reads null). */
292
- export const MANAGED_JOB_FIELDS = Object.freeze(['schedule', 'prompt', 'skills', 'deliver', 'model', 'provider', 'workdir', 'repeat', 'script', 'no_agent', 'monitor_script', 'monitor_url', 'enabled_toolsets', 'context_from']);
292
+ export const MANAGED_JOB_FIELDS = Object.freeze(['schedule', 'prompt', 'skills', 'deliver', 'attach_to_session', 'model', 'provider', 'workdir', 'repeat', 'script', 'no_agent', 'monitor_script', 'monitor_url', 'enabled_toolsets', 'context_from']);
package/cron.mjs CHANGED
@@ -12,7 +12,7 @@
12
12
 
13
13
  import { surfaceKeyString } from './ir.mjs';
14
14
  import { homeChannel } from './ir.mjs';
15
- import { endBinding, ensureRuntime, leaseId, newObligation, permissionResponse, reply } from './reducer.mjs';
15
+ import { endBinding, ensureRuntime, leaseId, newObligation, permissionResponse, reply, startWorker } from './reducer.mjs';
16
16
 
17
17
  /** Retry delays after the 1st, 2nd and 3rd send attempt (§4.3 "retry pending obligations"). */
18
18
  export const BACKOFF_MINUTES = Object.freeze([1, 2, 4]);
@@ -799,6 +799,7 @@ function launchFire(state, profile, job, fire, prompt, now, effects) {
799
799
  deliverResult(state, profile, { job, fire }, fire.error, true, now, effects);
800
800
  return;
801
801
  }
802
+ if (job.attach_to_session === true && attachFire(state, profile, job, fire, prompt, now, effects)) return;
802
803
  const rt = ensureRuntime(state);
803
804
 
804
805
  const key = { platform: 'cron', kind: 'dm', chat_id: job.id };
@@ -819,6 +820,42 @@ function launchFire(state, profile, job, fire, prompt, now, effects) {
819
820
  effects.push({ type: 'save' });
820
821
  }
821
822
 
823
+ /**
824
+ * `attach_to_session`: the fire is a turn in the live session of the conversation it delivers to, taken the way an
825
+ * inbound message there is: it steers the running turn where the worker takes input mid-turn, waits behind it
826
+ * otherwise, and reopens the conversation's own session when its worker is gone. The conversation's reply is the
827
+ * delivery, so the fire is done once it is handed over. False (a session of its own) when that conversation has
828
+ * no live binding.
829
+ */
830
+ function attachFire(state, profile, job, fire, prompt, now, effects) {
831
+ const target = resolveTarget(job, profile);
832
+ if (!target?.platform) return false;
833
+ const found = Object.entries(profile.bindings).find(([ks, b]) => !b.ended_at && !ks.includes('#')
834
+ && b.key.platform === target.platform && String(b.key.chat_id ?? '') === String(target.chat_id ?? '')
835
+ && String(b.key.thread_id ?? '') === String(target.thread_id ?? ''));
836
+ if (!found) return false;
837
+ const [keyString, binding] = found;
838
+ const rt = ensureRuntime(state);
839
+ const lid = leaseId(profile.name, keyString);
840
+ if (!rt.leases[lid] && !rt.turns[lid] && !rt.starting[lid]) {
841
+ if (binding.worker.session_id) binding.residue.resume_runtime_id ??= binding.residue.runtime_id ?? binding.worker.session_id;
842
+ startWorker(state, profile, keyString, effects);
843
+ }
844
+ binding.last_activity_at = now;
845
+ const text = `[scheduled: ${job.name ?? job.id}] ${prompt}`;
846
+ if (rt.turns[lid] && rt.leases[lid]?.steer) effects.push({ type: 'steer_input', profile: profile.name, keyString, text });
847
+ else if (rt.turns[lid] || !rt.leases[lid]) (rt.queues[lid] ??= []).push({ text, at: now, job_id: job.id });
848
+ else {
849
+ rt.turns[lid] = { started_at: now, buffer: '' };
850
+ effects.push({ type: 'send_input', profile: profile.name, keyString, text });
851
+ }
852
+ fire.started_at = now;
853
+ fire.residue = { ...(fire.residue ?? {}), attached_to: keyString };
854
+ finishFire(profile, fire, job, 'succeeded', now, null, effects);
855
+ effects.push({ type: 'save' });
856
+ return true;
857
+ }
858
+
822
859
  function retryObligations(state, profile, now, effects) {
823
860
  const rt = ensureRuntime(state);
824
861
  const t = Date.parse(now);
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 }>;
package/index.mjs CHANGED
@@ -7,7 +7,7 @@ export { load, save, compile, importFrom, exportTo, closeWorld, retainWorld, rel
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
- const instructions = memory ? INSTRUCTION_ARGUMENTS[worker.harness](memory) : [];
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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@volter/supercode-orchestrator",
3
- "version": "0.4.8",
3
+ "version": "0.4.10",
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": {
package/reducer.mjs CHANGED
@@ -228,7 +228,7 @@ function handleInbound(state, ev, effects) {
228
228
  * a burst of messages before the lease exists queues behind ONE start (the
229
229
  * `started`/`error` worker events clear the mark).
230
230
  */
231
- function startWorker(state, profile, keyString, effects) {
231
+ export function startWorker(state, profile, keyString, effects) {
232
232
  const rt = ensureRuntime(state);
233
233
  rt.starting[leaseId(profile.name, keyString)] = true;
234
234
  // A binding whose runtime went away with the daemon reopens that same session where its harness can, so the