@inetafrica/open-claudia 2.6.59 → 2.7.1
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/CHANGELOG.md +11 -0
- package/bin/cli.js +1 -1
- package/bin/tool.js +177 -23
- package/core/recall/discoverer.js +71 -3
- package/core/system-prompt.js +14 -7
- package/core/tool-repo.js +270 -0
- package/core/tools.js +268 -59
- package/package.json +1 -1
- package/test-recall-discoverer.js +36 -1
- package/test-tools.js +139 -19
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## v2.7.1
|
|
4
|
+
- **The system prompt now teaches tool-FIRST, not tool-after (enforcement 5d).** The fixed "Reusable tools" section in `core/system-prompt.js` was the root cause of the baseline failure: it taught "crystallise the script you just wrote" — do the work raw, save a tool afterwards. Rewritten as "Tools are the interface": before operational work, walk the loop **search → use (read TOOL.md first, never guess args) → extend the missing verb → scaffold first** — and only then do the work *through* the tool. Raw one-liners and heredocs are demoted to probing/diagnosis; a broken tool gets fixed or journaled (`tool note --issue`), never routed around. The section also documents the risk gate honestly: the `--yes`/`--yes-destructive` flag is the agent's mechanical acknowledgment *after* the user approves — it never replaces asking first.
|
|
5
|
+
- **Tool-scout: operational turns can no longer meet silence (enforcement 5a).** Today an empty tool match is silent, and silence reads as permission to improvise. The discoverer now runs a pattern-based scout (no LLM, ~zero cost) over each seeds/full-tier turn: a table of high-precision operational domains — named hosts (central.inet.africa, ticket-central, chat-central, git.coders.africa…), prod IP ranges, infra commands (kubectl, argocd, mongosh…) — each with a `covers` matcher against the tool registry. When a turn trips a domain: if a registry tool covers it but wasn't auto-surfaced, the block points at it by name (`tool show X`, then work through it); if **nothing** covers it, the block says so and hands over the exact scaffold command (`tool scaffold <suggested-name> --risk write`). Domains already covered by a surfaced tool stay quiet, and non-operational chatter never trips the patterns (precision over recall — they expand from audit evidence later, per 5c). Gap signals flow into recall metrics (`toolGaps`) and the engine result for future `/tooltrace` surfacing. Extends `test-recall-discoverer.js` with pure-function and through-the-engine scout coverage.
|
|
6
|
+
|
|
7
|
+
## v2.7.0
|
|
8
|
+
- **Tools become memory objects (tool-first architecture, Phase 1).** A tool is no longer a flat script — it's a directory: `tools/<name>/tool` (the executable), `TOOL.md` (Interface · Known issues · State · Journal — the curated, human-readable condition of the tool), and `state.json` (machine telemetry, runtime-written, gitignored). The tools dir is now a **git repository**: every add, metadata change, note, and removal auto-commits (with a per-invocation identity, never touching git config), so `git log` *is* the upgrade history and any change is one revert from undone. `tool show` is tiered disclosure: header metadata, live telemetry, TOOL.md, and the recent commit log — the source only with `--source`, so reading about a tool no longer costs its whole body in context.
|
|
9
|
+
- **Risk tiers + run gate.** Every tool declares `risk: read-only | write | destructive` in its header (absent = treated as write, fail-safe). `tool run` now enforces the ask-first rule mechanically: read-only runs freely; write requires `--yes`; destructive requires `--yes-destructive` — and a plain `--yes` does **not** unlock a destructive tool. Refusals exit 3 with a clear message. The flags pass through to the tool unstripped, so tools with their own confirmation gates (e.g. prod-k8s) keep working. `tool add`/`tool set` accept `--risk`; adding without it defaults to write and says so.
|
|
10
|
+
- **Run telemetry stamped at the point of use.** `tool run` itself records every execution into the tool's `state.json`: run count, last used, last exit, last success/failure, per-verb health (first non-flag arg), and a rolling history of the last 20 invocations with timing. A failing run prints a nudge to journal the defect (`tool note <name> --issue "..."`). This is the v1.2 health doctrine in code: no smoke tests, no health crons — health is verified by use, and breakage is captured automatically where it happens.
|
|
11
|
+
- **`tool scaffold`, `tool note`, `tool migrate`.** `scaffold <name>` creates a ready-to-extend verb-dispatch stub (node or bash) with full header, TOOL.md skeleton, and initial telemetry — and refuses if the tool exists ("extend it instead"). `note <name> --issue|--state|--journal` maintains TOOL.md from the CLI: issues and journal lines insert newest-first; `--state` rewrites the State section (it describes *now*, not history). `migrate` converts legacy flat-file tools into directories — one commit each, sidecar telemetry carried over, TOOL.md generated — and runs automatically on first CLI use, so existing tools arrive in the new layout with their memory intact.
|
|
12
|
+
- **Secrets can no longer be saved into a tool.** The add-time secret lint is now **blocking** (was advisory): `tool add`, `tool set`, and `tool note` refuse content matching credential patterns, because the git-backed dir would remember the secret forever. Other lints (requires mismatch, syntax check, dangling pack) stay advisory. Extends `test-tools.js` end to end: layout, risk gate matrix, per-verb telemetry, secret refusal, migration, scaffold, git history.
|
|
13
|
+
|
|
3
14
|
## v2.6.58
|
|
4
15
|
- **Tiered recall gate — stop paying 15 seconds for "thanks".** Measured over 700+ live turns, the old discoverer pre-gate returned true whenever *any* seed matched, so it gated just 0.4% of turns — a bare "ok" with an incidental keyword hit still paid the full seed → graph → walker pass (p50 ~15s). A new `recallTier()` classifies each turn into three tiers: **skip** (pleasantries/acks up to 4 words *regardless of seeds*, emoji-only, or ≤2 words with no seeds — no recall at all), **seeds** (short command-like turns ≤4 words — user-origin keyword seeds inject directly with no graph expansion, no walker, no excerpts; the classic-engine baseline at ~ms cost), and **full** (substantive turns — the whole pipeline). The tier is logged per turn and the metrics summary now tracks the seeds-only share alongside the gated share.
|
|
5
16
|
- **Walker candidate cap.** The latency deep-dive showed the walk itself dominates, not process spawn: 15–40 candidates × 600-char excerpts = 10–25KB prompts to the haiku judge on every substantive turn. Full-tier candidates are now priority-ordered — user-origin seeds by match score, then context seeds, then graph-activated nodes by activation — and capped at `RECALL_WALKER_MAX_CANDIDATES` (default 14), so the judge reads the strongest few instead of everything the graph touched.
|
package/bin/cli.js
CHANGED
|
@@ -374,7 +374,7 @@ Memory tools:
|
|
|
374
374
|
open-claudia transcript-window <pattern> Search project transcript, show hits with context
|
|
375
375
|
(alias: tw; --help for options)
|
|
376
376
|
open-claudia pack list|show|match|archive|restore|archived Context packs: living topic docs (skills + memory)
|
|
377
|
-
open-claudia tool list|search|show|add|set|edit|run|remove
|
|
377
|
+
open-claudia tool list|search|show|scaffold|add|set|note|edit|run|migrate|remove Reusable tools: git-tracked dirs (exec + TOOL.md + telemetry), risk-gated runs
|
|
378
378
|
open-claudia entity list|show|match|note Entity notes: people/places/projects memory
|
|
379
379
|
open-claudia lessons list|add|remove|show Always-loaded learned rules (cross-cutting, promoted after a miss)
|
|
380
380
|
open-claudia ideas list|add|remove|show Self-improvement backlog (captured by the nightly dream)
|
package/bin/tool.js
CHANGED
|
@@ -1,23 +1,38 @@
|
|
|
1
|
-
// CLI: manage and run reusable tools —
|
|
2
|
-
//
|
|
3
|
-
//
|
|
1
|
+
// CLI: manage and run reusable tools — the interface operational work happens
|
|
2
|
+
// through. Tool-first loop: search → exists: use it → missing a verb: extend →
|
|
3
|
+
// nothing: scaffold, then work through the tool.
|
|
4
4
|
//
|
|
5
5
|
// open-claudia tool list — index (name — description [skill])
|
|
6
6
|
// open-claudia tool search <query> — lexical match (find before adding a dup)
|
|
7
|
-
// open-claudia tool show <name>
|
|
8
|
-
// open-claudia tool
|
|
9
|
-
// [--pack <dir>] [--desc "..."] [--
|
|
7
|
+
// open-claudia tool show <name> [--source] — TOOL.md, telemetry, history (source with --source)
|
|
8
|
+
// open-claudia tool scaffold <name> — create a new tool skeleton (dir + stub + TOOL.md)
|
|
9
|
+
// [--pack <dir>] [--desc "..."] [--risk read-only|write|destructive]
|
|
10
|
+
// [--requires "k1,k2"] [--usage "..."] [--lang node|bash]
|
|
11
|
+
// open-claudia tool add <path> [--name n] — register an existing script as a tool
|
|
12
|
+
// [--pack <dir>] [--desc "..."] [--risk tier] [--requires "k1,k2"] [--usage "..."]
|
|
10
13
|
// open-claudia tool set <name> [--desc ...] — fix a tool's metadata in place
|
|
11
|
-
// [--pack <dir>] [--requires "k1,k2"] [--usage "..."]
|
|
14
|
+
// [--pack <dir>] [--risk tier] [--requires "k1,k2"] [--usage "..."]
|
|
15
|
+
// open-claudia tool note <name> — append to TOOL.md (auto-committed)
|
|
16
|
+
// [--issue "..."] [--state "..."] [--journal "..."]
|
|
12
17
|
// open-claudia tool edit <name> — print the file path to open & edit
|
|
13
|
-
// open-claudia tool run <name> [args...] — run it
|
|
18
|
+
// open-claudia tool run <name> [args...] — run it (keyring pre-loaded, risk-gated)
|
|
19
|
+
// open-claudia tool migrate — convert legacy flat-file tools to directories
|
|
14
20
|
// open-claudia tool remove <name> — delete one
|
|
15
21
|
// open-claudia tool path — print the tools directory
|
|
16
22
|
//
|
|
17
|
-
//
|
|
18
|
-
//
|
|
19
|
-
//
|
|
20
|
-
//
|
|
23
|
+
// A tool is a directory: executable + TOOL.md (Interface · Known issues ·
|
|
24
|
+
// State · Journal) + state.json (runtime telemetry). The dir is git-tracked;
|
|
25
|
+
// every change commits, so `git -C $(open-claudia tool path) log` is the
|
|
26
|
+
// upgrade history.
|
|
27
|
+
//
|
|
28
|
+
// Risk tiers gate `tool run`: write-tier needs --yes, destructive-tier needs
|
|
29
|
+
// --yes-destructive — get the user's approval first; the flag records that
|
|
30
|
+
// deliberate step. Read-only tools run freely.
|
|
31
|
+
//
|
|
32
|
+
// Fix before fork: when a tool is wrong, prefer `tool set` (metadata), `tool
|
|
33
|
+
// note` (docs), or `tool edit` (body) over adding a near-duplicate. Hardcoded
|
|
34
|
+
// secrets BLOCK a save; other lints (requires/keyring mismatch, syntax,
|
|
35
|
+
// dangling pack link) stay advisory.
|
|
21
36
|
//
|
|
22
37
|
// Credentials: a tool runs with the operational keyring merged into its env, so
|
|
23
38
|
// reference creds as $NAME inside the script. `open-claudia keyring list` shows
|
|
@@ -25,6 +40,7 @@
|
|
|
25
40
|
|
|
26
41
|
const { spawnSync } = require("child_process");
|
|
27
42
|
const tools = require("../core/tools");
|
|
43
|
+
const repo = require("../core/tool-repo");
|
|
28
44
|
|
|
29
45
|
// Minimal flag parser: pulls --key value (and --key=value) out of argv, returns
|
|
30
46
|
// { positional, flags }.
|
|
@@ -88,6 +104,17 @@ function run(args) {
|
|
|
88
104
|
const cmd = (args[0] || "list").toLowerCase();
|
|
89
105
|
const rest = args.slice(1);
|
|
90
106
|
|
|
107
|
+
// Auto-migrate legacy flat-file tools to the directory layout on first use
|
|
108
|
+
// (idempotent, one git commit per tool, telemetry carried over).
|
|
109
|
+
if (cmd !== "path") {
|
|
110
|
+
try {
|
|
111
|
+
if (repo.hasLegacyTools()) {
|
|
112
|
+
const { migrated } = repo.migrateLegacyTools();
|
|
113
|
+
if (migrated.length) console.error(`(migrated ${migrated.length} tool(s) to directory layout: ${migrated.join(", ")})`);
|
|
114
|
+
}
|
|
115
|
+
} catch (e) { /* best-effort */ }
|
|
116
|
+
}
|
|
117
|
+
|
|
91
118
|
switch (cmd) {
|
|
92
119
|
case "list":
|
|
93
120
|
case "ls": {
|
|
@@ -98,7 +125,8 @@ function run(args) {
|
|
|
98
125
|
console.log(`${all.length} reusable tool(s) — run via 'open-claudia tool run <name>':\n`);
|
|
99
126
|
for (const t of all) {
|
|
100
127
|
const skill = t.pack ? ` [skill: ${t.pack}]` : "";
|
|
101
|
-
|
|
128
|
+
const risk = t.risk === "read-only" ? "" : ` [${t.risk || "write?"}]`;
|
|
129
|
+
console.log(`• ${t.name} — ${t.description || "(no description)"}${skill}${risk}`);
|
|
102
130
|
}
|
|
103
131
|
console.log(`\nDocs: open-claudia tool show <name> · Dir: ${tools.TOOLS_DIR}`);
|
|
104
132
|
break;
|
|
@@ -125,13 +153,15 @@ function run(args) {
|
|
|
125
153
|
|
|
126
154
|
case "show":
|
|
127
155
|
case "cat": {
|
|
128
|
-
const
|
|
129
|
-
|
|
156
|
+
const { positional, flags } = parseFlags(rest);
|
|
157
|
+
const name = positional[0];
|
|
158
|
+
if (!name) { console.error("Usage: tool show <name> [--source]"); process.exitCode = 1; return; }
|
|
130
159
|
const t = tools.findTool(name);
|
|
131
160
|
if (!t) { console.error(`No tool named "${name}". Run: open-claudia tool list`); process.exitCode = 1; return; }
|
|
132
161
|
console.log(`Tool: ${t.name}`);
|
|
133
162
|
if (t.description) console.log(`Description: ${t.description}`);
|
|
134
163
|
if (t.pack) console.log(`Skill pack: ${t.pack} (open-claudia pack show ${t.pack})`);
|
|
164
|
+
console.log(`Risk: ${t.risk || "(undeclared — treated as write)"}`);
|
|
135
165
|
console.log(`Usage: open-claudia tool run ${t.name}${t.usage ? " (" + t.usage + ")" : ""}`);
|
|
136
166
|
if (t.requires.length) {
|
|
137
167
|
const missing = tools.missingRequires(t);
|
|
@@ -139,6 +169,22 @@ function run(args) {
|
|
|
139
169
|
console.log(`Requires keyring keys: ${t.requires.join(", ")} (${status})`);
|
|
140
170
|
}
|
|
141
171
|
console.log(`File: ${t.file}${t.executable ? "" : " (not executable!)"}`);
|
|
172
|
+
|
|
173
|
+
// Telemetry: overall + per-verb health from state.json.
|
|
174
|
+
if (t.runCount || t.lastUsed) {
|
|
175
|
+
const exit = t.lastExit === undefined ? "" : ` · last exit ${t.lastExit}`;
|
|
176
|
+
console.log(`Runs: ${t.runCount}${t.lastUsed ? ` · last used ${t.lastUsed.slice(0, 16).replace("T", " ")}` : ""}${exit}`);
|
|
177
|
+
}
|
|
178
|
+
if (t.verbs && Object.keys(t.verbs).length) {
|
|
179
|
+
const rows = Object.entries(t.verbs).map(([v, s]) =>
|
|
180
|
+
` • ${v}: ${s.runs} run(s), last exit ${s.lastExit}${s.lastSuccess ? `, last success ${s.lastSuccess.slice(0, 10)}` : ""}`);
|
|
181
|
+
console.log("Verbs:\n" + rows.join("\n"));
|
|
182
|
+
}
|
|
183
|
+
try {
|
|
184
|
+
const log = repo.toolLog(t.name, 5);
|
|
185
|
+
if (log.length) console.log("Recent changes:\n" + log.map((l) => " " + l).join("\n"));
|
|
186
|
+
} catch (e) { /* git optional */ }
|
|
187
|
+
|
|
142
188
|
// Directed tool-graph: what tends to run right after / before this one.
|
|
143
189
|
try {
|
|
144
190
|
const graph = require("../core/tool-graph");
|
|
@@ -156,7 +202,13 @@ function run(args) {
|
|
|
156
202
|
}
|
|
157
203
|
}
|
|
158
204
|
} catch (e) { /* graph optional (old node) */ }
|
|
159
|
-
|
|
205
|
+
|
|
206
|
+
// Tiered disclosure: TOOL.md is the manual; source only when modifying.
|
|
207
|
+
const doc = tools.readToolDoc(t.name);
|
|
208
|
+
if (doc) console.log(`\n----- TOOL.md -----\n${doc.trim()}`);
|
|
209
|
+
if (flags.source) console.log(`\n----- source -----\n${t.content}`);
|
|
210
|
+
else if (!doc) console.log(`\n----- source (no TOOL.md yet) -----\n${t.content}`);
|
|
211
|
+
else console.log(`\n(source: open-claudia tool show ${t.name} --source)`);
|
|
160
212
|
break;
|
|
161
213
|
}
|
|
162
214
|
|
|
@@ -173,10 +225,14 @@ function run(args) {
|
|
|
173
225
|
name: typeof flags.name === "string" ? flags.name : undefined,
|
|
174
226
|
pack: typeof flags.pack === "string" ? flags.pack : undefined,
|
|
175
227
|
description: typeof flags.desc === "string" ? flags.desc : (typeof flags.description === "string" ? flags.description : undefined),
|
|
228
|
+
risk: typeof flags.risk === "string" ? flags.risk : undefined,
|
|
176
229
|
requires: typeof flags.requires === "string" ? flags.requires.split(/[,\s]+/).filter(Boolean) : undefined,
|
|
177
230
|
usage: typeof flags.usage === "string" ? flags.usage : undefined,
|
|
178
231
|
});
|
|
179
|
-
console.log(`Saved tool "${t.name}"${t.pack ? ` (skill: ${t.pack})` : ""}.`);
|
|
232
|
+
console.log(`Saved tool "${t.name}"${t.pack ? ` (skill: ${t.pack})` : ""} — risk: ${t.risk}.`);
|
|
233
|
+
if (t.defaultedRisk) {
|
|
234
|
+
console.log(` No --risk given → defaulted to "write" (runs will demand --yes). If it only reads, fix: open-claudia tool set ${t.name} --risk read-only`);
|
|
235
|
+
}
|
|
180
236
|
console.log(`Run it: open-claudia tool run ${t.name}`);
|
|
181
237
|
if (t.requires.length) {
|
|
182
238
|
const missing = tools.missingRequires(t);
|
|
@@ -217,17 +273,21 @@ function run(args) {
|
|
|
217
273
|
if (typeof flags.desc === "string") patch.description = flags.desc;
|
|
218
274
|
else if (typeof flags.description === "string") patch.description = flags.description;
|
|
219
275
|
if (typeof flags.pack === "string") patch.pack = flags.pack;
|
|
276
|
+
if (typeof flags.risk === "string") patch.risk = flags.risk;
|
|
220
277
|
if (typeof flags.requires === "string") patch.requires = flags.requires.split(/[,\s]+/).filter(Boolean);
|
|
221
278
|
if (typeof flags.usage === "string") patch.usage = flags.usage;
|
|
222
279
|
if (Object.keys(patch).length === 0) {
|
|
223
|
-
console.error('Nothing to set. Pass at least one of --desc / --pack / --requires / --usage. Body edits: open-claudia tool edit ' + name);
|
|
280
|
+
console.error('Nothing to set. Pass at least one of --desc / --pack / --risk / --requires / --usage. Body edits: open-claudia tool edit ' + name);
|
|
224
281
|
process.exitCode = 1; return;
|
|
225
282
|
}
|
|
226
|
-
|
|
283
|
+
let updated;
|
|
284
|
+
try { updated = tools.updateToolHeader(name, patch); }
|
|
285
|
+
catch (e) { console.error(`Could not update "${name}": ${e.message}`); process.exitCode = 1; return; }
|
|
227
286
|
if (!updated) { console.error(`Could not update "${name}".`); process.exitCode = 1; return; }
|
|
228
287
|
console.log(`Updated tool "${updated.name}".`);
|
|
229
288
|
console.log(` Description: ${updated.description || "(none)"}`);
|
|
230
289
|
if (updated.pack) console.log(` Skill pack: ${updated.pack}`);
|
|
290
|
+
console.log(` Risk: ${updated.risk || "(undeclared — treated as write)"}`);
|
|
231
291
|
if (updated.requires.length) console.log(` Requires: ${updated.requires.join(", ")}`);
|
|
232
292
|
if (updated.usage) console.log(` Usage: ${updated.usage}`);
|
|
233
293
|
reportSafety(updated);
|
|
@@ -252,14 +312,108 @@ function run(args) {
|
|
|
252
312
|
if (!name) { console.error("Usage: tool run <name> [args...]"); process.exitCode = 1; return; }
|
|
253
313
|
const t = tools.findTool(name);
|
|
254
314
|
if (!t) { console.error(`No tool named "${name}". Run: open-claudia tool list`); process.exitCode = 1; return; }
|
|
315
|
+
const toolArgs = rest.slice(1);
|
|
316
|
+
|
|
317
|
+
// Risk-tier gate: write needs --yes, destructive needs --yes-destructive.
|
|
318
|
+
// The flag is passed through to the tool (which may have its own gate).
|
|
319
|
+
const gate = tools.runGate(t, toolArgs);
|
|
320
|
+
if (!gate.ok) { console.error(gate.message); process.exitCode = 3; return; }
|
|
321
|
+
|
|
255
322
|
const missing = tools.missingRequires(t);
|
|
256
323
|
if (missing.length) {
|
|
257
324
|
console.error(`Cannot run ${t.name}: missing keyring keys ${missing.join(", ")}. Set them with 'open-claudia keyring set <name> <value>'.`);
|
|
258
325
|
process.exitCode = 1; return;
|
|
259
326
|
}
|
|
260
|
-
const
|
|
261
|
-
|
|
262
|
-
|
|
327
|
+
const started = Date.now();
|
|
328
|
+
const r = spawnSync(t.file, toolArgs, { stdio: "inherit", env: tools.runEnv() });
|
|
329
|
+
const ms = Date.now() - started;
|
|
330
|
+
if (r.error) {
|
|
331
|
+
tools.recordRunResult(t.name, { args: toolArgs, exit: -1, ms });
|
|
332
|
+
console.error(`Failed to run ${t.name}: ${r.error.message}`);
|
|
333
|
+
process.exitCode = 1; return;
|
|
334
|
+
}
|
|
335
|
+
const exit = typeof r.status === "number" ? r.status : 1;
|
|
336
|
+
tools.recordRunResult(t.name, { args: toolArgs, exit, ms });
|
|
337
|
+
if (exit !== 0) {
|
|
338
|
+
console.error(`(exit ${exit} recorded in ${t.name} telemetry — if this is a real defect, journal it: ` +
|
|
339
|
+
`open-claudia tool note ${t.name} --issue "<what broke>")`);
|
|
340
|
+
}
|
|
341
|
+
process.exitCode = exit;
|
|
342
|
+
break;
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
case "scaffold":
|
|
346
|
+
case "new": {
|
|
347
|
+
const { positional, flags } = parseFlags(rest);
|
|
348
|
+
const name = positional[0];
|
|
349
|
+
if (!name) {
|
|
350
|
+
console.error('Usage: tool scaffold <name> [--pack dir] [--desc "..."] [--risk read-only|write|destructive] [--requires "k1,k2"] [--usage "..."] [--lang node|bash]');
|
|
351
|
+
process.exitCode = 1; return;
|
|
352
|
+
}
|
|
353
|
+
try {
|
|
354
|
+
const t = repo.scaffoldTool(name, {
|
|
355
|
+
pack: typeof flags.pack === "string" ? flags.pack : undefined,
|
|
356
|
+
description: typeof flags.desc === "string" ? flags.desc : (typeof flags.description === "string" ? flags.description : undefined),
|
|
357
|
+
risk: typeof flags.risk === "string" ? flags.risk : undefined,
|
|
358
|
+
requires: typeof flags.requires === "string" ? flags.requires.split(/[,\s]+/).filter(Boolean) : [],
|
|
359
|
+
usage: typeof flags.usage === "string" ? flags.usage : undefined,
|
|
360
|
+
lang: typeof flags.lang === "string" ? flags.lang : "node",
|
|
361
|
+
});
|
|
362
|
+
console.log(`Scaffolded tool "${t.name}" (risk: ${t.risk}).`);
|
|
363
|
+
console.log(` Executable: ${t.file}`);
|
|
364
|
+
console.log(` Docs: ${t.docFile}`);
|
|
365
|
+
console.log(`Fill in the verbs, then work through it: open-claudia tool run ${t.name} <verb>`);
|
|
366
|
+
} catch (e) {
|
|
367
|
+
console.error(`Could not scaffold: ${e.message}`); process.exitCode = 1;
|
|
368
|
+
}
|
|
369
|
+
break;
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
case "note": {
|
|
373
|
+
const { positional, flags } = parseFlags(rest);
|
|
374
|
+
const name = positional[0];
|
|
375
|
+
const issue = typeof flags.issue === "string" ? flags.issue : null;
|
|
376
|
+
const state = typeof flags.state === "string" ? flags.state : null;
|
|
377
|
+
const journal = typeof flags.journal === "string" ? flags.journal : null;
|
|
378
|
+
if (!name || (!issue && !state && !journal)) {
|
|
379
|
+
console.error('Usage: tool note <name> [--issue "..."] [--state "..."] [--journal "..."]');
|
|
380
|
+
process.exitCode = 1; return;
|
|
381
|
+
}
|
|
382
|
+
const t = tools.findTool(name);
|
|
383
|
+
if (!t) { console.error(`No tool named "${name}". Run: open-claudia tool list`); process.exitCode = 1; return; }
|
|
384
|
+
if (!t.docFile) { console.error(`"${t.name}" is a legacy flat tool — run any tool command to migrate it first.`); process.exitCode = 1; return; }
|
|
385
|
+
try {
|
|
386
|
+
tools.assertNoSecrets([issue, state, journal].filter(Boolean).join("\n"), "note");
|
|
387
|
+
const fs = require("fs");
|
|
388
|
+
let doc = tools.readToolDoc(t.name) || repo.toolMdSkeleton(t);
|
|
389
|
+
const date = new Date().toISOString().slice(0, 10);
|
|
390
|
+
const appendUnder = (heading, line) => {
|
|
391
|
+
const re = new RegExp(`(##\\s*${heading}[^\\n]*\\n)`, "i");
|
|
392
|
+
if (re.test(doc)) doc = doc.replace(re, `$1${line}\n`);
|
|
393
|
+
else doc += `\n## ${heading}\n${line}\n`;
|
|
394
|
+
};
|
|
395
|
+
if (issue) appendUnder("Known issues", `- [${date}] ${issue}`);
|
|
396
|
+
if (state) {
|
|
397
|
+
// State is a rewrite, not an append — it describes NOW.
|
|
398
|
+
const re = /(##\s*State[^\n]*\n)([\s\S]*?)(?=\n##\s|$)/i;
|
|
399
|
+
if (re.test(doc)) doc = doc.replace(re, `$1${state}\n\n`);
|
|
400
|
+
else doc += `\n## State\n${state}\n`;
|
|
401
|
+
}
|
|
402
|
+
if (journal) appendUnder("Journal", `- [${date}] ${journal}`);
|
|
403
|
+
fs.writeFileSync(t.docFile, doc, { mode: 0o600 });
|
|
404
|
+
repo.commitTool(t.name, `note ${t.name}: ${(issue || state || journal).slice(0, 60)}`);
|
|
405
|
+
console.log(`Noted in ${t.name}/TOOL.md${issue ? " (known issue)" : ""}${state ? " (state)" : ""}${journal ? " (journal)" : ""}.`);
|
|
406
|
+
} catch (e) {
|
|
407
|
+
console.error(`Could not note: ${e.message}`); process.exitCode = 1;
|
|
408
|
+
}
|
|
409
|
+
break;
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
case "migrate": {
|
|
413
|
+
const { migrated, skipped } = repo.migrateLegacyTools();
|
|
414
|
+
if (!migrated.length && !skipped.length) console.log("Nothing to migrate — all tools already use the directory layout.");
|
|
415
|
+
if (migrated.length) console.log(`Migrated: ${migrated.join(", ")}`);
|
|
416
|
+
if (skipped.length) console.log(`Skipped (no tool header — left untouched): ${skipped.join(", ")}`);
|
|
263
417
|
break;
|
|
264
418
|
}
|
|
265
419
|
|
|
@@ -277,7 +431,7 @@ function run(args) {
|
|
|
277
431
|
break;
|
|
278
432
|
|
|
279
433
|
default:
|
|
280
|
-
console.log('Usage: open-claudia tool [list | search <query> | show <name> | add <path> [flags] | set <name> [flags] | edit <name> | run <name> [args] | remove <name> | path]');
|
|
434
|
+
console.log('Usage: open-claudia tool [list | search <query> | show <name> [--source] | scaffold <name> [flags] | add <path> [flags] | set <name> [flags] | note <name> [flags] | edit <name> | run <name> [args] | migrate | remove <name> | path]');
|
|
281
435
|
}
|
|
282
436
|
}
|
|
283
437
|
|
|
@@ -27,6 +27,65 @@ const toolsLib = require("../tools");
|
|
|
27
27
|
// entity-only). Optional — absent on old node where node:sqlite is missing.
|
|
28
28
|
let toolGraph = null;
|
|
29
29
|
try { toolGraph = require("../tool-graph"); } catch (e) { /* old node */ }
|
|
30
|
+
|
|
31
|
+
// ── Tool-scout (enforcement 5a): operational-domain gap detection ────────────
|
|
32
|
+
// When a turn looks operational, an empty tool match must not stay silent —
|
|
33
|
+
// silence reads as permission to improvise a raw script. v1 is pure patterns,
|
|
34
|
+
// no LLM: `test` decides the turn touches an operational domain (named hosts,
|
|
35
|
+
// prod IPs, infra commands — precision over recall so local/dev chatter never
|
|
36
|
+
// trips it); `covers` finds a registry tool that fronts that domain (matched
|
|
37
|
+
// on name + description); `slug` is the suggested scaffold name when nothing
|
|
38
|
+
// in the registry covers it. Patterns expand from audit evidence (5c).
|
|
39
|
+
const OPERATIONAL_DOMAINS = [
|
|
40
|
+
{ label: "Kubernetes cluster ops", test: /\bkubectl\b|\bargocd\b|control[- ]plane|\brollout (?:status|restart|history)\b/i, covers: /k8s|kubernetes|kubectl|cluster/i, slug: "prod-k8s" },
|
|
41
|
+
{ label: "in-cluster MongoDB", test: /\bmongosh\b|\bmongo\b[^\n]*--eval|\bdb\.\w+\.(?:find|update\w*|delete\w*|insert\w*|aggregate)\(/i, covers: /mongo|k8s/i, slug: "prod-k8s" },
|
|
42
|
+
{ label: "inet-central platform API", test: /central\.inet\.africa|\binet[- ]central\b/i, covers: /inet[- ]?central/i, slug: "inet-central-cli" },
|
|
43
|
+
{ label: "ticket-central API", test: /ticketcentral|\bticket[- ]central\b/i, covers: /\bticket/i, slug: "kticket" },
|
|
44
|
+
{ label: "kazee chat-central API", test: /\bchat[- ]central\b/i, covers: /kazee-chat|chat/i, slug: "kchat" },
|
|
45
|
+
{ label: "kazee spaces API", test: /spaces\.kazee|\bspaces[- ]central\b/i, covers: /spaces/i, slug: "spaces" },
|
|
46
|
+
{ label: "GitLab / coders.africa", test: /git\.coders\.africa|codersafrica@|\bgitlab\b/i, covers: /gitlab|coders/i, slug: "gitlab-ops" },
|
|
47
|
+
{ label: "MikroTik / RouterOS", test: /mikrotik|routeros|winbox|\/rest\/(?:ip|ppp|queue)\b/i, covers: /mikrotik|routeros/i, slug: "mikrotik" },
|
|
48
|
+
{ label: "iNet radius/ops backend", test: /radius\.inet\.africa|ops\.inet\.africa/i, covers: /radius|pppoe/i, slug: "inet-radius" },
|
|
49
|
+
{ label: "production network host", test: /\b10\.200\.\d{1,3}\.\d{1,3}\b|\b102\.222\.4\.\d{1,3}\b/, covers: null, slug: "" },
|
|
50
|
+
];
|
|
51
|
+
|
|
52
|
+
// Pure + exported for tests. Returns [{ label, kind: "use", tool }] when a
|
|
53
|
+
// registry tool covers a tripped domain but was not surfaced this turn, or
|
|
54
|
+
// [{ label, kind: "scaffold", slug }] when nothing in the registry covers it.
|
|
55
|
+
// Domains already covered by a surfaced (kept) tool produce no signal.
|
|
56
|
+
function scoutToolGaps(userText, keptToolNames, allTools) {
|
|
57
|
+
const text = String(userText || "");
|
|
58
|
+
if (!text) return [];
|
|
59
|
+
let all = allTools;
|
|
60
|
+
if (!all) { try { all = toolsLib.listTools(); } catch (e) { return []; } }
|
|
61
|
+
const kept = [...(keptToolNames || [])].map((n) => String(n).toLowerCase());
|
|
62
|
+
const gaps = [];
|
|
63
|
+
const seen = new Set();
|
|
64
|
+
for (const d of OPERATIONAL_DOMAINS) {
|
|
65
|
+
if (!d.test.test(text)) continue;
|
|
66
|
+
if (d.covers && kept.some((n) => d.covers.test(n))) continue;
|
|
67
|
+
const hit = d.covers
|
|
68
|
+
? all.find((t) => d.covers.test(t.name) || d.covers.test(String(t.description || "")))
|
|
69
|
+
: null;
|
|
70
|
+
if (hit && kept.includes(hit.name.toLowerCase())) continue;
|
|
71
|
+
const g = hit
|
|
72
|
+
? { label: d.label, kind: "use", tool: hit.name }
|
|
73
|
+
: { label: d.label, kind: "scaffold", slug: d.slug || "" };
|
|
74
|
+
const key = g.kind + ":" + (g.tool || g.slug || g.label);
|
|
75
|
+
if (seen.has(key)) continue;
|
|
76
|
+
seen.add(key);
|
|
77
|
+
gaps.push(g);
|
|
78
|
+
}
|
|
79
|
+
return gaps;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function renderToolGaps(gaps) {
|
|
83
|
+
if (!gaps || !gaps.length) return "";
|
|
84
|
+
const lines = gaps.map((g) => g.kind === "use"
|
|
85
|
+
? `- ${g.label}: covered by existing tool \`${g.tool}\` (not auto-surfaced this turn) — \`open-claudia tool show ${g.tool}\`, then work through it.`
|
|
86
|
+
: `- ${g.label}: NO tool covers this domain. Scaffold before improvising: \`open-claudia tool scaffold ${g.slug || "<system-name>"} --desc "<what it fronts>" --risk write\` — implement the verb you need, then do the work through it.`);
|
|
87
|
+
return `\n\n## Tool-first check (operational turn)\nThis turn touches operational domains. Do the operational work THROUGH a tool — raw one-liners only to probe:\n${lines.join("\n")}\n`;
|
|
88
|
+
}
|
|
30
89
|
// Episodic memory: FTS over past transcripts (same optionality as the graphs).
|
|
31
90
|
let transcriptIndex = null;
|
|
32
91
|
try { transcriptIndex = require("../transcript-index"); } catch (e) { /* old node */ }
|
|
@@ -236,7 +295,7 @@ async function run(ctx) {
|
|
|
236
295
|
const tier = recallTier(userText, seedCount);
|
|
237
296
|
if (tier === "skip") {
|
|
238
297
|
metrics.logTurn({ engine: "discoverer", model: WALKER_MODEL, query: userText, gated: true, tier, latencyMs: Date.now() - started });
|
|
239
|
-
return { packBlock: "", entityBlock: "", toolBlock: "", episodeBlock: "", packMatches: [], entityMatches: [], toolMatches: [], episodeMatches: [], why: {}, gated: true, tier };
|
|
298
|
+
return { packBlock: "", entityBlock: "", toolBlock: "", episodeBlock: "", packMatches: [], entityMatches: [], toolMatches: [], toolGaps: [], episodeMatches: [], why: {}, gated: true, tier };
|
|
240
299
|
}
|
|
241
300
|
|
|
242
301
|
// 3: spreading activation from seeds across the graph (full tier only — the
|
|
@@ -464,6 +523,14 @@ async function run(ctx) {
|
|
|
464
523
|
toolBlock = `\n\n## Tools that may help here\nSurfaced for this turn — run with \`open-claudia tool run <name> [args]\`; read docs/source with \`open-claudia tool show <name>\`:\n${lines.join("\n")}\n`;
|
|
465
524
|
}
|
|
466
525
|
|
|
526
|
+
// 5a tool-scout: replace the silence of an empty/partial tool match with an
|
|
527
|
+
// explicit use-this-tool or scaffold-first signal on operational turns. Runs
|
|
528
|
+
// on both seeds and full tiers (short command-like turns are exactly the
|
|
529
|
+
// operational ones); skip-tier pleasantries never reach here.
|
|
530
|
+
let toolGaps = [];
|
|
531
|
+
try { toolGaps = scoutToolGaps(userText, toolMatches.map((m) => m.name)); } catch (e) {}
|
|
532
|
+
if (toolGaps.length) toolBlock += renderToolGaps(toolGaps);
|
|
533
|
+
|
|
467
534
|
// Past-conversation episodes the walker kept (fail-open drops them — an
|
|
468
535
|
// unjudged transcript snippet is a guess, not a memory).
|
|
469
536
|
const episodeMatches = episodeCands
|
|
@@ -497,12 +564,13 @@ async function run(ctx) {
|
|
|
497
564
|
walkerMs: walkRes.walkerMs,
|
|
498
565
|
walker: walkRes.source,
|
|
499
566
|
costUsd: walkRes.costUsd || 0,
|
|
567
|
+
toolGaps: toolGaps.length ? toolGaps.map((g) => `${g.kind}:${g.tool || g.slug || g.label}`) : undefined,
|
|
500
568
|
});
|
|
501
569
|
|
|
502
570
|
return {
|
|
503
571
|
packBlock, entityBlock, toolBlock, episodeBlock, packMatches: finalPacks, entityMatches: finalEnts,
|
|
504
|
-
toolMatches, episodeMatches, why: whyMap ? Object.fromEntries(whyMap) : {}, gated: false, tier,
|
|
572
|
+
toolMatches, toolGaps, episodeMatches, why: whyMap ? Object.fromEntries(whyMap) : {}, gated: false, tier,
|
|
505
573
|
};
|
|
506
574
|
}
|
|
507
575
|
|
|
508
|
-
module.exports = { name: "discoverer", run, needsRecall, recallTier, walk, cascadeVerdict };
|
|
576
|
+
module.exports = { name: "discoverer", run, needsRecall, recallTier, walk, cascadeVerdict, scoutToolGaps, renderToolGaps };
|
package/core/system-prompt.js
CHANGED
|
@@ -79,18 +79,25 @@ function buildToolIndexBlock() {
|
|
|
79
79
|
if (count) {
|
|
80
80
|
listing = `\nYou have ${count} reusable tool${count === 1 ? "" : "s"}. The ones relevant to a turn are surfaced automatically below (\"Tools that may help here\"). To find others on demand: \`open-claudia tool search <query>\` (lexical match) or \`open-claudia tool list\`; read docs/source with \`open-claudia tool show <name>\`; run with \`open-claudia tool run <name> [args]\`.\n`;
|
|
81
81
|
} else {
|
|
82
|
-
listing = "\nNo reusable tools
|
|
82
|
+
listing = "\nNo reusable tools exist yet — your first operational task starts by scaffolding the tool for it, not by improvising a script.\n";
|
|
83
83
|
}
|
|
84
84
|
} catch (e) {
|
|
85
85
|
return "";
|
|
86
86
|
}
|
|
87
|
-
return `\n##
|
|
88
|
-
|
|
87
|
+
return `\n## Tools are the interface (tool-first)
|
|
88
|
+
Operational work — hitting an API, mutating a live system, driving an interface, any command you would re-derive next time — happens THROUGH a reusable tool, not around one. BEFORE doing the work, walk this loop in order:
|
|
89
89
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
90
|
+
1. **Search** — check the "Tools that may help here" block if present; otherwise \`open-claudia tool search <query>\` or \`tool list\`.
|
|
91
|
+
2. **Use** — a tool covers it: read it first (\`open-claudia tool show <name>\` gives docs, State, known issues, recent changes — never guess its args; \`--source\` only when modifying), then \`open-claudia tool run <name> <verb> [args]\`.
|
|
92
|
+
3. **Extend** — right tool, missing verb: add the verb to that tool (\`tool edit <name>\`, then \`tool note <name> --journal "added <verb>"\`) and run it. One CLI per system, verbs as subcommands — never fork a near-duplicate.
|
|
93
|
+
4. **Scaffold** — no tool fronts the system: \`open-claudia tool scaffold <name> --desc "..." --risk <read-only|write|destructive> [--pack <dir>] [--requires "key1,key2"]\` FIRST, implement the verb you need, then do the work through it.
|
|
94
|
+
|
|
95
|
+
Raw shell one-liners and heredocs are for probing and diagnosis only — never the operational action itself. If a tool is broken, fix it or journal the defect (\`tool note <name> --issue "..."\`); do not route around it with a script.
|
|
96
|
+
|
|
97
|
+
- Risk gate: read-only tools run freely; write-tier needs \`--yes\`; destructive needs \`--yes-destructive\`. The flag is your mechanical acknowledgment AFTER the user approves the action — it never replaces asking first.
|
|
98
|
+
- Tools carry their own memory: TOOL.md (Interface · Known issues · State · Journal) is the manual, state.json records every run (per-verb health), and every change is a git commit. Keep TOOL.md truthful as you work; update the tool in place when behaviour changes.
|
|
99
|
+
- Preauth: the operational keyring is merged into tool runs — and into your own Bash. Reference creds as \`$inet_central_user\` etc. (\`open-claudia keyring list\` shows names); declare a tool's needs via \`--requires\` so a missing key reports before the run; never write a secret into a tool file (saves are refused).
|
|
100
|
+
- Announce in one line when you scaffold or change a tool, same as packs. Full CLI: \`open-claudia tool list|search|show|scaffold|add|set|note|edit|run|migrate|remove\`.
|
|
94
101
|
${listing}`;
|
|
95
102
|
}
|
|
96
103
|
|