@jabworks/condux 0.20.0 → 0.21.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/index.js +144 -13
- package/package.json +1 -1
- package/skills/condux-doctor/SKILL.md +4 -1
- package/skills/condux-doctor/doctor.mjs +19 -2
- package/skills/workflow/hooks/routing.md +4 -2
package/index.js
CHANGED
|
@@ -13,13 +13,18 @@
|
|
|
13
13
|
// separate `npx skills add` step for condux. This works because the config hook
|
|
14
14
|
// mutates the cached config before OpenCode lazily discovers skills.
|
|
15
15
|
//
|
|
16
|
-
// It also
|
|
17
|
-
//
|
|
18
|
-
//
|
|
19
|
-
//
|
|
20
|
-
//
|
|
21
|
-
//
|
|
22
|
-
//
|
|
16
|
+
// It also carries workflow's routing.md — the payload Claude Code and Codex
|
|
17
|
+
// get from their SessionStart hook — into the session as a `synthetic: true`
|
|
18
|
+
// `<system-reminder>` text part on the first user message of every *main*
|
|
19
|
+
// session (`chat.message`), re-injected after compaction. That is the shape
|
|
20
|
+
// OpenCode's own plan-mode reminders use (session/reminders.ts): it reaches
|
|
21
|
+
// the model in the user turn rather than mid-system-prompt, and it never
|
|
22
|
+
// reaches subagent sessions. Verified live on OpenCode 1.18.25 — the part
|
|
23
|
+
// persists (`chat.message` runs before the message is saved, and its parts
|
|
24
|
+
// array is the one written) and the model sees it. Per main-session turn it
|
|
25
|
+
// costs the same ~390 tokens as the `config.instructions` channel it replaces
|
|
26
|
+
// (docket #38 ratified that trade; docket #72 relocated the payload out of
|
|
27
|
+
// the system prompt and out of subagents).
|
|
23
28
|
//
|
|
24
29
|
// Optional plan-review listener (CONDUX_PLAN_REVIEW=1): when the primary
|
|
25
30
|
// `plan` agent finishes a turn (session.idle), spawns the plan-review annotate
|
|
@@ -29,6 +34,7 @@
|
|
|
29
34
|
|
|
30
35
|
import { existsSync, readFileSync, readdirSync } from 'node:fs';
|
|
31
36
|
import { spawn } from 'node:child_process';
|
|
37
|
+
import { randomBytes } from 'node:crypto';
|
|
32
38
|
import path from 'node:path';
|
|
33
39
|
import os from 'node:os';
|
|
34
40
|
import { fileURLToPath } from 'node:url';
|
|
@@ -62,6 +68,56 @@ function loadBundledAgents() {
|
|
|
62
68
|
return agents;
|
|
63
69
|
}
|
|
64
70
|
|
|
71
|
+
// The routing payload, framed the way OpenCode frames its own reminders. Null
|
|
72
|
+
// when routing.md is missing or empty — then the hook is a no-op, the same
|
|
73
|
+
// fail-open contract the Claude Code and Codex SessionStart scripts follow.
|
|
74
|
+
function loadRoutingReminder() {
|
|
75
|
+
if (!existsSync(ROUTING_MD)) return null;
|
|
76
|
+
const payload = readFileSync(ROUTING_MD, 'utf8').trim();
|
|
77
|
+
|
|
78
|
+
return payload ? `<system-reminder>\n${payload}\n</system-reminder>` : null;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// What the compaction summariser is asked to keep. The full reminder is
|
|
82
|
+
// re-injected on the next user message; this only stops the summary from
|
|
83
|
+
// describing a session in which the router never existed.
|
|
84
|
+
const COMPACTION_CONTEXT =
|
|
85
|
+
'Carry this rule into the summary: every implementation request in this session starts by loading the ' +
|
|
86
|
+
'`workflow` skill (`skill(name="workflow")`) before any other condux skill or any edit.';
|
|
87
|
+
|
|
88
|
+
// A part id in OpenCode's own ascending format — `prt_` + six big-endian bytes
|
|
89
|
+
// of (ms << 12 | counter) + fourteen base62 characters — so the reminder sorts
|
|
90
|
+
// among the parts OpenCode minted. The counter is pinned to its maximum: a
|
|
91
|
+
// part created in the same millisecond as the user's text must still order
|
|
92
|
+
// after it. The reminder follows the prompt, never precedes it.
|
|
93
|
+
const BASE62 = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
|
|
94
|
+
|
|
95
|
+
function partId() {
|
|
96
|
+
const stamp = BigInt(Date.now()) * 0x1000n + 0xfffn;
|
|
97
|
+
const bytes = Buffer.alloc(6);
|
|
98
|
+
for (let i = 0; i < 6; i++) bytes[i] = Number((stamp >> BigInt(40 - 8 * i)) & 0xffn);
|
|
99
|
+
let suffix = '';
|
|
100
|
+
for (const byte of randomBytes(14)) suffix += BASE62[byte % 62];
|
|
101
|
+
|
|
102
|
+
return `prt_${bytes.toString('hex')}${suffix}`;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// True when the session's stored history still shows the reminder to the
|
|
106
|
+
// model: a synthetic text part with exactly this text on a user message that
|
|
107
|
+
// comes after the last compaction. Compaction narrows the model's view to the
|
|
108
|
+
// summary plus a short tail, so a reminder on the far side of one counts as
|
|
109
|
+
// absent — the next user message gets it again.
|
|
110
|
+
export function historyIsRouted(messages, reminder) {
|
|
111
|
+
let routed = false;
|
|
112
|
+
for (const { info, parts = [] } of messages) {
|
|
113
|
+
if (parts.some((part) => part.type === 'compaction')) routed = false;
|
|
114
|
+
if (info?.role !== 'user') continue;
|
|
115
|
+
if (parts.some((part) => part.type === 'text' && part.synthetic === true && part.text === reminder)) routed = true;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
return routed;
|
|
119
|
+
}
|
|
120
|
+
|
|
65
121
|
// The annotate server ships inside the plan-review skill; look for it in every
|
|
66
122
|
// skill tree OpenCode discovers (project then global).
|
|
67
123
|
function findAnnotateServer(worktree) {
|
|
@@ -82,11 +138,54 @@ function findAnnotateServer(worktree) {
|
|
|
82
138
|
return null;
|
|
83
139
|
}
|
|
84
140
|
|
|
85
|
-
export const ConduxPlugin = async ({ worktree }) => {
|
|
141
|
+
export const ConduxPlugin = async ({ worktree, client }) => {
|
|
86
142
|
const bundled = loadBundledAgents();
|
|
143
|
+
const reminder = loadRoutingReminder();
|
|
87
144
|
const activeAgent = new Map();
|
|
145
|
+
// Sessions whose live history carries the reminder, as far as this process
|
|
146
|
+
// knows. A compaction clears the entry so the next user message re-injects.
|
|
147
|
+
const routed = new Set();
|
|
148
|
+
const isChild = new Map();
|
|
88
149
|
let warnedPayloadShape = false;
|
|
89
150
|
|
|
151
|
+
// Subagent sessions never get the router: their brief is the task the parent
|
|
152
|
+
// handed them, and "every request starts at workflow" contradicts coder's.
|
|
153
|
+
// The bundled agent names are the free path; the parent lookup catches every
|
|
154
|
+
// other child (OpenCode's own `general`, user-defined subagents) — `task`
|
|
155
|
+
// creates them with parentID set, and `chat.message` carries their agent
|
|
156
|
+
// name. Unknown counts as main: the instructions channel this replaces
|
|
157
|
+
// reached subagents too, so leaning toward injection is the known state.
|
|
158
|
+
async function isSubagentSession(input) {
|
|
159
|
+
if (input.agent && bundled[input.agent]?.mode === 'subagent') return true;
|
|
160
|
+
if (typeof client?.session?.get !== 'function') return false;
|
|
161
|
+
if (!isChild.has(input.sessionID)) {
|
|
162
|
+
try {
|
|
163
|
+
const { data } = await client.session.get({ path: { id: input.sessionID } });
|
|
164
|
+
isChild.set(input.sessionID, Boolean(data?.parentID));
|
|
165
|
+
} catch {
|
|
166
|
+
isChild.set(input.sessionID, false);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
return isChild.get(input.sessionID);
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
// On first sight of a session in this process — fresh, resumed, or after a
|
|
174
|
+
// compaction cleared it — ask the server whether the reminder is already in
|
|
175
|
+
// the model's view instead of trusting process memory: a resumed session
|
|
176
|
+
// would otherwise be injected twice, a compacted one never.
|
|
177
|
+
async function alreadyRouted(sessionID) {
|
|
178
|
+
if (routed.has(sessionID)) return true;
|
|
179
|
+
if (typeof client?.session?.messages !== 'function') return false;
|
|
180
|
+
try {
|
|
181
|
+
const { data } = await client.session.messages({ path: { id: sessionID } });
|
|
182
|
+
|
|
183
|
+
return Array.isArray(data) && historyIsRouted(data, reminder);
|
|
184
|
+
} catch {
|
|
185
|
+
return false;
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
|
|
90
189
|
return {
|
|
91
190
|
config: async (cfg) => {
|
|
92
191
|
cfg.agent ??= {};
|
|
@@ -116,13 +215,40 @@ export const ConduxPlugin = async ({ worktree }) => {
|
|
|
116
215
|
cfg.skills.paths ??= [];
|
|
117
216
|
if (!cfg.skills.paths.includes(SKILLS_DIR)) cfg.skills.paths.push(SKILLS_DIR);
|
|
118
217
|
}
|
|
218
|
+
// routing.md deliberately does NOT go on cfg.instructions any more: that
|
|
219
|
+
// channel is global (every subagent session read it) and lands mid
|
|
220
|
+
// system prompt. The reminder below is the replacement (docket #72).
|
|
221
|
+
},
|
|
222
|
+
|
|
223
|
+
// Route through workflow the way Claude Code and Codex do at SessionStart:
|
|
224
|
+
// one reminder on the first user message of a main session. Runs before
|
|
225
|
+
// the message is saved, so the pushed part is persisted with the rest.
|
|
226
|
+
'chat.message': async (input, output) => {
|
|
227
|
+
if (!reminder || !input?.sessionID || !output?.message?.id || !Array.isArray(output.parts)) return;
|
|
228
|
+
if (await isSubagentSession(input)) return;
|
|
229
|
+
if (await alreadyRouted(input.sessionID)) {
|
|
230
|
+
routed.add(input.sessionID);
|
|
119
231
|
|
|
120
|
-
|
|
121
|
-
// see the file-header comment for why `instructions` is the mechanism.
|
|
122
|
-
if (existsSync(ROUTING_MD)) {
|
|
123
|
-
cfg.instructions ??= [];
|
|
124
|
-
if (!cfg.instructions.includes(ROUTING_MD)) cfg.instructions.push(ROUTING_MD);
|
|
232
|
+
return;
|
|
125
233
|
}
|
|
234
|
+
|
|
235
|
+
output.parts.push({
|
|
236
|
+
id: partId(),
|
|
237
|
+
messageID: output.message.id,
|
|
238
|
+
sessionID: input.sessionID,
|
|
239
|
+
type: 'text',
|
|
240
|
+
synthetic: true,
|
|
241
|
+
text: reminder,
|
|
242
|
+
});
|
|
243
|
+
routed.add(input.sessionID);
|
|
244
|
+
},
|
|
245
|
+
|
|
246
|
+
// Compaction narrows the model's view to a summary plus a short tail. Ask
|
|
247
|
+
// the summariser to keep the rule; the next user message re-injects the
|
|
248
|
+
// full reminder (the `session.compacted` event below clears the session).
|
|
249
|
+
'experimental.session.compacting': async (input, output) => {
|
|
250
|
+
if (!reminder || !Array.isArray(output?.context)) return;
|
|
251
|
+
if (input?.sessionID && routed.has(input.sessionID)) output.context.push(COMPACTION_CONTEXT);
|
|
126
252
|
},
|
|
127
253
|
|
|
128
254
|
'chat.params': async (input) => {
|
|
@@ -130,6 +256,11 @@ export const ConduxPlugin = async ({ worktree }) => {
|
|
|
130
256
|
},
|
|
131
257
|
|
|
132
258
|
event: async ({ event }) => {
|
|
259
|
+
if (event.type === 'session.compacted') {
|
|
260
|
+
routed.delete(event.properties?.sessionID);
|
|
261
|
+
|
|
262
|
+
return;
|
|
263
|
+
}
|
|
133
264
|
if (process.env.CONDUX_PLAN_REVIEW !== '1') return;
|
|
134
265
|
if (event.type !== 'session.idle') return;
|
|
135
266
|
const sessionID = event.properties?.sessionID;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jabworks/condux",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.21.0",
|
|
4
4
|
"description": "OpenCode plugin for the condux workflow toolkit — bundles the condux skills and injects the specialist agents (coder, explorer, planner, researcher) plus an opt-in plan-review listener.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"publishConfig": {
|
|
@@ -46,7 +46,10 @@ else on the machine competes with it. Only `broken` affects the exit code.
|
|
|
46
46
|
- **plan-review's Codex Stop hook** — resolved, never executed. It blocks a
|
|
47
47
|
turn for up to four days waiting on a human by design.
|
|
48
48
|
- **OpenCode** — `@jabworks/condux` in the plugin array, and when a local
|
|
49
|
-
copy exists, that it ships its bundled `agents/` and `skills
|
|
49
|
+
copy exists, that it ships its bundled `agents/` and `skills/` and that the
|
|
50
|
+
routing reminder it injects names the OpenCode verb, `skill(name="workflow")`
|
|
51
|
+
— a payload still saying `/condux:workflow` is the docket #72 under-firing
|
|
52
|
+
shape, reported broken with an upgrade as the fix.
|
|
50
53
|
- **The four specialist agents** — `coder`, `explorer`, `planner`,
|
|
51
54
|
`researcher`. They live in a plugin-level directory reached by its own sync
|
|
52
55
|
step, which is exactly the mirror that drifted once before.
|
|
@@ -338,12 +338,29 @@ function probeOpencode(hosts) {
|
|
|
338
338
|
return {
|
|
339
339
|
host: 'opencode',
|
|
340
340
|
status: 'broken',
|
|
341
|
-
detail: 'the installed package ships no workflow/hooks/routing.md —
|
|
341
|
+
detail: 'the installed package ships no workflow/hooks/routing.md — the plugin has no routing reminder to inject',
|
|
342
342
|
fix: `reinstall ${PACKAGE}`,
|
|
343
343
|
};
|
|
344
344
|
}
|
|
345
345
|
|
|
346
|
-
|
|
346
|
+
// Since @jabworks/condux 0.21.0 the payload is rewritten for OpenCode:
|
|
347
|
+
// `/condux:workflow` is a Claude Code command the host cannot run, and a
|
|
348
|
+
// payload still naming it is the docket #72 under-firing shape — installed,
|
|
349
|
+
// but asking for a verb the model has to translate on its own.
|
|
350
|
+
if (!fs.readFileSync(routing, 'utf8').includes('skill(name="workflow")')) {
|
|
351
|
+
return {
|
|
352
|
+
host: 'opencode',
|
|
353
|
+
status: 'broken',
|
|
354
|
+
detail: 'the installed routing payload names /condux:workflow, which OpenCode cannot run — the reminder under-fires',
|
|
355
|
+
fix: `upgrade ${PACKAGE} to 0.21.0 or later`,
|
|
356
|
+
};
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
return {
|
|
360
|
+
host: 'opencode',
|
|
361
|
+
status: 'done',
|
|
362
|
+
detail: 'registered, and the installed package ships its agents, skills, and a routing reminder that names the OpenCode verb',
|
|
363
|
+
};
|
|
347
364
|
}
|
|
348
365
|
|
|
349
366
|
// The four specialist agents are plugin-level and reached by their own sync
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
<EXTREMELY_IMPORTANT>
|
|
2
2
|
You have condux — this session's agentic workflow system.
|
|
3
3
|
|
|
4
|
-
**Every implementation request starts at
|
|
4
|
+
**Every implementation request starts at the `workflow` skill — `skill(name="workflow")`.** Feature, bug fix,
|
|
5
5
|
refactor, new endpoint, UI change, "can you add…", "can you fix…" — all of it
|
|
6
6
|
routes there first. The router infers the tier (Small / Medium / Large), confirms
|
|
7
7
|
it with the user, then executes the matching flow, loading downstream skills only
|
|
@@ -13,7 +13,7 @@ when a step needs them.
|
|
|
13
13
|
`root-cause-analysis`, `live-verification`, `plan-review`, `technical-spec`.
|
|
14
14
|
|
|
15
15
|
If you find yourself reaching for one of those as the *first* skill of a task,
|
|
16
|
-
you have skipped the router — go back to
|
|
16
|
+
you have skipped the router — go back to the `workflow` skill — `skill(name="workflow")`. Debugging is the
|
|
17
17
|
most common miss: a crash report, a stack trace, or "why does this fail" is
|
|
18
18
|
still a dev task, so it routes through workflow, which loads
|
|
19
19
|
`root-cause-analysis` at the right moment.
|
|
@@ -25,4 +25,6 @@ user instructions — "skip workflow", "just do it", "I've already planned this"
|
|
|
25
25
|
**Not everything is a dev task.** Questions, explanations, code reading, research,
|
|
26
26
|
and one-line factual answers route nowhere — answer them directly. Routing a
|
|
27
27
|
conversation through a workflow is as wrong as skipping the router on a feature.
|
|
28
|
+
|
|
29
|
+
**On OpenCode, a `/name` mention of any condux skill means the `skill` tool:** `/workflow` → `skill(name="workflow")`, `/finalize` → `skill(name="finalize")`, and so on. None of them is a slash command here.
|
|
28
30
|
</EXTREMELY_IMPORTANT>
|