@contextium/cli 1.0.15 → 1.0.17

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contextium/cli",
3
- "version": "1.0.15",
3
+ "version": "1.0.17",
4
4
  "description": "Command-line tool for managing Contextium documentation, agents, skills, and workflows — pipe context to AI coding assistants",
5
5
  "keywords": [
6
6
  "contextium",
@@ -7,6 +7,28 @@ description: General behaviour rules for the Contextium MCP and CLI — scoping,
7
7
 
8
8
  These rules apply whenever the Contextium MCP is connected or the CLI is in use, regardless of which slash command was run.
9
9
 
10
+ ## Session Auto-Restore
11
+
12
+ At the start of any new session where no `--- WORKFLOW SESSION CONTEXT ---` block exists in the conversation yet, automatically restore the last used workspace and workflow:
13
+
14
+ 1. Silently check `.contextiumrc`:
15
+ ```bash
16
+ cat .contextiumrc 2>/dev/null
17
+ ```
18
+
19
+ 2. If `last_workflow` and `last_workspace` are present, load the workflow immediately without asking:
20
+
21
+ **CLI:** `contextium workflow "<last_workflow>" -w <last_workspace> --sync 2>/dev/null`
22
+ **MCP:** call mcp__contextium__load_workflow with the workflow name
23
+
24
+ 3. Output the session context block as normal. Do not announce that you're auto-restoring — just do it transparently and continue with whatever the user asked.
25
+
26
+ 4. If `last_workflow` is not set, or loading fails silently, proceed as normal without mentioning it.
27
+
28
+ This runs once per session — never repeat it once the session context block has been output.
29
+
30
+ ---
31
+
10
32
  ## Scope Rules
11
33
 
12
34
  ### If a workflow has been loaded in this session
@@ -17,6 +17,10 @@ Output the following help reference directly — no tools needed:
17
17
  ╚══════════════════════════════════════════════════════════════╝
18
18
 
19
19
  GETTING STARTED
20
+ /ium:scan-existing Scan an existing codebase and write analysis docs to
21
+ Contextium — stack, architecture, conventions, concerns.
22
+ Run this before /ium:new-project on existing projects.
23
+
20
24
  /ium:new-project Set up a new Contextium project from scratch —
21
25
  auth, workspace, libraries, agents, skills, workflow
22
26
 
@@ -92,6 +92,19 @@ If yes:
92
92
  If no: continue to project description with a clean slate.
93
93
  </step>
94
94
 
95
+ <step name="codebase_scan_check">
96
+ Silently check whether any library in the selected workspace contains codebase analysis documents from `/ium:scan-existing`. Look for files named `stack.md`, `architecture.md`, `structure.md`, `conventions.md`, `concerns.md` in any library.
97
+
98
+ **CLI:** `contextium library list --workspace <slug> 2>/dev/null` then check file lists per library
99
+ **MCP:** call mcp__contextium__list_context_libraries, then mcp__contextium__list_files for each
100
+
101
+ If found, read `architecture.md` and `stack.md` silently to understand what already exists. Store this as `has_codebase_scan = true` and `codebase_library = <library name>`. This will be used later to pre-populate validated capabilities in the project state.
102
+
103
+ If not found, set `has_codebase_scan = false` and continue.
104
+
105
+ Do not mention this check to the user.
106
+ </step>
107
+
95
108
  <step name="project_description">
96
109
  Ask the user this question exactly:
97
110
 
@@ -221,6 +234,13 @@ If yes:
221
234
  **Last Updated:** [today's date]
222
235
  **Next Action:** Begin Phase 1
223
236
 
237
+ ## Already Built
238
+ > Capabilities confirmed by codebase scan — these do not need to be built.
239
+ > _(Remove this section if starting a greenfield project with no existing code)_
240
+
241
+ - ✓ [Existing capability — e.g. "Express API with JWT auth"] — `src/server.ts`
242
+ - ✓ [Existing capability] — `src/`
243
+
224
244
  ## Phases
225
245
 
226
246
  ### Phase 1: [Name]
@@ -253,6 +273,8 @@ _(ad-hoc notes that don't fit elsewhere)_
253
273
 
254
274
  Infer sensible phases from the project description. Title the file `project-state.md`.
255
275
 
276
+ **If `has_codebase_scan = true`:** populate the `## Already Built` section from the `architecture.md` found in the codebase scan library — list the key capabilities that clearly already exist. Only plan phases for what is **not** in the Already Built list. If starting greenfield, remove the Already Built section entirely.
277
+
256
278
  **Important:** Only one `project-state.md` should ever exist per context library. This is the single source of truth for this project. Never create a second one or split state across multiple files.
257
279
 
258
280
  If no: set `planner_planned = false` and continue.
@@ -0,0 +1,422 @@
1
+ ---
2
+ name: ium:scan-existing
3
+ description: Scan an existing codebase and write analysis documents to a Contextium context library — tech stack, architecture, structure, conventions, and concerns. Used before /ium:new-project to generate a roadmap that knows what's already built vs what still needs doing.
4
+ allowed-tools:
5
+ - Bash
6
+ - Glob
7
+ - Grep
8
+ - Read
9
+ - mcp__contextium__list_workspaces
10
+ - mcp__contextium__list_context_libraries
11
+ - mcp__contextium__list_workflows
12
+ - mcp__contextium__load_workflow
13
+ - mcp__contextium__create_context_library
14
+ - mcp__contextium__create_file
15
+ - mcp__contextium__update_file
16
+ - mcp__contextium__list_files
17
+ - mcp__contextium__get_file
18
+ - AskUserQuestion
19
+ ---
20
+
21
+ <objective>
22
+ Analyse an existing codebase across five domains and write the findings as structured documents to a Contextium context library. The output gives any agent full context about what exists, how it's built, and what's already working — without re-analysing the codebase every session. When followed by /ium:new-project, the roadmap will know what's already done and only plan phases for what's missing.
23
+ </objective>
24
+
25
+ <mode-detection>
26
+ Run once at the start, silently:
27
+
28
+ ```bash
29
+ command -v contextium &>/dev/null && echo "cli" || echo "no-cli"
30
+ ```
31
+
32
+ - If `cli`: use CLI commands throughout.
33
+ - If `no-cli`: use MCP tools throughout.
34
+ - If neither: tell the user "Contextium doesn't appear to be installed." and stop.
35
+ </mode-detection>
36
+
37
+ <process>
38
+
39
+ <step name="check_auth">
40
+ **CLI only.** Run silently:
41
+ ```bash
42
+ contextium whoami 2>/dev/null | grep -E "Token:|Name:" || echo "unauthenticated"
43
+ ```
44
+ If unauthenticated or token expired, tell the user to run `contextium login` and stop.
45
+
46
+ MCP users are already authenticated — skip.
47
+ </step>
48
+
49
+ <step name="select_library">
50
+ Determine where to write the codebase documents.
51
+
52
+ If a workflow is already loaded in this session, check whether any of its libraries have an obvious "codebase" or "technical" purpose. If yes, suggest it. If not, ask which library to use.
53
+
54
+ If no workflow is loaded:
55
+
56
+ **CLI:** `contextium library list --workspace <slug> 2>/dev/null`
57
+ **MCP:** call mcp__contextium__list_context_libraries
58
+
59
+ Ask: "Which library should I write the codebase analysis to? Or I can create a new one — for example, 'Codebase Analysis'."
60
+
61
+ Use AskUserQuestion:
62
+ - Present existing library names
63
+ - "Create a new library for this"
64
+
65
+ If creating new: use the name the user provides, or default to "[Project Name] Codebase". Create it:
66
+
67
+ **CLI:** `contextium library create "<name>" --workspace <slug>`
68
+ **MCP:** call mcp__contextium__create_context_library
69
+
70
+ Store the target library ID as `target_library_id`.
71
+ </step>
72
+
73
+ <step name="check_existing">
74
+ Check whether any of the five analysis documents already exist in the target library by listing its files and looking for: `stack.md`, `architecture.md`, `structure.md`, `conventions.md`, `concerns.md`.
75
+
76
+ If any exist, ask:
77
+
78
+ "I found existing analysis documents in this library. What would you like to do?"
79
+
80
+ Use AskUserQuestion:
81
+ - "Refresh all documents (overwrite)"
82
+ - "Update specific documents only"
83
+ - "Cancel"
84
+
85
+ If "Update specific": ask which ones to update. Only run analysis passes for those.
86
+ If "Refresh all" or no existing docs: run all five passes.
87
+ </step>
88
+
89
+ <step name="orient">
90
+ Before analysing, silently orient yourself to the project. Run:
91
+
92
+ ```bash
93
+ ls -la 2>/dev/null | head -40
94
+ ```
95
+
96
+ Then look for the project's primary language and framework indicators:
97
+
98
+ ```bash
99
+ ls package.json requirements.txt Cargo.toml go.mod pyproject.toml composer.json 2>/dev/null
100
+ ```
101
+
102
+ ```bash
103
+ ls -d src/ app/ lib/ pkg/ internal/ api/ 2>/dev/null
104
+ ```
105
+
106
+ Do not show this output to the user. Use it to focus the analysis passes that follow.
107
+
108
+ Tell the user:
109
+ ```
110
+ Scanning codebase — this will take a moment.
111
+
112
+ ○ Tech stack & integrations
113
+ ○ Architecture & structure
114
+ ○ Conventions & testing
115
+ ○ Concerns & tech debt
116
+ ```
117
+
118
+ Update each `○` to `✓` as each pass completes.
119
+ </step>
120
+
121
+ <step name="pass_1_tech">
122
+ **Tech Stack & Integrations**
123
+
124
+ Analyse and write `stack.md`:
125
+
126
+ Read dependency manifests:
127
+ ```bash
128
+ cat package.json 2>/dev/null
129
+ cat requirements.txt pyproject.toml 2>/dev/null
130
+ cat Cargo.toml go.mod 2>/dev/null
131
+ cat composer.json 2>/dev/null
132
+ ```
133
+
134
+ Read config files:
135
+ ```bash
136
+ cat tsconfig.json 2>/dev/null
137
+ ls *.config.* 2>/dev/null
138
+ cat .nvmrc .node-version .python-version 2>/dev/null
139
+ ```
140
+
141
+ Check for external service patterns:
142
+ ```bash
143
+ grep -rn "process\.env\." src/ app/ lib/ 2>/dev/null | grep -v "node_modules" | head -40
144
+ cat .env.example .env.sample 2>/dev/null
145
+ ```
146
+
147
+ Produce `stack.md` in this structure:
148
+
149
+ ```markdown
150
+ # Tech Stack
151
+ **Analysis Date:** [today]
152
+
153
+ ## Runtime & Language
154
+ [language, version, runtime]
155
+
156
+ ## Frameworks & Libraries
157
+ [list key dependencies with versions and purpose]
158
+
159
+ ## Build & Tooling
160
+ [build system, bundler, linter, formatter, type checker]
161
+
162
+ ## External Services & Integrations
163
+ [APIs, databases, auth providers, storage, email — with env var names]
164
+
165
+ ## Platform & Deployment
166
+ [inferred from config files — Docker, Vercel, Railway, etc.]
167
+ ```
168
+
169
+ Every item must reference the actual config file or env var it was found in. No vague summaries.
170
+
171
+ Write to Contextium:
172
+ **CLI:** `cat << 'EOF' | contextium new <library-name> -t "Tech Stack" -p "stack.md" --stdin -w <workspace>`
173
+ **MCP:** call mcp__contextium__create_file (or update_file if refreshing)
174
+
175
+ Update the progress indicator to `✓ Tech stack & integrations`.
176
+ </step>
177
+
178
+ <step name="pass_2_architecture">
179
+ **Architecture & Structure**
180
+
181
+ Analyse and write `architecture.md` and `structure.md`:
182
+
183
+ Get the full directory tree:
184
+ ```bash
185
+ find . -type f -not -path "*/node_modules/*" -not -path "*/.git/*" -not -path "*/dist/*" -not -path "*/.next/*" -not -path "*/build/*" | head -120
186
+ ```
187
+
188
+ Find entry points:
189
+ ```bash
190
+ ls src/index.* src/main.* src/app.* src/server.* app/page.* app/layout.* 2>/dev/null
191
+ ```
192
+
193
+ Sample key files to understand patterns:
194
+ ```bash
195
+ head -60 $(ls src/index.* src/main.* src/app.* 2>/dev/null | head -3) 2>/dev/null
196
+ ```
197
+
198
+ Produce `architecture.md`:
199
+
200
+ ```markdown
201
+ # Architecture
202
+ **Analysis Date:** [today]
203
+
204
+ ## Pattern
205
+ [MVC / layered / feature-based / monolith / microservices / etc — with evidence]
206
+
207
+ ## Layers
208
+ [list each layer: what it contains, what it depends on, example files]
209
+
210
+ ## Data Flow
211
+ [how a typical request flows through the system — entry point → handler → service → data layer]
212
+
213
+ ## Key Abstractions
214
+ [important interfaces, base classes, shared utilities — with file paths]
215
+
216
+ ## Error Handling
217
+ [how errors propagate — try/catch, result types, middleware, etc.]
218
+ ```
219
+
220
+ Produce `structure.md`:
221
+
222
+ ```markdown
223
+ # Structure
224
+ **Analysis Date:** [today]
225
+
226
+ ## Directory Map
227
+ [annotated directory tree showing purpose of each folder]
228
+
229
+ ## Key File Locations
230
+ | Purpose | Path |
231
+ |---------|------|
232
+ | Entry point | `src/index.ts` |
233
+ | Route definitions | `src/routes/` |
234
+ | [etc] | [etc] |
235
+
236
+ ## Where to Add New Code
237
+ [specific guidance: "New API routes go in src/routes/, follow the pattern in src/routes/users.ts"]
238
+
239
+ ## Naming Conventions
240
+ [file naming, folder naming, component naming patterns with examples]
241
+ ```
242
+
243
+ Write both files to Contextium. Update progress to `✓ Architecture & structure`.
244
+ </step>
245
+
246
+ <step name="pass_3_conventions">
247
+ **Conventions & Testing**
248
+
249
+ Analyse and write `conventions.md` and `testing.md`:
250
+
251
+ Read linting/formatting config:
252
+ ```bash
253
+ cat .eslintrc* eslint.config.* .prettierrc* biome.json 2>/dev/null
254
+ ```
255
+
256
+ Sample source files to extract conventions:
257
+ ```bash
258
+ head -80 $(find src/ app/ lib/ -name "*.ts" -o -name "*.tsx" -o -name "*.js" 2>/dev/null | grep -v test | grep -v spec | head -5) 2>/dev/null
259
+ ```
260
+
261
+ Check testing setup:
262
+ ```bash
263
+ cat jest.config.* vitest.config.* pytest.ini setup.cfg 2>/dev/null
264
+ find . -name "*.test.*" -o -name "*.spec.*" 2>/dev/null | grep -v node_modules | head -20
265
+ ```
266
+
267
+ Produce `conventions.md`:
268
+
269
+ ```markdown
270
+ # Conventions
271
+ **Analysis Date:** [today]
272
+
273
+ ## Naming
274
+ [variables, functions, classes, files, folders — with real examples from the codebase]
275
+
276
+ ## Code Style
277
+ [formatting rules, import order, export patterns — reference linting config]
278
+
279
+ ## Function Design
280
+ [pure vs stateful, async patterns, error handling style]
281
+
282
+ ## State Management
283
+ [how state is managed — context, stores, props — with example file paths]
284
+
285
+ ## Comments & Documentation
286
+ [what gets documented and how]
287
+ ```
288
+
289
+ Produce `testing.md`:
290
+
291
+ ```markdown
292
+ # Testing
293
+ **Analysis Date:** [today]
294
+
295
+ ## Framework & Setup
296
+ [test runner, assertion library, config file location]
297
+
298
+ ## File Organisation
299
+ [where tests live relative to source — colocated, __tests__, etc.]
300
+
301
+ ## Test Structure
302
+ [describe/it patterns, setup/teardown conventions — with example from an existing test]
303
+
304
+ ## Mocking Approach
305
+ [how dependencies are mocked — with example]
306
+
307
+ ## Coverage
308
+ [what's covered, what's not, any coverage thresholds configured]
309
+
310
+ ## How to Run Tests
311
+ [exact commands]
312
+ ```
313
+
314
+ Write both files to Contextium. Update progress to `✓ Conventions & testing`.
315
+ </step>
316
+
317
+ <step name="pass_4_concerns">
318
+ **Concerns & Tech Debt**
319
+
320
+ Analyse and write `concerns.md`:
321
+
322
+ Find tech debt markers:
323
+ ```bash
324
+ grep -rn "TODO\|FIXME\|HACK\|XXX\|TEMP\|@deprecated" --include="*.ts" --include="*.tsx" --include="*.js" --include="*.py" . 2>/dev/null | grep -v node_modules | head -60
325
+ ```
326
+
327
+ Find large/complex files:
328
+ ```bash
329
+ find . -name "*.ts" -o -name "*.tsx" -o -name "*.js" -o -name "*.py" 2>/dev/null | grep -v node_modules | grep -v dist | xargs wc -l 2>/dev/null | sort -rn | head -20
330
+ ```
331
+
332
+ Find empty stubs or incomplete implementations:
333
+ ```bash
334
+ grep -rn "throw new Error.*not implemented\|TODO.*implement\|return null\|pass$" --include="*.ts" --include="*.tsx" --include="*.js" --include="*.py" . 2>/dev/null | grep -v node_modules | head -30
335
+ ```
336
+
337
+ Check for hardcoded values that should be config:
338
+ ```bash
339
+ grep -rn "localhost\|127\.0\.0\.1\|hardcoded\|magic number" --include="*.ts" --include="*.js" . 2>/dev/null | grep -v node_modules | grep -v test | head -20
340
+ ```
341
+
342
+ Produce `concerns.md`:
343
+
344
+ ```markdown
345
+ # Concerns & Tech Debt
346
+ **Analysis Date:** [today]
347
+
348
+ ## Tech Debt
349
+ | Issue | Location | Suggested Fix |
350
+ |-------|----------|---------------|
351
+ | [specific issue] | `src/path/file.ts:42` | [concrete fix approach] |
352
+
353
+ ## Known Gaps / Incomplete Features
354
+ [stubs, TODOs marked as incomplete, features with placeholder implementations — file paths required]
355
+
356
+ ## Fragile Areas
357
+ [files or patterns that are high-risk to modify — explain why and how to modify safely]
358
+
359
+ ## Security Observations
360
+ [anything that looks like a security concern — never log secrets, only note patterns]
361
+
362
+ ## Test Coverage Gaps
363
+ [areas with no tests that clearly need them]
364
+
365
+ ## Dependencies to Watch
366
+ [outdated, deprecated, or high-risk dependencies found in package manifest]
367
+ ```
368
+
369
+ Write to Contextium. Update progress to `✓ Concerns & tech debt`.
370
+ </step>
371
+
372
+ <step name="update_project_state">
373
+ If a `project-state.md` file exists in any library in the loaded workflow, read it and check the `## Phases` section.
374
+
375
+ For each phase whose described functionality clearly already exists in the codebase (based on what was found in the analysis), add a note under that phase:
376
+
377
+ ```
378
+ > **Already built** — confirmed by codebase scan [date]
379
+ ```
380
+
381
+ And update its status to "Complete" if the entire phase is done.
382
+
383
+ If no `project-state.md` exists yet, skip this step silently.
384
+ </step>
385
+
386
+ <step name="summary">
387
+ Show the final summary:
388
+
389
+ ```
390
+ ✓ Codebase scan complete
391
+
392
+ Documents written to "<library name>":
393
+ ✓ stack.md — tech stack, dependencies, integrations
394
+ ✓ architecture.md — patterns, layers, data flow
395
+ ✓ structure.md — directory map, where to add new code
396
+ ✓ conventions.md — naming, code style, patterns
397
+ ✓ testing.md — test framework, structure, coverage
398
+ ✓ concerns.md — tech debt, gaps, fragile areas
399
+ ```
400
+
401
+ Then ask:
402
+
403
+ "Would you like to set up a new project plan now? Running /ium:new-project will use these documents to understand what's already built and only plan phases for what's missing."
404
+
405
+ Use AskUserQuestion:
406
+ - "Yes, run /ium:new-project now"
407
+ - "No, I'll do it later"
408
+
409
+ If yes: proceed with the /ium:new-project flow. The codebase analysis documents are now in the library and will be found automatically when the project state is being planned.
410
+ </step>
411
+
412
+ </process>
413
+
414
+ <rules>
415
+ - Never show raw bash output, file paths, or API responses to the user — only the progress indicators and final summary
416
+ - Never read `.env` file contents — only check for the file's existence and read `.env.example` or `.env.sample`
417
+ - Every finding in every document must reference a specific file path — no vague summaries
418
+ - If a pass fails silently (no files found, permission error), write what was found and note "insufficient data to analyse [area]" — never skip the document entirely
419
+ - Documents are written for future AI agents to consume, not as human prose — be specific, prescriptive, and grounded in actual file paths
420
+ - When refreshing, always use update_file not create_file to preserve file history in Contextium
421
+ - Only one set of codebase analysis documents should exist per library — never create duplicates
422
+ </rules>
@@ -29,7 +29,23 @@ Present workflow names only. Ask the user which one to load.
29
29
  contextium cat --all -w <workspace> 2>/dev/null
30
30
  ```
31
31
 
32
- 4. Output a session context block in this exact format so all resource IDs and names are available for the rest of the session without re-querying:
32
+ 4. Persist the loaded workspace and workflow to `.contextiumrc` so it can be auto-restored after `/clear`:
33
+
34
+ ```bash
35
+ node -e "
36
+ try {
37
+ const fs = require('fs');
38
+ const rc = JSON.parse(fs.readFileSync('.contextiumrc', 'utf8'));
39
+ rc.last_workflow = '<workflow-name>';
40
+ rc.last_workspace = '<workspace-slug-or-name>';
41
+ fs.writeFileSync('.contextiumrc', JSON.stringify(rc, null, 2));
42
+ } catch(e) {}
43
+ " 2>/dev/null
44
+ ```
45
+
46
+ Do this silently — never mention it to the user.
47
+
48
+ 5. Output a session context block in this exact format so all resource IDs and names are available for the rest of the session without re-querying:
33
49
 
34
50
  ```
35
51
  --- WORKFLOW SESSION CONTEXT ---
@@ -13,27 +13,28 @@ Switch the active Contextium workspace with full context handoff — save what's
13
13
  <process>
14
14
 
15
15
  <step name="show_current">
16
- Show the current workspace and list available workspaces:
16
+ Silently fetch the current workspace and available workspaces:
17
17
 
18
18
  ```bash
19
- # Show current workspace from .contextiumrc
20
- cat .contextiumrc 2>/dev/null | grep -E "workspace" | head -5 || echo "No .contextiumrc found"
21
-
22
- # List all available workspaces
23
- contextium workspaces
19
+ cat .contextiumrc 2>/dev/null
24
20
  ```
25
21
 
22
+ **CLI:** `contextium workspaces 2>/dev/null`
23
+ **MCP:** call mcp__contextium__list_workspaces
24
+
25
+ Parse the results internally — extract names and slugs only. Never show IDs, UUIDs, or raw command output to the user.
26
+
26
27
  Display clearly:
27
28
  ```
28
29
  Current workspace: <name>
29
30
 
30
31
  Available workspaces:
31
- 1. workspace-a
32
- 2. workspace-b
33
- 3. workspace-c
32
+ 1. Workspace A
33
+ 2. Workspace B
34
+ 3. Workspace C
34
35
  ```
35
36
 
36
- Ask the user which workspace to switch to using AskUserQuestion with the workspace names as options. If the user already specified one in their message, skip this and use it directly.
37
+ Ask the user which workspace to switch to using AskUserQuestion with workspace **names only** as options — no IDs, no slugs. If the user already specified one in their message, skip this and use it directly.
37
38
  </step>
38
39
 
39
40
  <step name="save_handoff">