@volter/supercode-orchestrator 0.4.9 → 0.4.11

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
@@ -6,6 +6,7 @@ import { join, relative, resolve } from 'node:path';
6
6
  import { homedir } from 'node:os';
7
7
  import { mkdirSync, readFileSync, readdirSync, lstatSync, rmSync, writeFileSync, existsSync } from 'node:fs';
8
8
  import { CLAUDE_BRIDGE, linkTo, skillSources } from './hermes-home.mjs';
9
+ import { ownLogin } from './worker-route.mjs';
9
10
 
10
11
  /** Which env var each harness reads its config home from (supercode registry evidence). */
11
12
  export const HOME_ENV = Object.freeze({
@@ -44,7 +45,8 @@ export function activationEnv({ root, profile, surfaceKey, vault }) {
44
45
  // `home: user` keeps the user's own harness home (their CLAUDE.md, skills, hooks, plugins, MCP servers and login);
45
46
  // the profile's persona and skills come in beside it through the launch (userHomeArguments).
46
47
  if (worker.home === 'user') env.HOME = homedir();
47
- else if (homeVar) env[homeVar] = join(profile.dir, worker.harness);
48
+ // a worker on its user's own login keeps that user's config home (worker-route.mjs `ownLogin`)
49
+ else if (homeVar && !ownLogin(profile)) env[homeVar] = join(profile.dir, worker.harness);
48
50
  for (const [k, v] of Object.entries(worker.env ?? {})) env[k] = resolveRef(v, vault);
49
51
  env[ORCH_ENV.root] = root;
50
52
  env[ORCH_ENV.profile] = profile.name;
@@ -131,10 +133,15 @@ export function materializeSkills(profile) {
131
133
  mkdirSync(join(profile.dir, worker.harness, '.claude-plugin'), { recursive: true });
132
134
  if (!existsSync(manifest) || readFileSync(manifest, 'utf8') !== text) writeFileSync(manifest, text);
133
135
  }
134
- for (const [name, from] of sources) linkTo(join(into, name), relative(into, from));
135
- for (const entry of readdirSync(into)) {
136
- const path = join(into, entry);
137
- if (lstatSync(path).isSymbolicLink() && !sources.has(entry) && !existsSync(path)) rmSync(path, { force: true });
136
+ // A worker on its user's own login reads them from the `--add-dir`ed Claude home's `.claude/skills` (worker-route.mjs
137
+ // `ownLogin`), linked beside `skills/`, which the orchestrator's own skill lookup still reads.
138
+ for (const folder of [into, ...(ownLogin(profile) ? [join(profile.dir, worker.harness, '.claude', 'skills')] : [])]) {
139
+ mkdirSync(folder, { recursive: true });
140
+ for (const [name, from] of sources) linkTo(join(folder, name), relative(folder, from));
141
+ for (const entry of readdirSync(folder)) {
142
+ const path = join(folder, entry);
143
+ if (lstatSync(path).isSymbolicLink() && !sources.has(entry) && !existsSync(path)) rmSync(path, { force: true });
144
+ }
138
145
  }
139
146
  return into;
140
147
  }
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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@volter/supercode-orchestrator",
3
- "version": "0.4.9",
3
+ "version": "0.4.11",
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
package/worker-route.mjs CHANGED
@@ -91,9 +91,27 @@ export function workerRoute(profile, worker, vault) {
91
91
  return { model, args: ['-c', `model_provider=${JSON.stringify(id)}`], env };
92
92
  }
93
93
 
94
- /** Claude Code's route: its own environment and the endpoint's Messages wire. */
94
+ /**
95
+ * Whether a Claude Code worker runs on its user's own Claude login: `provider: anthropic` with no endpoint and no key,
96
+ * in the profile's home (a `home: user` worker is in that user's home already). The runhuman lobby managers run so.
97
+ * Claude Code finds its login through its config home, and a `CLAUDE_CONFIG_DIR` of the profile's own reports "Not
98
+ * logged in" (measured, claude 2.1.280), so the worker keeps its user's config home and the profile's reaches it by
99
+ * flag: `--add-dir` the profile's Claude home (its `CLAUDE.md`, read there under
100
+ * `CLAUDE_CODE_ADDITIONAL_DIRECTORIES_CLAUDE_MD`, and its `.claude/skills`), `--setting-sources project,local` so that
101
+ * user's own settings, hooks and `CLAUDE.md` stay out, and `--strict-mcp-config` so only the MCP door's servers mount.
102
+ */
103
+ export function ownLogin(profile, worker = profile?.worker) {
104
+ const route = hermesModel(profile);
105
+ return worker?.harness === 'claude-code' && worker?.home !== 'user' && route?.provider === 'anthropic' && !route.base_url && !route.api_key;
106
+ }
107
+
108
+ /** Claude Code's route: its own environment, the endpoint's Messages wire, or its user's own login (`ownLogin`). */
95
109
  function claudeRoute(profile, route, model, vault) {
96
110
  if (!['custom', 'anthropic'].includes(route.provider)) throw new Error(`model.provider ${route.provider} has no Claude Code route in this orchestrator yet; refused rather than run on Claude Code's default`);
111
+ if (ownLogin(profile, { ...profile.worker, harness: 'claude-code' })) {
112
+ const env = { CLAUDE_CODE_ADDITIONAL_DIRECTORIES_CLAUDE_MD: '1', ...(model ? { ANTHROPIC_MODEL: model } : {}) };
113
+ return { model, args: ['--add-dir', join(profile.dir, 'claude-code'), '--setting-sources', 'project,local', '--strict-mcp-config'], env };
114
+ }
97
115
  if (!route.base_url) throw new Error('Claude Code runs on a model with an endpoint (model.base_url); refused rather than run on Claude Code\'s default');
98
116
  const env = { CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC: '1' };
99
117
  if (route.base_url) env.ANTHROPIC_BASE_URL = String(resolve(route.base_url, vault).value).replace(/\/v1\/?$/, '').replace(/\/$/, '');