@chatpanel/gateway 0.6.101 → 0.6.104
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/agent.js +7 -0
- package/src/bridge-supervisor.js +42 -6
- package/src/server.js +1 -1
- package/src/team-record.js +18 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@chatpanel/gateway",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.104",
|
|
4
4
|
"description": "Local privacy gateway — redacts PII out of OpenAI/Anthropic API traffic before it reaches a model, then restores it in the reply. Point opencode, codex, aider, Claude Code, etc. at it.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
package/src/agent.js
CHANGED
|
@@ -179,6 +179,13 @@ export function resolveTeam(team, pool = [], { chatModel = null, targetFor = nul
|
|
|
179
179
|
// that is the bridge's id for Claude Code and the pilot's choice — change it on the card.
|
|
180
180
|
|
|
181
181
|
export const STARTER_AGENTS = Object.freeze([
|
|
182
|
+
// The EXECUTIVE holds a goal (project-run.js): it posts the jobs, recruits for each from
|
|
183
|
+
// the pool, runs the recruited as a team, reads what came back, posts the follow-ups, asks
|
|
184
|
+
// the stakeholder where the gate says a person decides, and closes when done-when holds.
|
|
185
|
+
// A person is the stakeholder by default; this is the manager they delegate the running to.
|
|
186
|
+
{ id: 'executive', name: 'Executive', purpose: 'Runs a project: posts the jobs for the goal, recruits from the pool, reads the results, posts follow-ups, asks before spending or changing scope, closes when done-when holds.',
|
|
187
|
+
prompt: 'You are the Executive. You hold one goal and its done-when. Break the goal into jobs a stranger could act on, each naming the skills and tools it needs; prefer jobs that run at the same time and use dependsOn only when one truly needs another\'s result. Read every result against done-when as written — say it holds only when it does on the results as they are, not as they could be. Post follow-up jobs only for what would move done-when. Say plainly what was not found. You never do a job yourself and never create an agent, tool or skill without a person\'s approval.',
|
|
188
|
+
skills: ['planning', 'management'], grants: ['none'], engine: { kind: 'auto', policy: { prefer: 'best-quality' } }, appliesTo: ['jobs'] },
|
|
182
189
|
{ id: 'architect', name: 'Architect', purpose: 'Reads the docs and the repos; writes the project page and the jobs.',
|
|
183
190
|
prompt: 'You are the Architect. Read the feature doc, ROADMAP.md, naming-revamp.md and architecture-pillars.md before deciding anything. Write the project page (goal, done-when, budget) and post one job per repo that must change, saying which repo and what the guard is. Propose a new agent type only when no one in the pool fits. Never run a shell.',
|
|
184
191
|
skills: [], grants: ['data', 'history'], engine: { kind: 'auto', policy: { prefer: 'best-quality' } }, appliesTo: ['jobs'] },
|
package/src/bridge-supervisor.js
CHANGED
|
@@ -112,6 +112,10 @@ export async function ensureBridge(cfg, {
|
|
|
112
112
|
waitForSiblingMs = 2500,
|
|
113
113
|
now = Date.now,
|
|
114
114
|
setTimer = setTimeout,
|
|
115
|
+
// The watch on an ADOPTED bridge: its own timer seam (a test's immediate `setTimer` would
|
|
116
|
+
// spin it), unref'd so a pending watch never keeps the process alive.
|
|
117
|
+
setWatch = (fn, ms) => { const t = setTimeout(fn, ms); t.unref?.(); return t; },
|
|
118
|
+
watchEveryMs = 10_000,
|
|
115
119
|
} = {}) {
|
|
116
120
|
const url = String(cfg?.bridge?.url || DEFAULT_BRIDGE_URL).replace(/\/$/, '');
|
|
117
121
|
const state = { mode: 'off', version: null, pid: null, restarts: 0, why: '', child: null, stopping: false, backoff: 0 };
|
|
@@ -131,12 +135,43 @@ export async function ensureBridge(cfg, {
|
|
|
131
135
|
const plan = planBridge({ managed, cfgUrl: url, healthy, standalone, embeddedVersion });
|
|
132
136
|
|
|
133
137
|
if (plan.action === 'off') { settle('off', plan.why); return controller(); }
|
|
134
|
-
if (plan.action === 'adopt') { settle('adopted', plan.why, { version: healthy.version }); return controller(); }
|
|
135
138
|
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
+
// What WE would run, decided once and kept: an adopted bridge that goes away is replaced
|
|
140
|
+
// by this without re-planning from scratch.
|
|
141
|
+
const specFor = (p) => (p.action === 'spawn-embedded'
|
|
142
|
+
? { ...emb, env: { CHATPANEL_BRIDGE_EMBEDDED: '1' }, mode: 'embedded', version: p.version || embeddedVersion }
|
|
143
|
+
: { program: p.path, args: [], env: {}, mode: 'standalone', version: standalone?.version || null });
|
|
144
|
+
let spec = plan.action === 'adopt' ? null : specFor(plan);
|
|
139
145
|
let startedAt = 0;
|
|
146
|
+
let watch = null;
|
|
147
|
+
let misses = 0;
|
|
148
|
+
|
|
149
|
+
// AN ADOPTED BRIDGE IS WATCHED, NOT TRUSTED FOREVER. The gateway carries the bridge: when
|
|
150
|
+
// the one it adopted goes away — the desktop app that ran it quit, an old login unit was
|
|
151
|
+
// removed, a standalone was stopped — the port is quiet and every agent turn fails with
|
|
152
|
+
// "bridge unreachable" until someone restarts the gateway. Two missed probes (a refused
|
|
153
|
+
// port counts at once) and ours starts.
|
|
154
|
+
const adopt = (why, ver) => {
|
|
155
|
+
settle('adopted', why, { version: ver || null });
|
|
156
|
+
misses = 0;
|
|
157
|
+
const tick = async () => {
|
|
158
|
+
if (state.stopping || state.mode !== 'adopted') return;
|
|
159
|
+
const h = await probe(url);
|
|
160
|
+
if (h) { misses = 0; state.version = h.version || state.version; watch = setWatch(tick, watchEveryMs); return; }
|
|
161
|
+
misses += 1;
|
|
162
|
+
if (misses < 2) { watch = setWatch(tick, Math.min(watchEveryMs, 3000)); return; }
|
|
163
|
+
if (!spec) {
|
|
164
|
+
const ev = embeddedVersion || version(emb.program, emb.args);
|
|
165
|
+
const p = planBridge({ managed, cfgUrl: url, healthy: null, standalone, embeddedVersion: ev });
|
|
166
|
+
if (p.action === 'off') { settle('off', `the adopted bridge went away and ${p.why}`); return; }
|
|
167
|
+
spec = specFor({ ...p, version: ev });
|
|
168
|
+
}
|
|
169
|
+
log(` bridge : the adopted bridge at ${url} went away — ${spec.mode === 'embedded' ? `starting the embedded bridge (v${spec.version || '?'})` : `starting the installed bridge (v${spec.version || '?'})`}`);
|
|
170
|
+
settle(spec.mode, `the adopted bridge went away; ${spec.mode} bridge started in its place`, { version: spec.version });
|
|
171
|
+
start();
|
|
172
|
+
};
|
|
173
|
+
watch = setWatch(tick, watchEveryMs);
|
|
174
|
+
};
|
|
140
175
|
|
|
141
176
|
const start = () => {
|
|
142
177
|
if (state.stopping) return;
|
|
@@ -155,7 +190,7 @@ export async function ensureBridge(cfg, {
|
|
|
155
190
|
// The port may have been taken by a bridge someone else started while ours came up —
|
|
156
191
|
// that is not a failure to restart from, it is a bridge to adopt.
|
|
157
192
|
const other = await probe(url);
|
|
158
|
-
if (other) {
|
|
193
|
+
if (other) { adopt(`a bridge already answers at ${url} (v${other.version || '?'}${other.managedBy ? `, run by ${other.managedBy}` : ''}) — ours stepped aside`, other.version); return; }
|
|
159
194
|
if (now() - startedAt > STABLE_MS) state.backoff = 0;
|
|
160
195
|
const delay = BACKOFF_MS[Math.min(state.backoff, BACKOFF_MS.length - 1)];
|
|
161
196
|
state.backoff += 1; state.restarts += 1;
|
|
@@ -163,6 +198,7 @@ export async function ensureBridge(cfg, {
|
|
|
163
198
|
setTimer(start, delay);
|
|
164
199
|
});
|
|
165
200
|
};
|
|
201
|
+
if (plan.action === 'adopt') { adopt(plan.why, healthy.version); return controller(); }
|
|
166
202
|
settle(spec.mode, plan.why, { version: spec.version });
|
|
167
203
|
start();
|
|
168
204
|
return controller();
|
|
@@ -170,7 +206,7 @@ export async function ensureBridge(cfg, {
|
|
|
170
206
|
function controller() {
|
|
171
207
|
return {
|
|
172
208
|
status: () => ({ mode: state.mode, version: state.version, pid: state.pid, restarts: state.restarts, why: state.why }),
|
|
173
|
-
stop: () => { state.stopping = true; if (state.child && !state.child.killed) { try { state.child.kill('SIGTERM'); } catch { /* gone */ } } },
|
|
209
|
+
stop: () => { state.stopping = true; if (watch) { clearTimeout(watch); watch = null; } if (state.child && !state.child.killed) { try { state.child.kill('SIGTERM'); } catch { /* gone */ } } },
|
|
174
210
|
};
|
|
175
211
|
}
|
|
176
212
|
}
|
package/src/server.js
CHANGED
|
@@ -63,7 +63,7 @@ import * as openai from './openai.js';
|
|
|
63
63
|
import * as responses from './responses.js';
|
|
64
64
|
import * as anthropic from './anthropic.js';
|
|
65
65
|
|
|
66
|
-
export const VERSION = '0.6.
|
|
66
|
+
export const VERSION = '0.6.104';
|
|
67
67
|
|
|
68
68
|
// WARM search tier — SQLite + FTS5 record store (falls back to an encrypted-JSON
|
|
69
69
|
// store if SQLite can't load), fed by the extension's ingest sync + backup-ingest.
|
package/src/team-record.js
CHANGED
|
@@ -36,7 +36,7 @@ export function foldRun(run, ev) {
|
|
|
36
36
|
case 'plan.ready':
|
|
37
37
|
run.plan = { by: p.by || 'fixed', tasks: Array.isArray(p.tasks) ? p.tasks : [] };
|
|
38
38
|
// A resume replays the plan: keep what the tasks already hold (transcripts, attempts).
|
|
39
|
-
run.tasks = run.plan.tasks.map((t) => ({ ...(taskOf(run, t.id) || {}), id: t.id, role: t.role, title: t.title, status: taskOf(run, t.id)?.status === 'ok' ? 'ok' : (t.parent && !t.role ? 'unassigned' : 'pending'), findings: taskOf(run, t.id)?.findings || 0, ...(t.parent ? { parent: t.parent, requestedBy: t.requestedBy || null } : {}), ...(t.grants ? { grants: t.grants, why: t.why || '' } : {}) }));
|
|
39
|
+
run.tasks = run.plan.tasks.map((t) => ({ ...(taskOf(run, t.id) || {}), id: t.id, role: t.role, title: t.title, status: taskOf(run, t.id)?.status === 'ok' ? 'ok' : (t.parent && !t.role ? 'unassigned' : 'pending'), findings: taskOf(run, t.id)?.findings || 0, ...(t.parent ? { parent: t.parent, requestedBy: t.requestedBy || null } : {}), ...(t.grants ? { grants: t.grants, why: t.why || '' } : {}), ...(t.kind ? { kind: t.kind } : {}) }));
|
|
40
40
|
run.status = 'running';
|
|
41
41
|
break;
|
|
42
42
|
// A SUB-TASK (§15.2): requested by a member mid-run, it joins the plan under its parent;
|
|
@@ -48,13 +48,29 @@ export function foldRun(run, ev) {
|
|
|
48
48
|
run.tasks.push({ id: task.id, role: null, title: task.title, status: 'requested', findings: 0, parent: task.parent, requestedBy: task.requestedBy, needs: task.needs, requestedAt: at });
|
|
49
49
|
}
|
|
50
50
|
break;
|
|
51
|
+
// A TASK ADDED AFTER THE PLAN — the merge (the judge's task, opened when the members are
|
|
52
|
+
// done). It joins the plan so a resume carries it and the board draws its thread and log.
|
|
53
|
+
case 'task.added':
|
|
54
|
+
if (p.taskId && !taskOf(run, p.taskId)) {
|
|
55
|
+
const task = { id: p.taskId, role: p.role || null, title: p.title || p.taskId, dependsOn: Array.isArray(p.dependsOn) ? p.dependsOn : [], ...(p.kind ? { kind: p.kind } : {}) };
|
|
56
|
+
if (run.plan) run.plan.tasks = [...(run.plan.tasks || []), task];
|
|
57
|
+
run.tasks.push({ id: task.id, role: task.role, title: task.title, status: 'pending', findings: 0, ...(p.kind ? { kind: p.kind } : {}) });
|
|
58
|
+
}
|
|
59
|
+
break;
|
|
51
60
|
case 'task.taken': { const t = taskOf(run, p.taskId); if (t) { t.role = p.role; t.status = 'pending'; t.takenBy = { by: p.by || 'fit', role: p.role, fit: p.fit ?? null, reasons: p.reasons || [], agentId: p.agentId || null, engine: p.engine || null, why: p.why || '', at }; } const pt = run.plan?.tasks?.find((x) => x.id === p.taskId); if (pt) pt.role = p.role; break; }
|
|
52
61
|
case 'task.posted': { const t = taskOf(run, p.taskId); if (t) t.job = p.job || null; if (p.job && !run.jobs.some((j) => j.id === p.job.id)) run.jobs.push({ ...p.job, taskId: p.taskId, at }); break; }
|
|
53
62
|
case 'task.proposed': { const t = taskOf(run, p.taskId); if (t) t.proposal = { agent: p.agent || null, threadId: p.threadId || null, postId: p.postId || null, why: p.why || '', at }; break; }
|
|
54
63
|
case 'task.unassigned': { const t = taskOf(run, p.taskId); if (t) { t.status = 'unassigned'; t.error = p.why || null; t.endedAt = at; } const j = run.jobs.find((x) => x.taskId === p.taskId); if (j) j.status = 'failed'; break; }
|
|
55
64
|
case 'task.nudged': { const t = taskOf(run, p.taskId); if (t) t.nudged = [...(t.nudged || []), { grants: p.grants || [], at }]; break; }
|
|
56
65
|
case 'run.role-added': if (p.role?.id && !run.roles.includes(p.role.id)) { run.roles.push(p.role.id); run.recruited = [...(run.recruited || []), { ...p.role, jobId: p.jobId || null, at }]; const j = run.jobs.find((x) => x.id === p.jobId); if (j) { j.status = 'recruited'; j.recruited = { agentId: p.role.agent || p.role.id, engine: p.role.engine || null, at }; } } break;
|
|
57
|
-
case 'task.started': {
|
|
66
|
+
case 'task.started': {
|
|
67
|
+
// A start the plan never named (a record from a build whose merge was not a task) gets
|
|
68
|
+
// its row here rather than being dropped — the fold never loses a task that ran.
|
|
69
|
+
let t = taskOf(run, p.taskId);
|
|
70
|
+
if (!t && p.taskId) { t = { id: p.taskId, role: p.role || null, title: p.title || p.taskId, status: 'pending', findings: 0, ...(p.taskId === 'merge' ? { kind: 'merge' } : {}) }; run.tasks.push(t); }
|
|
71
|
+
if (t) { t.status = 'running'; t.startedAt = at; t.error = null; }
|
|
72
|
+
run.status = 'running'; break;
|
|
73
|
+
}
|
|
58
74
|
case 'task.model': { const t = taskOf(run, p.taskId); if (t) { t.model = p.model; t.attempts = [...(t.attempts || []), { model: p.model, at, attempt: p.attempt }]; } break; }
|
|
59
75
|
case 'task.step': { const t = taskOf(run, p.taskId); if (t && Array.isArray(p.steps)) t.transcript = [...(t.transcript || []), ...p.steps]; break; }
|
|
60
76
|
case 'task.handoff': { const t = taskOf(run, p.taskId); if (t) { t.model = p.to; t.handoffs = [...(t.handoffs || []), { from: p.from, to: p.to, by: p.by, reason: p.reason, at }]; } break; }
|