toga-ai 1.0.44 → 1.0.46

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/knowledge.js CHANGED
@@ -145,6 +145,107 @@ function coreReposFor(registry, framework) {
145
145
  return registry.filter(r => r.framework === framework && r.role === 'core').map(r => r.repo);
146
146
  }
147
147
 
148
+ /* ------------------------------------------------------------------ */
149
+ /* command: manifest — compact pickable lists for kickoff (one call, */
150
+ /* no profile reads). Prints minified JSON {repos:[...],clients:[...]}. */
151
+ /* ------------------------------------------------------------------ */
152
+
153
+ function cmdManifest() {
154
+ const registry = loadRegistry();
155
+ const repos = registry.map(r => ({ repo: r.repo, project: r.project, framework: r.framework, role: r.role }));
156
+ const clients = [];
157
+ const clientsDir = path.join(ROOT, 'clients');
158
+ if (fs.existsSync(clientsDir)) {
159
+ for (const slug of fs.readdirSync(clientsDir, { withFileTypes: true }).filter(e => e.isDirectory()).map(e => e.name)) {
160
+ const profile = path.join(clientsDir, slug, 'profile.md');
161
+ let title = slug, framework = '';
162
+ if (fs.existsSync(profile)) {
163
+ const { data } = parseFrontmatter(fs.readFileSync(profile, 'utf8'));
164
+ title = data.title || slug;
165
+ framework = data.framework || '';
166
+ }
167
+ clients.push({ slug, title, framework });
168
+ }
169
+ }
170
+ console.log(JSON.stringify({ repos, clients }));
171
+ }
172
+
173
+ /* ------------------------------------------------------------------ */
174
+ /* command: publish — capture's deterministic finish (validate, index, */
175
+ /* optional mirror, commit knowledge/, rebase-before-push with retry). */
176
+ /* Replaces ~80 lines of skill prose + 6 model-orchestrated git calls. */
177
+ /* Flags: --msg=<commit msg> --mirror=<project .claude dir> --branch= */
178
+ /* Prints one PUBLISH: <STATUS> line the skill can branch on. */
179
+ /* ------------------------------------------------------------------ */
180
+
181
+ function copyDir(src, dest) {
182
+ fs.mkdirSync(dest, { recursive: true });
183
+ for (const e of fs.readdirSync(src, { withFileTypes: true })) {
184
+ const s = path.join(src, e.name), d = path.join(dest, e.name);
185
+ if (e.isDirectory()) copyDir(s, d);
186
+ else fs.copyFileSync(s, d);
187
+ }
188
+ }
189
+
190
+ function cmdPublish(args) {
191
+ const cp = require('child_process');
192
+ const TEAM = __dirname;
193
+ const node = process.argv[0];
194
+ const self = __filename;
195
+ const branch = args.branch || '_main';
196
+ const run = (cmd) => cp.execSync(cmd, { cwd: TEAM, encoding: 'utf8', stdio: 'pipe' });
197
+
198
+ // 0. must be a git clone
199
+ try { run('git rev-parse --git-dir'); }
200
+ catch { console.log('PUBLISH: NOT_GIT — knowledge written locally only; run `npx toga-ai` to create a pushable clone'); return; }
201
+
202
+ // 1. validate (inherit output so any ERROR: lines are visible); abort on failure
203
+ try { cp.execSync(`"${node}" "${self}" validate`, { cwd: TEAM, stdio: 'inherit' }); }
204
+ catch { console.log('PUBLISH: VALIDATE_FAILED — fix the errors above; nothing pushed'); process.exitCode = 1; return; }
205
+
206
+ // 2. rebuild indexes
207
+ cp.execSync(`"${node}" "${self}" index`, { cwd: TEAM, stdio: 'inherit' });
208
+
209
+ // 3. optional mirror back to the project bundle (keeps local reads fresh)
210
+ if (args.mirror && typeof args.mirror === 'string') {
211
+ const dest = path.join(args.mirror, 'knowledge');
212
+ if (path.resolve(dest) !== path.resolve(ROOT)) { copyDir(ROOT, dest); console.log('PUBLISH: mirrored knowledge/ -> ' + dest); }
213
+ }
214
+
215
+ // 4. stage knowledge/ ONLY; bail if anything else slipped in
216
+ run('git add knowledge/');
217
+ const staged = run('git diff --cached --name-only').split('\n').map(s => s.trim()).filter(Boolean);
218
+ if (staged.length === 0) { console.log('PUBLISH: NO_CHANGES — nothing new to push'); return; }
219
+ const outside = staged.filter(f => !f.startsWith('knowledge/'));
220
+ if (outside.length) { run('git reset -q'); console.log('PUBLISH: ABORT_OUTSIDE_KNOWLEDGE — refusing to commit non-knowledge files: ' + outside.join(', ')); process.exitCode = 1; return; }
221
+
222
+ // 5. commit
223
+ const msg = String(args.msg || 'knowledge: capture session updates').replace(/["\\]/g, "'").slice(0, 200);
224
+ run(`git commit -m "${msg}"`);
225
+
226
+ // 6. rebase-before-push, retrying the CI version-bump race up to 3x
227
+ for (let attempt = 1; attempt <= 3; attempt++) {
228
+ try {
229
+ run('git fetch origin');
230
+ run(`git rebase origin/${branch}`);
231
+ run(`git push origin HEAD:${branch}`);
232
+ console.log(`PUBLISH: PUSHED to ${branch} — CI publishes a new npm version; teammates get it on \`npx toga-ai\``);
233
+ return;
234
+ } catch (e) {
235
+ let status = '';
236
+ try { status = run('git status --porcelain'); } catch { /* ignore */ }
237
+ if (/^(UU|AA|DD|AU|UA|DU|UD) /m.test(status)) {
238
+ try { run('git rebase --abort'); } catch { /* ignore */ }
239
+ console.log(`PUBLISH: CONFLICT — rebase onto origin/${branch} hit a real conflict; resolve manually, then re-run publish`);
240
+ process.exitCode = 1; return;
241
+ }
242
+ // else: almost certainly a fresh CI bump (non-fast-forward) — loop and retry
243
+ }
244
+ }
245
+ console.log(`PUBLISH: PUSH_FAILED after 3 attempts — run manually: git -C "${TEAM}" push origin HEAD:${branch}`);
246
+ process.exitCode = 1;
247
+ }
248
+
148
249
  /* ------------------------------------------------------------------ */
149
250
  /* command: deps */
150
251
  /* ------------------------------------------------------------------ */
@@ -379,8 +480,10 @@ function main() {
379
480
  case 'index': return cmdIndex();
380
481
  case 'deps': return cmdDeps(args);
381
482
  case 'validate': return cmdValidate();
483
+ case 'manifest': return cmdManifest();
484
+ case 'publish': return cmdPublish(args);
382
485
  default:
383
- console.log('Usage: node knowledge.js <search|index|deps|validate> [--flags]');
486
+ console.log('Usage: node knowledge.js <search|index|deps|validate|manifest|publish> [--flags]');
384
487
  process.exitCode = 1;
385
488
  }
386
489
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "toga-ai",
3
- "version": "1.0.44",
3
+ "version": "1.0.46",
4
4
  "description": "TOGA Technology Team Claude Knowledge System — shared AI coding harness with skills, knowledge base CLI, and project installer for Claude Code.",
5
5
  "keywords": [
6
6
  "claude",
@@ -11,17 +11,10 @@ assume**. Nothing is written until the developer approves your proposal.
11
11
 
12
12
  ### Contribution model
13
13
 
14
- Every `/capture` automatically pushes new knowledge back to the team git repo after
15
- validate + index succeed:
16
-
17
- - Teammates get it on their **next `npx toga-harness`** run, which pulls the git repo
18
- before installing — so the two-way loop is:
19
- 1. `npx toga-harness` seeds knowledge from the npm bundle
20
- 2. `/capture` grows the knowledge base and pushes it back to git
21
- 3. Teammates run `npx toga-harness` → git pull delivers the new docs → they get it
22
- - The push is **non-blocking**: if offline or credentials are missing, capture is still
23
- successful and you report a reminder to push manually.
24
- - Only `knowledge/` files are ever staged — source code is never touched.
14
+ Every `/capture` validates, indexes, then **pushes** `knowledge/` to the team git repo
15
+ (only `knowledge/` is ever staged — never source code). Teammates receive it on their next
16
+ `npx toga-ai` run (which git-pulls before installing). The push is **non-blocking**: if
17
+ offline or unauthenticated, the capture still succeeds report a manual-push reminder.
25
18
 
26
19
  ## Core data model (same as `knowledge/CONVENTIONS.md` and the `kickoff` skill)
27
20
 
@@ -60,8 +53,8 @@ done
60
53
  **`~/toga-tech` must be probed first** — `npx toga-ai` runs `initLocalRepo` there, which
61
54
  creates a proper git repo seeded from the bundle even when the remote is private.
62
55
 
63
- **If `IS_GIT_CLONE` is false** (only `.claude/` bundle found): warn immediately and skip
64
- Steps 5–7 for git operations:
56
+ **If `IS_GIT_CLONE` is false** (only `.claude/` bundle found): you can still write docs
57
+ locally (Step 5), but the Step 6 publish will report `NOT_GIT` instead of pushing. Warn:
65
58
  > "⚠ No git clone found at standard paths. Docs will be written locally only.
66
59
  > Run `npx toga-ai` first (it creates `~/toga-tech` as a pushable git repo),
67
60
  > then re-run /capture to push to GitHub."
@@ -150,94 +143,34 @@ For a client `profile.md`, the `title:` **is** the client's formal name (e.g. "C
150
143
  there is no separate name field; `validate` requires `title`. See New-client onboarding.
151
144
  Add `related:` cross-links. Append new repos to `<TEAM_REPO>/knowledge/registry.json`.
152
145
 
153
- ## Step 6 — Validate, index, mirror back (mandatory)
146
+ ## Step 6 — Publish (validate → index mirror rebase-push, one command)
154
147
 
155
- ```bash
156
- node "<TEAM_REPO>/knowledge.js" validate
157
- node "<TEAM_REPO>/knowledge.js" index
158
- ```
159
-
160
- If `validate` reports any ERROR — stop and fix before continuing.
161
-
162
- After both pass, **mirror back** to keep the project's local reads fresh:
163
- ```bash
164
- # Only when TEAM_REPO != <project>/.claude
165
- cp -r "<TEAM_REPO>/knowledge/" "<project>/.claude/knowledge/"
166
- ```
167
- Skip mirror-back if the paths are the same directory.
168
-
169
- ## Step 7 — Push (only when IS_GIT_CLONE is true)
170
-
171
- **This push is pre-authorized and mandatory — never ask the developer to confirm it.**
172
- Running `/capture` IS the authorization to publish. After validate + index pass and the
173
- staged set is confined to `knowledge/`, commit and push automatically as the final step of
174
- every capture. Do not pause, do not present a "ready to push?" prompt, do not offer to "leave
175
- it staged locally." The only reasons to stop are the guardrails already listed below: nothing
176
- new to push (Check B empty), files staged outside `knowledge/`, or a push that errors.
177
-
178
- If `IS_GIT_CLONE` is false — skip this step entirely and show:
179
- > "⚠ Docs written to `.claude/knowledge/` only (no git clone). Run `npx toga-ai`
180
- > to create `~/toga-tech`, then re-run /capture to push."
181
-
182
- Otherwise:
183
-
184
- **Check A — origin URL correct?**
185
- ```bash
186
- git -C "<TEAM_REPO>" remote get-url origin
187
- ```
188
- If wrong or missing: `git -C "<TEAM_REPO>" remote set-url origin https://github.com/agilantsolutions/claude`
189
-
190
- **Check B — anything new to push?**
191
- ```bash
192
- git -C "<TEAM_REPO>" status --short knowledge/
193
- ```
194
- If empty — report "No new knowledge to push" and exit cleanly.
195
-
196
- **Commit:**
197
- ```bash
198
- git -C "<TEAM_REPO>" add knowledge/
199
- git -C "<TEAM_REPO>" diff --cached --quiet || \
200
- git -C "<TEAM_REPO>" commit -m "knowledge: <one-line summary>"
201
- ```
202
-
203
- Never stage files outside `knowledge/`. If `git diff --cached` includes anything outside
204
- `knowledge/`, abort and warn before committing.
205
-
206
- **Sync, then push (rebase BEFORE pushing — this prevents the version-bump conflict):**
207
-
208
- Every push to this branch triggers a CI job that commits a `chore: bump version [skip ci]`
209
- back to the branch. So after *any* prior push (e.g. an earlier capture in the same session),
210
- your local branch is one commit behind the remote, and a naive push is rejected as a
211
- non-fast-forward. Rebase your fresh commit onto the remote **before** pushing — this pulls in
212
- commits that already exist (no waiting on CI), so the push fast-forwards cleanly:
148
+ Finish every capture with the deterministic publisher — **do not** run validate/index/git
149
+ by hand. The push is **pre-authorized and mandatory**: running `/capture` IS the
150
+ authorization, so never ask "ready to push?".
213
151
 
214
152
  ```bash
215
- git -C "<TEAM_REPO>" fetch origin
216
- git -C "<TEAM_REPO>" rebase origin/_main
217
- git -C "<TEAM_REPO>" push origin HEAD:_main
153
+ node "<TEAM_REPO>/knowledge.js" publish --msg="knowledge: <one-line summary>" --mirror="<project>/.claude"
218
154
  ```
219
155
 
220
- > **Do NOT "pull after push" instead** the bump commit for *this* push is created
221
- > asynchronously by CI a few seconds later, so pulling immediately afterward races CI and
222
- > usually grabs nothing. Rebasing *before* the push is what reliably avoids the conflict,
223
- > with zero dependency on npm build/publish timing.
224
-
225
- **If the push is still rejected** (a bump commit landed in the brief window between your
226
- rebase and push), simply repeat `fetch` → `rebase` → `push`, up to 2 more times. This is an
227
- expected occasional race, not an error — do not report it as a failure unless all retries are
228
- exhausted.
156
+ This validates, rebuilds indexes, mirrors `knowledge/` back to the project bundle, then
157
+ stages **only** `knowledge/`, commits, and rebase-pushes to `_main` (auto-retrying the CI
158
+ version-bump race). Omit `--mirror` if TEAM_REPO already *is* the project bundle. Read the
159
+ final `PUBLISH:` line and act on it:
229
160
 
230
- **If push succeeds:**
231
- > "✓ Pushed to `_main` CI publishes new npm version. Teammates get it on `npx toga-ai`."
161
+ - **`PUSHED`** — done. Report: "✓ Pushed to `_main` — teammates get it on `npx toga-ai`."
162
+ - **`NO_CHANGES`**report "No new knowledge to push" and finish.
163
+ - **`VALIDATE_FAILED`** — fix the printed `ERROR:` lines, then re-run publish. Never push around it.
164
+ - **`CONFLICT`** — a real rebase conflict; resolve manually, then re-run publish.
165
+ - **`ABORT_OUTSIDE_KNOWLEDGE`** — non-`knowledge/` files were staged; investigate before retrying.
166
+ - **`NOT_GIT`** — no git clone; docs are local only. Tell the dev to run `npx toga-ai` first.
167
+ - **`PUSH_FAILED`** — show the printed manual-push command.
232
168
 
233
- **If push fails**show exact git error, then:
234
- > "⚠ Push failed: `<error>`. Run manually: `git -C <TEAM_REPO> push origin HEAD:_main`"
235
-
236
- ## Step 8 — Report
169
+ ## Step 7Report
237
170
 
238
171
  List exactly what changed (clickable relative paths), and note any ⚠ ELEVATED docs the
239
172
  developer approved so they remember those touched senior-owned standards/architecture.
240
- If Step 7 pushed successfully, include the push confirmation in the report.
173
+ If Step 6 published successfully (`PUSHED`), include the push confirmation in the report.
241
174
 
242
175
  ---
243
176
 
@@ -392,34 +325,15 @@ Who the client is and what their integration does.
392
325
 
393
326
  ### After Capture
394
327
 
395
- Once you have completed a capture session and confirmed the changes are committed to
396
- the knowledge base, suggest the following to the developer:
397
-
398
- > "Session captured successfully. If you're done for today or may not finish this
399
- > thread in one sitting, run `/session-save` to persist your session state. This
400
- > records exactly what worked, what failed, what's pending, and your exact next step —
401
- > so you can resume without losing context, even days later."
328
+ After the push is confirmed, suggest the developer persist session state:
329
+ > "Captured. If you might not finish this thread in one sitting, run `/session-save` to
330
+ > record what worked, what failed, what's pending, and your next step — so you can resume
331
+ > later without losing context."
402
332
 
403
- Provide the suggested command with a name hint:
404
- ```
405
- /session-save <suggested-slug-based-on-what-was-worked-on>
406
- ```
407
-
408
- For example, if the session was about "ClickUp deploy worker actions", suggest:
409
- ```
410
- /session-save clickup-deploy-worker
411
- ```
333
+ Suggest a slug from the work, e.g. `/session-save clickup-deploy-worker`.
412
334
 
413
335
  ### PostToolUse hook auto-validation
414
336
 
415
- The `.claude/settings.json` in this repo includes a `PostToolUse` hook that
416
- automatically runs `node knowledge.js validate` after any file write to `knowledge/`.
417
- This means:
418
-
419
- - As each doc is written during the capture step, validation runs immediately.
420
- - You will see inline output with any `ERROR:` or `OK` messages.
421
- - If validation fails after a write, address the error before writing the next doc —
422
- do not proceed to Step 6's explicit `validate` run while errors are outstanding.
423
- - Step 6's explicit `node knowledge.js validate` call is still required as the final
424
- gate — the hook fires per-write, but the explicit call confirms global consistency
425
- after all writes are complete.
337
+ `.claude/settings.json` runs `node knowledge.js validate` after every write to `knowledge/`,
338
+ so `ERROR:`/`OK` output appears inline as each doc is written — fix any error before writing
339
+ the next. Step 6's `publish` re-runs `validate` as the final global-consistency gate before pushing.
@@ -14,7 +14,7 @@ shortcut the flow.
14
14
  - **Step 0 (auto-update check) ALWAYS runs first**, with or without arguments.
15
15
  - Use the argument text to **pre-fill answers** to the Step 2 interview (framework, layer,
16
16
  repo, client, task). Only ask about whatever is still missing or ambiguous.
17
- - Never treat the argument as an instruction to start coding before Steps 0–5 complete.
17
+ - Never treat the argument as an instruction to start coding before Steps 0–6 complete.
18
18
 
19
19
  ## Step 0 — Auto-update check (runs before anything else, even with arguments)
20
20
 
@@ -107,52 +107,26 @@ When resolved, if there was no `team-repo-path` memory, **write one** (memory ty
107
107
 
108
108
  ## Step 2 — Interview the developer (ask the work questions FIRST)
109
109
 
110
- Ask these in one message. **Present the repos/projects you already know** (read
111
- `registry.json`) so the developer can just pick:
110
+ Get the pickable lists in **one call**: `node "<TEAM_REPO>/knowledge.js" manifest` returns
111
+ minified JSON `{repos:[{repo,project,framework,role}], clients:[{slug,title,framework}]}`.
112
+ **Do not read `registry.json` or any `profile.md` to build these lists.** Ask all questions
113
+ in one message:
112
114
 
113
115
  1. **Framework** — 1.0, 2.0, or **both**?
114
116
  2. **Layer** — front-end, back-end, or hybrid?
115
- 3. **Repo(s) / project(s)** — **list EVERY registered repo for the chosen framework(s)** —
116
- do not abbreviate or show only a few. **This is a multi-select (checkbox), not a single
117
- choice;** a session often spans more than one repo/project, so always let the developer
118
- pick several. If they pick a repo not listed, run **New-repo onboarding** (below) for
119
- each new repo before continuing.
120
- 4. **Client** — which client is this for, or "shared / internal"? **List EVERY client by its
121
- formal name** — read the `title:` field from each `knowledge/clients/<slug>/profile.md`
122
- and show the **formal name, not the slug** (fall back to a title-cased slug only if the
123
- profile is missing). Include "shared / internal" and "a new client". Do not show only a
124
- subset.
117
+ 3. **Repo(s) / project(s)** — list EVERY manifest repo for the chosen framework(s).
118
+ **Multi-select (checkbox), not single choice** a session often spans several repos. If
119
+ they name a repo not listed, run **New-repo onboarding** (below) for each before continuing.
120
+ 4. **Client** list EVERY manifest client by its **`title`** (the formal name, not the slug),
121
+ plus "shared / internal" and "a new client".
125
122
  5. **What are you building or changing?** (a sentence — used to pick relevant feature docs.)
126
123
 
127
- If any answer is unclear, ask again. Do not guess the framework, repo, project, or client.
124
+ If any answer is unclear, ask again. Do not guess framework, repo, project, or client.
128
125
 
129
- ### How to present the repo and client choices (questions 3 and 4)
130
-
131
- **Do NOT use the option-chip / radio question control for questions 3 and 4.** That
132
- control caps at ~4 options, which silently truncates the list with 7+ repos or 3+
133
- clients the developer never sees the full set. Instead, **render the full list as a
134
- numbered markdown list in a normal message** and ask the developer to reply with the
135
- numbers they want (e.g. "1, 3, 5"). This shows every repo and every client with no cap
136
- and naturally supports multi-select.
137
-
138
- ```
139
- **Which repo(s)/project(s)?** (reply with the numbers, multiple OK)
140
- 1. _underscore (_Underscore — 2.0 core)
141
- 2. worker2 (Worker — 2.0 app)
142
- 3. api2 (API — 2.0 app)
143
- ... every registered repo for the chosen framework(s) ...
144
- N. a new repo not listed
145
-
146
- **Which client?** (one, or "shared / internal")
147
- 1. Compass Canada
148
- 2. Compass USA
149
- 3. Elite
150
- ... every client's FORMAL name (from clients/<slug>/profile.md `title:`), not the slug ...
151
- S. shared / internal
152
- X. a new client
153
- ```
154
-
155
- Framework (q1) and layer (q2) have ≤4 options, so the chip control is fine for those.
126
+ **Presenting q3 and q4:** do NOT use the option-chip / radio control it caps at ~4 options
127
+ and silently truncates a 7-repo / 5-client list. Render the full list as a numbered markdown
128
+ list and have the developer reply with numbers (e.g. "1, 3, 5") no cap, supports
129
+ multi-select. Framework (q1) and layer (q2) have ≤4 options, so chips are fine there.
156
130
 
157
131
  ## Step 3 — Resolve the repos this work needs (local paths, lazily)
158
132
 
@@ -251,7 +225,7 @@ If they have already run `/session-resume` and are now running `/kickoff`, proce
251
225
  normally — the session context they loaded will complement the framework knowledge
252
226
  loaded here.
253
227
 
254
- ## Step 5 — Propose a multi-agent workflow plan
228
+ ## Step 6 — Propose a multi-agent workflow plan
255
229
 
256
230
  After loading context, analyze what the developer said they're building and **propose a
257
231
  concrete agent plan before writing a single line of code**. This gives them visibility