nubos-pilot 0.2.2 → 0.4.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.
@@ -0,0 +1,155 @@
1
+ ---
2
+ command: np:scan-codebase
3
+ description: Initial deep codebase scan — inventories files, groups them into coherent modules, writes skill-style docs under .nubos-pilot/codebase/ that dev-agents must read before touching code.
4
+ ---
5
+
6
+ # np:scan-codebase
7
+
8
+ Perform the initial codebase scan for a project. Produces a full set of
9
+ module docs under `.nubos-pilot/codebase/modules/`, an `INDEX.md` pointer
10
+ file, a `.hashes.json` manifest for staleness tracking, and a
11
+ `.doc-index.json` mapping of doc → source paths.
12
+
13
+ Dev-agents (executor, code-fixer, planner, researcher, documenter, custom)
14
+ MUST read `INDEX.md` + any relevant module docs before modifying code, and
15
+ MUST call `np:update-docs` after changes.
16
+
17
+ ## Philosophy
18
+
19
+ <philosophy>
20
+ The codebase doc layer is the shared memory of every agent working in the
21
+ project. If it is empty or stale, each agent re-derives context from raw
22
+ source, burns tokens, and can drift. This workflow pays the one-time cost
23
+ of a deep inventory, hybrid-parser-plus-documenter-agent pass so that every
24
+ subsequent agent starts informed.
25
+
26
+ Nothing in this workflow is Claude-specific. The subcommand returns
27
+ module-facts JSON, the documenter agent is a prompt that any orchestrator
28
+ (Claude Code, OpenAI, Codex) can dispatch. Stay runtime-agnostic.
29
+ </philosophy>
30
+
31
+ ## Scope Guardrail
32
+
33
+ <scope_guardrail>
34
+ This workflow ONLY writes inside `.nubos-pilot/codebase/`. It NEVER:
35
+
36
+ - modifies application source code
37
+ - touches PROJECT.md, REQUIREMENTS.md, or roadmap.yaml
38
+ - runs git commands beyond read-only `git log` via the scanner
39
+ - spawns network calls outside the documenter agent's own tool surface
40
+
41
+ Refuse and report if any of these boundaries would be crossed.
42
+ </scope_guardrail>
43
+
44
+ ## Downstream Awareness
45
+
46
+ <downstream_awareness>
47
+ - `np:update-docs` reads `.doc-index.json` + `.hashes.json` to diff.
48
+ - Every `np:execute-*` workflow's post-step calls `np:update-docs`.
49
+ - Every np-agent is instructed to read `.nubos-pilot/codebase/INDEX.md` and
50
+ relevant module docs before editing source.
51
+
52
+ If this workflow produces malformed INDEX.md or unreadable frontmatter,
53
+ every downstream agent degrades silently. Validate the written files at the
54
+ end.
55
+ </downstream_awareness>
56
+
57
+ ## Single-Call Init
58
+
59
+ Scan, group, write manifest + stubs, emit module-facts in one call:
60
+
61
+ ```bash
62
+ PLAN=$(node np-tools.cjs scan-codebase --project-name "$PROJECT_NAME")
63
+ if [[ "$PLAN" == @file:* ]]; then PLAN=$(cat "${PLAN#@file:}"); fi
64
+ ```
65
+
66
+ `--project-name` is optional; when provided it goes into `INDEX.md`. Other
67
+ flags: `--batch-size N` (default 500), `--max-files N`.
68
+
69
+ Parse: `mode`, `stats`, `modules[]` (each with `id`, `directory`,
70
+ `primary_language`, `file_count`, `facts`), `index_path`, `manifest_path`.
71
+
72
+ ## Process
73
+
74
+ ### Step 1: Confirm scan scope with the user
75
+
76
+ Show a summary before iterating modules:
77
+
78
+ ```
79
+ Scan complete.
80
+ - Files walked: <stats.file_count>
81
+ - Hashed: <stats.hashed_count>
82
+ - Languages: <top 3 by count>
83
+ - Modules discovered: <modules.length>
84
+ - Manifests captured: <manifests.length> (package.json, …)
85
+
86
+ Generate doc prose for all <N> modules? (yes / pick subset)
87
+ ```
88
+
89
+ Large codebases may warrant a subset pass. Honor the user's choice — do
90
+ not blast through 500 agent calls without consent.
91
+
92
+ ### Step 2: For each selected module, dispatch the documenter
93
+
94
+ Per module, build the prompt from `facts` and dispatch the documenter
95
+ subagent. The subagent is defined in `agents/np-codebase-documenter.md` and
96
+ is runtime-agnostic — pick whichever dispatch mechanism your host supports.
97
+
98
+ ```bash
99
+ PROSE_FILE=$(mktemp -t np-prose-XXXXXX.json)
100
+ # Host dispatches agent with buildDocumenterPrompt(facts) and writes JSON
101
+ # to $PROSE_FILE. Validate JSON before proceeding.
102
+ python -c 'import json,sys; json.load(open(sys.argv[1]))' "$PROSE_FILE"
103
+ ```
104
+
105
+ Batch pacing: the user opted into batches during Step 1. Between batches,
106
+ show a progress line (`[37/120 modules documented]`) and give the user a
107
+ chance to pause with Ctrl-C. Never eat interrupt signals.
108
+
109
+ ### Step 3: Apply prose per module
110
+
111
+ ```bash
112
+ node np-tools.cjs scan-codebase --apply-prose \
113
+ --module "$MODULE_ID" \
114
+ --prose-file "$PROSE_FILE"
115
+ ```
116
+
117
+ The subcommand re-reads the module's source hashes (handles files that
118
+ changed between scan and apply), merges the prose, and atomically writes
119
+ `modules/<id>.md`.
120
+
121
+ ### Step 4: Validate written artifacts
122
+
123
+ Before declaring success:
124
+
125
+ ```bash
126
+ test -f .nubos-pilot/codebase/INDEX.md
127
+ test -f .nubos-pilot/codebase/.hashes.json
128
+ test -f .nubos-pilot/codebase/.doc-index.json
129
+ ls .nubos-pilot/codebase/modules/ | wc -l
130
+ ```
131
+
132
+ Warn if a module doc is still `_TBD_` — user may have opted out mid-run.
133
+
134
+ ## Output
135
+
136
+ ```
137
+ np:scan-codebase complete.
138
+
139
+ Indexed: .nubos-pilot/codebase/INDEX.md
140
+ Modules: <N> (documented: <M>, stubs only: <N-M>)
141
+ Manifest: .nubos-pilot/codebase/.hashes.json
142
+
143
+ Dev-agents will now read INDEX.md + relevant module docs before editing.
144
+ Next change → np:update-docs runs automatically from np:execute-* workflows.
145
+ ```
146
+
147
+ ## Errors
148
+
149
+ | Code | Trigger | User action |
150
+ |------|---------|-------------|
151
+ | `scan-codebase-not-initialized` | `.nubos-pilot/` missing | Run `np:new-project` first |
152
+ | `scan-codebase-missing-module` | `--apply-prose` without `--module` | Supply flag |
153
+ | `scan-codebase-missing-prose` | `--apply-prose` without `--prose-file` | Supply flag |
154
+ | `scan-codebase-module-not-found` | id does not exist in current scan | Re-list via default mode |
155
+ | `scan-codebase-prose-unreadable` | prose JSON unreadable or invalid | Fix JSON; re-dispatch agent |
@@ -0,0 +1,132 @@
1
+ ---
2
+ command: np:update-docs
3
+ description: Incremental codebase-doc refresh — diffs current source against .hashes.json, refreshes only affected module docs, and updates the manifest.
4
+ ---
5
+
6
+ # np:update-docs
7
+
8
+ Run after any code change to keep `.nubos-pilot/codebase/` in sync with the
9
+ source. Detects added / changed / removed files, maps them to affected
10
+ modules, dispatches the documenter agent per stale module, and writes back
11
+ updated docs + manifest.
12
+
13
+ Dev-agents must invoke this after writing/editing source. `np:execute-*`
14
+ workflows call it automatically. Humans can call it manually.
15
+
16
+ ## Philosophy
17
+
18
+ <philosophy>
19
+ Docs that lag the code are worse than no docs — agents act on stale facts.
20
+ `np:update-docs` is the backpressure that keeps the shared memory fresh.
21
+ It is cheap when little has changed (diff is empty → no-op) and incremental
22
+ when much has changed (only stale modules re-documented).
23
+
24
+ Runtime-agnostic: the subcommand returns stale-module facts + new module
25
+ stubs; the host dispatches the documenter agent on each; the workflow
26
+ calls `--apply-prose` per module.
27
+ </philosophy>
28
+
29
+ ## Scope Guardrail
30
+
31
+ <scope_guardrail>
32
+ This workflow ONLY writes inside `.nubos-pilot/codebase/`. It NEVER:
33
+
34
+ - rewrites source code
35
+ - renames or removes doc files for modules that still exist
36
+ - regenerates prose for modules that did not change
37
+ </scope_guardrail>
38
+
39
+ ## Downstream Awareness
40
+
41
+ <downstream_awareness>
42
+ - Called from every `np:execute-*` workflow's post-step.
43
+ - Reads `.doc-index.json` to map touched paths → stale docs.
44
+ - Writes `.hashes.json` on completion so the next run has a fresh baseline.
45
+
46
+ If `.doc-index.json` is missing, fall back to a full rescan via
47
+ `np:scan-codebase` instead of guessing.
48
+ </downstream_awareness>
49
+
50
+ ## Single-Call Init
51
+
52
+ ```bash
53
+ PLAN=$(node np-tools.cjs update-docs)
54
+ if [[ "$PLAN" == @file:* ]]; then PLAN=$(cat "${PLAN#@file:}"); fi
55
+ ```
56
+
57
+ Parse: `mode`, `diff_summary` (added/removed/changed/unchanged counts),
58
+ `stale_modules[]`, `added_modules[]`, `removed_modules[]`.
59
+
60
+ If all counts are zero, print "No doc updates needed." and exit.
61
+
62
+ ## Process
63
+
64
+ ### Step 1: Report diff to the user
65
+
66
+ ```
67
+ Diff vs last manifest:
68
+ - Added files: <n>
69
+ - Changed files: <n>
70
+ - Removed files: <n>
71
+
72
+ Stale modules: <n> — prose will be refreshed
73
+ Added modules: <n> — stubs written; prose pending
74
+ Removed modules: <n> — marked for user review
75
+ ```
76
+
77
+ For non-zero stale/added, ask: "Refresh prose now? (yes / no / pick)".
78
+ If "no", exit with stubs-only state — user can run the workflow later.
79
+
80
+ ### Step 2: Dispatch documenter per stale + added module
81
+
82
+ For each module in `stale_modules ++ added_modules`:
83
+
84
+ ```bash
85
+ # Build prompt from facts, dispatch agent, capture JSON to $PROSE_FILE
86
+ node np-tools.cjs update-docs --apply-prose \
87
+ --module "$MODULE_ID" \
88
+ --prose-file "$PROSE_FILE"
89
+ ```
90
+
91
+ ### Step 3: Handle removed modules
92
+
93
+ For `removed_modules`, prompt the user:
94
+
95
+ ```
96
+ Module <id> has no source files anymore. Delete its doc?
97
+ (delete / archive to modules/_archived/ / keep)
98
+ ```
99
+
100
+ Default: archive. The workflow MUST NOT silently delete docs.
101
+
102
+ ### Step 4: Verify manifest is fresh
103
+
104
+ ```bash
105
+ stat -f "%m" .nubos-pilot/codebase/.hashes.json
106
+ ```
107
+
108
+ The `generated_at` in the JSON should be within the last few seconds.
109
+
110
+ ## Output
111
+
112
+ ```
113
+ np:update-docs complete.
114
+
115
+ Diff: +<added> ~<changed> -<removed>
116
+ Refreshed: <n> modules
117
+ Added: <n> modules
118
+ Archived: <n> modules
119
+
120
+ Manifest: .nubos-pilot/codebase/.hashes.json
121
+ ```
122
+
123
+ ## Errors
124
+
125
+ | Code | Trigger | User action |
126
+ |------|---------|-------------|
127
+ | `update-docs-not-initialized` | `.nubos-pilot/` missing | Run `np:new-project` |
128
+ | `update-docs-missing-module` | `--apply-prose` without `--module` | Supply flag |
129
+ | `update-docs-missing-prose` | `--apply-prose` without `--prose-file` | Supply flag |
130
+ | `update-docs-module-not-found` | id does not exist in current scan | Rescan |
131
+ | `update-docs-prose-unreadable` | prose JSON unreadable or invalid | Fix JSON; re-dispatch agent |
132
+ | `manifest-schema-mismatch` | old `.hashes.json` from prior schema | Delete manifest; run `np:scan-codebase` |