@synth-coder/memhub 0.1.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.
Files changed (104) hide show
  1. package/.eslintrc.cjs +46 -0
  2. package/.github/workflows/ci.yml +74 -0
  3. package/.iflow/commands/opsx-apply.md +152 -0
  4. package/.iflow/commands/opsx-archive.md +157 -0
  5. package/.iflow/commands/opsx-explore.md +173 -0
  6. package/.iflow/commands/opsx-propose.md +106 -0
  7. package/.iflow/skills/openspec-apply-change/SKILL.md +156 -0
  8. package/.iflow/skills/openspec-archive-change/SKILL.md +114 -0
  9. package/.iflow/skills/openspec-explore/SKILL.md +288 -0
  10. package/.iflow/skills/openspec-propose/SKILL.md +110 -0
  11. package/.prettierrc +11 -0
  12. package/README.md +171 -0
  13. package/README.zh-CN.md +169 -0
  14. package/dist/src/contracts/index.d.ts +7 -0
  15. package/dist/src/contracts/index.d.ts.map +1 -0
  16. package/dist/src/contracts/index.js +10 -0
  17. package/dist/src/contracts/index.js.map +1 -0
  18. package/dist/src/contracts/mcp.d.ts +194 -0
  19. package/dist/src/contracts/mcp.d.ts.map +1 -0
  20. package/dist/src/contracts/mcp.js +112 -0
  21. package/dist/src/contracts/mcp.js.map +1 -0
  22. package/dist/src/contracts/schemas.d.ts +1153 -0
  23. package/dist/src/contracts/schemas.d.ts.map +1 -0
  24. package/dist/src/contracts/schemas.js +246 -0
  25. package/dist/src/contracts/schemas.js.map +1 -0
  26. package/dist/src/contracts/types.d.ts +328 -0
  27. package/dist/src/contracts/types.d.ts.map +1 -0
  28. package/dist/src/contracts/types.js +30 -0
  29. package/dist/src/contracts/types.js.map +1 -0
  30. package/dist/src/index.d.ts +8 -0
  31. package/dist/src/index.d.ts.map +1 -0
  32. package/dist/src/index.js +8 -0
  33. package/dist/src/index.js.map +1 -0
  34. package/dist/src/server/index.d.ts +5 -0
  35. package/dist/src/server/index.d.ts.map +1 -0
  36. package/dist/src/server/index.js +5 -0
  37. package/dist/src/server/index.js.map +1 -0
  38. package/dist/src/server/mcp-server.d.ts +80 -0
  39. package/dist/src/server/mcp-server.d.ts.map +1 -0
  40. package/dist/src/server/mcp-server.js +263 -0
  41. package/dist/src/server/mcp-server.js.map +1 -0
  42. package/dist/src/services/index.d.ts +5 -0
  43. package/dist/src/services/index.d.ts.map +1 -0
  44. package/dist/src/services/index.js +5 -0
  45. package/dist/src/services/index.js.map +1 -0
  46. package/dist/src/services/memory-service.d.ts +105 -0
  47. package/dist/src/services/memory-service.d.ts.map +1 -0
  48. package/dist/src/services/memory-service.js +447 -0
  49. package/dist/src/services/memory-service.js.map +1 -0
  50. package/dist/src/storage/frontmatter-parser.d.ts +69 -0
  51. package/dist/src/storage/frontmatter-parser.d.ts.map +1 -0
  52. package/dist/src/storage/frontmatter-parser.js +207 -0
  53. package/dist/src/storage/frontmatter-parser.js.map +1 -0
  54. package/dist/src/storage/index.d.ts +6 -0
  55. package/dist/src/storage/index.d.ts.map +1 -0
  56. package/dist/src/storage/index.js +6 -0
  57. package/dist/src/storage/index.js.map +1 -0
  58. package/dist/src/storage/markdown-storage.d.ts +76 -0
  59. package/dist/src/storage/markdown-storage.d.ts.map +1 -0
  60. package/dist/src/storage/markdown-storage.js +193 -0
  61. package/dist/src/storage/markdown-storage.js.map +1 -0
  62. package/dist/src/utils/index.d.ts +5 -0
  63. package/dist/src/utils/index.d.ts.map +1 -0
  64. package/dist/src/utils/index.js +5 -0
  65. package/dist/src/utils/index.js.map +1 -0
  66. package/dist/src/utils/slugify.d.ts +24 -0
  67. package/dist/src/utils/slugify.d.ts.map +1 -0
  68. package/dist/src/utils/slugify.js +56 -0
  69. package/dist/src/utils/slugify.js.map +1 -0
  70. package/docs/architecture.md +349 -0
  71. package/docs/contracts.md +119 -0
  72. package/docs/prompt-template.md +79 -0
  73. package/docs/proposal-close-gates.md +58 -0
  74. package/docs/tool-calling-policy.md +107 -0
  75. package/package.json +53 -0
  76. package/src/contracts/index.ts +12 -0
  77. package/src/contracts/mcp.ts +303 -0
  78. package/src/contracts/schemas.ts +311 -0
  79. package/src/contracts/types.ts +414 -0
  80. package/src/index.ts +8 -0
  81. package/src/server/index.ts +5 -0
  82. package/src/server/mcp-server.ts +352 -0
  83. package/src/services/index.ts +5 -0
  84. package/src/services/memory-service.ts +548 -0
  85. package/src/storage/frontmatter-parser.ts +243 -0
  86. package/src/storage/index.ts +6 -0
  87. package/src/storage/markdown-storage.ts +236 -0
  88. package/src/utils/index.ts +5 -0
  89. package/src/utils/slugify.ts +63 -0
  90. package/test/contracts/schemas.test.ts +313 -0
  91. package/test/contracts/types.test.ts +21 -0
  92. package/test/frontmatter-parser-more.test.ts +94 -0
  93. package/test/server/mcp-server-internals.test.ts +257 -0
  94. package/test/server/mcp-server.test.ts +97 -0
  95. package/test/services/memory-service-edge.test.ts +248 -0
  96. package/test/services/memory-service.test.ts +279 -0
  97. package/test/storage/frontmatter-parser.test.ts +223 -0
  98. package/test/storage/markdown-storage.test.ts +217 -0
  99. package/test/storage/storage-edge.test.ts +238 -0
  100. package/test/utils/slugify-edge.test.ts +94 -0
  101. package/test/utils/slugify.test.ts +68 -0
  102. package/tsconfig.json +26 -0
  103. package/tsconfig.test.json +8 -0
  104. package/vitest.config.ts +27 -0
package/.eslintrc.cjs ADDED
@@ -0,0 +1,46 @@
1
+ module.exports = {
2
+ root: true,
3
+ parser: '@typescript-eslint/parser',
4
+ parserOptions: {
5
+ ecmaVersion: 2022,
6
+ sourceType: 'module',
7
+ project: ['./tsconfig.json', './tsconfig.test.json'],
8
+ tsconfigRootDir: __dirname,
9
+ },
10
+ plugins: ['@typescript-eslint'],
11
+ extends: [
12
+ 'eslint:recommended',
13
+ 'plugin:@typescript-eslint/recommended',
14
+ 'plugin:@typescript-eslint/recommended-requiring-type-checking',
15
+ 'prettier',
16
+ ],
17
+ rules: {
18
+ '@typescript-eslint/explicit-function-return-type': 'off',
19
+ '@typescript-eslint/no-explicit-any': 'error',
20
+ '@typescript-eslint/no-unused-vars': ['error', { argsIgnorePattern: '^_' }],
21
+ '@typescript-eslint/prefer-readonly': 'error',
22
+ '@typescript-eslint/strict-boolean-expressions': 'off',
23
+ 'no-console': ['warn', { allow: ['error', 'warn'] }],
24
+ 'import/no-unresolved': 'off',
25
+ 'import/order': 'off',
26
+ },
27
+ env: {
28
+ node: true,
29
+ es2022: true,
30
+ },
31
+ ignorePatterns: ['dist/', 'node_modules/', '*.config.*'],
32
+ overrides: [
33
+ {
34
+ // Test files
35
+ files: ['test/**/*.ts'],
36
+ rules: {
37
+ '@typescript-eslint/no-unused-vars': 'off',
38
+ '@typescript-eslint/require-await': 'off',
39
+ '@typescript-eslint/no-unsafe-assignment': 'off',
40
+ '@typescript-eslint/no-unsafe-member-access': 'off',
41
+ '@typescript-eslint/no-unsafe-call': 'off',
42
+ '@typescript-eslint/no-unsafe-return': 'off',
43
+ },
44
+ },
45
+ ],
46
+ };
@@ -0,0 +1,74 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches: [main, master]
6
+ pull_request:
7
+ branches: [main, master]
8
+
9
+ jobs:
10
+ quality:
11
+ name: Quality Gate
12
+ runs-on: ubuntu-latest
13
+
14
+ strategy:
15
+ matrix:
16
+ node-version: [18.x, 20.x]
17
+
18
+ steps:
19
+ - name: Checkout repository
20
+ uses: actions/checkout@v4
21
+
22
+ - name: Setup Node.js ${{ matrix.node-version }}
23
+ uses: actions/setup-node@v4
24
+ with:
25
+ node-version: ${{ matrix.node-version }}
26
+ cache: 'npm'
27
+
28
+ - name: Install dependencies
29
+ run: npm ci
30
+
31
+ - name: Run linter
32
+ run: npm run lint
33
+
34
+ - name: Check formatting
35
+ run: npm run format:check
36
+
37
+ - name: Run type check
38
+ run: npm run typecheck
39
+
40
+ - name: Run tests with coverage
41
+ run: npm run test:coverage
42
+
43
+ - name: Upload coverage reports
44
+ uses: codecov/codecov-action@v3
45
+ if: matrix.node-version == '20.x'
46
+ with:
47
+ files: ./coverage/lcov.info
48
+ fail_ci_if_error: false
49
+
50
+ build:
51
+ name: Build
52
+ runs-on: ubuntu-latest
53
+ needs: quality
54
+
55
+ steps:
56
+ - name: Checkout repository
57
+ uses: actions/checkout@v4
58
+
59
+ - name: Setup Node.js
60
+ uses: actions/setup-node@v4
61
+ with:
62
+ node-version: 20.x
63
+ cache: 'npm'
64
+
65
+ - name: Install dependencies
66
+ run: npm ci
67
+
68
+ - name: Build project
69
+ run: npm run build
70
+
71
+ - name: Check build output
72
+ run: |
73
+ test -f dist/index.js
74
+ test -f dist/server/mcp-server.js
@@ -0,0 +1,152 @@
1
+ ---
2
+ name: /opsx-apply
3
+ id: opsx-apply
4
+ category: Workflow
5
+ description: Implement tasks from an OpenSpec change (Experimental)
6
+ ---
7
+
8
+ Implement tasks from an OpenSpec change.
9
+
10
+ **Input**: Optionally specify a change name (e.g., `/opsx:apply add-auth`). If omitted, check if it can be inferred from conversation context. If vague or ambiguous you MUST prompt for available changes.
11
+
12
+ **Steps**
13
+
14
+ 1. **Select the change**
15
+
16
+ If a name is provided, use it. Otherwise:
17
+ - Infer from conversation context if the user mentioned a change
18
+ - Auto-select if only one active change exists
19
+ - If ambiguous, run `openspec list --json` to get available changes and use the **AskUserQuestion tool** to let the user select
20
+
21
+ Always announce: "Using change: <name>" and how to override (e.g., `/opsx:apply <other>`).
22
+
23
+ 2. **Check status to understand the schema**
24
+ ```bash
25
+ openspec status --change "<name>" --json
26
+ ```
27
+ Parse the JSON to understand:
28
+ - `schemaName`: The workflow being used (e.g., "spec-driven")
29
+ - Which artifact contains the tasks (typically "tasks" for spec-driven, check status for others)
30
+
31
+ 3. **Get apply instructions**
32
+
33
+ ```bash
34
+ openspec instructions apply --change "<name>" --json
35
+ ```
36
+
37
+ This returns:
38
+ - Context file paths (varies by schema)
39
+ - Progress (total, complete, remaining)
40
+ - Task list with status
41
+ - Dynamic instruction based on current state
42
+
43
+ **Handle states:**
44
+ - If `state: "blocked"` (missing artifacts): show message, suggest using `/opsx:continue`
45
+ - If `state: "all_done"`: congratulate, suggest archive
46
+ - Otherwise: proceed to implementation
47
+
48
+ 4. **Read context files**
49
+
50
+ Read the files listed in `contextFiles` from the apply instructions output.
51
+ The files depend on the schema being used:
52
+ - **spec-driven**: proposal, specs, design, tasks
53
+ - Other schemas: follow the contextFiles from CLI output
54
+
55
+ 5. **Show current progress**
56
+
57
+ Display:
58
+ - Schema being used
59
+ - Progress: "N/M tasks complete"
60
+ - Remaining tasks overview
61
+ - Dynamic instruction from CLI
62
+
63
+ 6. **Implement tasks (loop until done or blocked)**
64
+
65
+ For each pending task:
66
+ - Show which task is being worked on
67
+ - Make the code changes required
68
+ - Keep changes minimal and focused
69
+ - Mark task complete in the tasks file: `- [ ]` → `- [x]`
70
+ - Continue to next task
71
+
72
+ **Pause if:**
73
+ - Task is unclear → ask for clarification
74
+ - Implementation reveals a design issue → suggest updating artifacts
75
+ - Error or blocker encountered → report and wait for guidance
76
+ - User interrupts
77
+
78
+ 7. **On completion or pause, show status**
79
+
80
+ Display:
81
+ - Tasks completed this session
82
+ - Overall progress: "N/M tasks complete"
83
+ - If all done: suggest archive
84
+ - If paused: explain why and wait for guidance
85
+
86
+ **Output During Implementation**
87
+
88
+ ```
89
+ ## Implementing: <change-name> (schema: <schema-name>)
90
+
91
+ Working on task 3/7: <task description>
92
+ [...implementation happening...]
93
+ ✓ Task complete
94
+
95
+ Working on task 4/7: <task description>
96
+ [...implementation happening...]
97
+ ✓ Task complete
98
+ ```
99
+
100
+ **Output On Completion**
101
+
102
+ ```
103
+ ## Implementation Complete
104
+
105
+ **Change:** <change-name>
106
+ **Schema:** <schema-name>
107
+ **Progress:** 7/7 tasks complete ✓
108
+
109
+ ### Completed This Session
110
+ - [x] Task 1
111
+ - [x] Task 2
112
+ ...
113
+
114
+ All tasks complete! You can archive this change with `/opsx:archive`.
115
+ ```
116
+
117
+ **Output On Pause (Issue Encountered)**
118
+
119
+ ```
120
+ ## Implementation Paused
121
+
122
+ **Change:** <change-name>
123
+ **Schema:** <schema-name>
124
+ **Progress:** 4/7 tasks complete
125
+
126
+ ### Issue Encountered
127
+ <description of the issue>
128
+
129
+ **Options:**
130
+ 1. <option 1>
131
+ 2. <option 2>
132
+ 3. Other approach
133
+
134
+ What would you like to do?
135
+ ```
136
+
137
+ **Guardrails**
138
+ - Keep going through tasks until done or blocked
139
+ - Always read context files before starting (from the apply instructions output)
140
+ - If task is ambiguous, pause and ask before implementing
141
+ - If implementation reveals issues, pause and suggest artifact updates
142
+ - Keep code changes minimal and scoped to each task
143
+ - Update task checkbox immediately after completing each task
144
+ - Pause on errors, blockers, or unclear requirements - don't guess
145
+ - Use contextFiles from CLI output, don't assume specific file names
146
+
147
+ **Fluid Workflow Integration**
148
+
149
+ This skill supports the "actions on a change" model:
150
+
151
+ - **Can be invoked anytime**: Before all artifacts are done (if tasks exist), after partial implementation, interleaved with other actions
152
+ - **Allows artifact updates**: If implementation reveals design issues, suggest updating artifacts - not phase-locked, work fluidly
@@ -0,0 +1,157 @@
1
+ ---
2
+ name: /opsx-archive
3
+ id: opsx-archive
4
+ category: Workflow
5
+ description: Archive a completed change in the experimental workflow
6
+ ---
7
+
8
+ Archive a completed change in the experimental workflow.
9
+
10
+ **Input**: Optionally specify a change name after `/opsx:archive` (e.g., `/opsx:archive add-auth`). If omitted, check if it can be inferred from conversation context. If vague or ambiguous you MUST prompt for available changes.
11
+
12
+ **Steps**
13
+
14
+ 1. **If no change name provided, prompt for selection**
15
+
16
+ Run `openspec list --json` to get available changes. Use the **AskUserQuestion tool** to let the user select.
17
+
18
+ Show only active changes (not already archived).
19
+ Include the schema used for each change if available.
20
+
21
+ **IMPORTANT**: Do NOT guess or auto-select a change. Always let the user choose.
22
+
23
+ 2. **Check artifact completion status**
24
+
25
+ Run `openspec status --change "<name>" --json` to check artifact completion.
26
+
27
+ Parse the JSON to understand:
28
+ - `schemaName`: The workflow being used
29
+ - `artifacts`: List of artifacts with their status (`done` or other)
30
+
31
+ **If any artifacts are not `done`:**
32
+ - Display warning listing incomplete artifacts
33
+ - Prompt user for confirmation to continue
34
+ - Proceed if user confirms
35
+
36
+ 3. **Check task completion status**
37
+
38
+ Read the tasks file (typically `tasks.md`) to check for incomplete tasks.
39
+
40
+ Count tasks marked with `- [ ]` (incomplete) vs `- [x]` (complete).
41
+
42
+ **If incomplete tasks found:**
43
+ - Display warning showing count of incomplete tasks
44
+ - Prompt user for confirmation to continue
45
+ - Proceed if user confirms
46
+
47
+ **If no tasks file exists:** Proceed without task-related warning.
48
+
49
+ 4. **Assess delta spec sync state**
50
+
51
+ Check for delta specs at `openspec/changes/<name>/specs/`. If none exist, proceed without sync prompt.
52
+
53
+ **If delta specs exist:**
54
+ - Compare each delta spec with its corresponding main spec at `openspec/specs/<capability>/spec.md`
55
+ - Determine what changes would be applied (adds, modifications, removals, renames)
56
+ - Show a combined summary before prompting
57
+
58
+ **Prompt options:**
59
+ - If changes needed: "Sync now (recommended)", "Archive without syncing"
60
+ - If already synced: "Archive now", "Sync anyway", "Cancel"
61
+
62
+ If user chooses sync, use Task tool (subagent_type: "general-purpose", prompt: "Use Skill tool to invoke openspec-sync-specs for change '<name>'. Delta spec analysis: <include the analyzed delta spec summary>"). Proceed to archive regardless of choice.
63
+
64
+ 5. **Perform the archive**
65
+
66
+ Create the archive directory if it doesn't exist:
67
+ ```bash
68
+ mkdir -p openspec/changes/archive
69
+ ```
70
+
71
+ Generate target name using current date: `YYYY-MM-DD-<change-name>`
72
+
73
+ **Check if target already exists:**
74
+ - If yes: Fail with error, suggest renaming existing archive or using different date
75
+ - If no: Move the change directory to archive
76
+
77
+ ```bash
78
+ mv openspec/changes/<name> openspec/changes/archive/YYYY-MM-DD-<name>
79
+ ```
80
+
81
+ 6. **Display summary**
82
+
83
+ Show archive completion summary including:
84
+ - Change name
85
+ - Schema that was used
86
+ - Archive location
87
+ - Spec sync status (synced / sync skipped / no delta specs)
88
+ - Note about any warnings (incomplete artifacts/tasks)
89
+
90
+ **Output On Success**
91
+
92
+ ```
93
+ ## Archive Complete
94
+
95
+ **Change:** <change-name>
96
+ **Schema:** <schema-name>
97
+ **Archived to:** openspec/changes/archive/YYYY-MM-DD-<name>/
98
+ **Specs:** ✓ Synced to main specs
99
+
100
+ All artifacts complete. All tasks complete.
101
+ ```
102
+
103
+ **Output On Success (No Delta Specs)**
104
+
105
+ ```
106
+ ## Archive Complete
107
+
108
+ **Change:** <change-name>
109
+ **Schema:** <schema-name>
110
+ **Archived to:** openspec/changes/archive/YYYY-MM-DD-<name>/
111
+ **Specs:** No delta specs
112
+
113
+ All artifacts complete. All tasks complete.
114
+ ```
115
+
116
+ **Output On Success With Warnings**
117
+
118
+ ```
119
+ ## Archive Complete (with warnings)
120
+
121
+ **Change:** <change-name>
122
+ **Schema:** <schema-name>
123
+ **Archived to:** openspec/changes/archive/YYYY-MM-DD-<name>/
124
+ **Specs:** Sync skipped (user chose to skip)
125
+
126
+ **Warnings:**
127
+ - Archived with 2 incomplete artifacts
128
+ - Archived with 3 incomplete tasks
129
+ - Delta spec sync was skipped (user chose to skip)
130
+
131
+ Review the archive if this was not intentional.
132
+ ```
133
+
134
+ **Output On Error (Archive Exists)**
135
+
136
+ ```
137
+ ## Archive Failed
138
+
139
+ **Change:** <change-name>
140
+ **Target:** openspec/changes/archive/YYYY-MM-DD-<name>/
141
+
142
+ Target archive directory already exists.
143
+
144
+ **Options:**
145
+ 1. Rename the existing archive
146
+ 2. Delete the existing archive if it's a duplicate
147
+ 3. Wait until a different date to archive
148
+ ```
149
+
150
+ **Guardrails**
151
+ - Always prompt for change selection if not provided
152
+ - Use artifact graph (openspec status --json) for completion checking
153
+ - Don't block archive on warnings - just inform and confirm
154
+ - Preserve .openspec.yaml when moving to archive (it moves with the directory)
155
+ - Show clear summary of what happened
156
+ - If sync is requested, use the Skill tool to invoke `openspec-sync-specs` (agent-driven)
157
+ - If delta specs exist, always run the sync assessment and show the combined summary before prompting
@@ -0,0 +1,173 @@
1
+ ---
2
+ name: /opsx-explore
3
+ id: opsx-explore
4
+ category: Workflow
5
+ description: Enter explore mode - think through ideas, investigate problems, clarify requirements
6
+ ---
7
+
8
+ Enter explore mode. Think deeply. Visualize freely. Follow the conversation wherever it goes.
9
+
10
+ **IMPORTANT: Explore mode is for thinking, not implementing.** You may read files, search code, and investigate the codebase, but you must NEVER write code or implement features. If the user asks you to implement something, remind them to exit explore mode first and create a change proposal. You MAY create OpenSpec artifacts (proposals, designs, specs) if the user asks—that's capturing thinking, not implementing.
11
+
12
+ **This is a stance, not a workflow.** There are no fixed steps, no required sequence, no mandatory outputs. You're a thinking partner helping the user explore.
13
+
14
+ **Input**: The argument after `/opsx:explore` is whatever the user wants to think about. Could be:
15
+ - A vague idea: "real-time collaboration"
16
+ - A specific problem: "the auth system is getting unwieldy"
17
+ - A change name: "add-dark-mode" (to explore in context of that change)
18
+ - A comparison: "postgres vs sqlite for this"
19
+ - Nothing (just enter explore mode)
20
+
21
+ ---
22
+
23
+ ## The Stance
24
+
25
+ - **Curious, not prescriptive** - Ask questions that emerge naturally, don't follow a script
26
+ - **Open threads, not interrogations** - Surface multiple interesting directions and let the user follow what resonates. Don't funnel them through a single path of questions.
27
+ - **Visual** - Use ASCII diagrams liberally when they'd help clarify thinking
28
+ - **Adaptive** - Follow interesting threads, pivot when new information emerges
29
+ - **Patient** - Don't rush to conclusions, let the shape of the problem emerge
30
+ - **Grounded** - Explore the actual codebase when relevant, don't just theorize
31
+
32
+ ---
33
+
34
+ ## What You Might Do
35
+
36
+ Depending on what the user brings, you might:
37
+
38
+ **Explore the problem space**
39
+ - Ask clarifying questions that emerge from what they said
40
+ - Challenge assumptions
41
+ - Reframe the problem
42
+ - Find analogies
43
+
44
+ **Investigate the codebase**
45
+ - Map existing architecture relevant to the discussion
46
+ - Find integration points
47
+ - Identify patterns already in use
48
+ - Surface hidden complexity
49
+
50
+ **Compare options**
51
+ - Brainstorm multiple approaches
52
+ - Build comparison tables
53
+ - Sketch tradeoffs
54
+ - Recommend a path (if asked)
55
+
56
+ **Visualize**
57
+ ```
58
+ ┌─────────────────────────────────────────┐
59
+ │ Use ASCII diagrams liberally │
60
+ ├─────────────────────────────────────────┤
61
+ │ │
62
+ │ ┌────────┐ ┌────────┐ │
63
+ │ │ State │────────▶│ State │ │
64
+ │ │ A │ │ B │ │
65
+ │ └────────┘ └────────┘ │
66
+ │ │
67
+ │ System diagrams, state machines, │
68
+ │ data flows, architecture sketches, │
69
+ │ dependency graphs, comparison tables │
70
+ │ │
71
+ └─────────────────────────────────────────┘
72
+ ```
73
+
74
+ **Surface risks and unknowns**
75
+ - Identify what could go wrong
76
+ - Find gaps in understanding
77
+ - Suggest spikes or investigations
78
+
79
+ ---
80
+
81
+ ## OpenSpec Awareness
82
+
83
+ You have full context of the OpenSpec system. Use it naturally, don't force it.
84
+
85
+ ### Check for context
86
+
87
+ At the start, quickly check what exists:
88
+ ```bash
89
+ openspec list --json
90
+ ```
91
+
92
+ This tells you:
93
+ - If there are active changes
94
+ - Their names, schemas, and status
95
+ - What the user might be working on
96
+
97
+ If the user mentioned a specific change name, read its artifacts for context.
98
+
99
+ ### When no change exists
100
+
101
+ Think freely. When insights crystallize, you might offer:
102
+
103
+ - "This feels solid enough to start a change. Want me to create a proposal?"
104
+ - Or keep exploring - no pressure to formalize
105
+
106
+ ### When a change exists
107
+
108
+ If the user mentions a change or you detect one is relevant:
109
+
110
+ 1. **Read existing artifacts for context**
111
+ - `openspec/changes/<name>/proposal.md`
112
+ - `openspec/changes/<name>/design.md`
113
+ - `openspec/changes/<name>/tasks.md`
114
+ - etc.
115
+
116
+ 2. **Reference them naturally in conversation**
117
+ - "Your design mentions using Redis, but we just realized SQLite fits better..."
118
+ - "The proposal scopes this to premium users, but we're now thinking everyone..."
119
+
120
+ 3. **Offer to capture when decisions are made**
121
+
122
+ | Insight Type | Where to Capture |
123
+ |--------------|------------------|
124
+ | New requirement discovered | `specs/<capability>/spec.md` |
125
+ | Requirement changed | `specs/<capability>/spec.md` |
126
+ | Design decision made | `design.md` |
127
+ | Scope changed | `proposal.md` |
128
+ | New work identified | `tasks.md` |
129
+ | Assumption invalidated | Relevant artifact |
130
+
131
+ Example offers:
132
+ - "That's a design decision. Capture it in design.md?"
133
+ - "This is a new requirement. Add it to specs?"
134
+ - "This changes scope. Update the proposal?"
135
+
136
+ 4. **The user decides** - Offer and move on. Don't pressure. Don't auto-capture.
137
+
138
+ ---
139
+
140
+ ## What You Don't Have To Do
141
+
142
+ - Follow a script
143
+ - Ask the same questions every time
144
+ - Produce a specific artifact
145
+ - Reach a conclusion
146
+ - Stay on topic if a tangent is valuable
147
+ - Be brief (this is thinking time)
148
+
149
+ ---
150
+
151
+ ## Ending Discovery
152
+
153
+ There's no required ending. Discovery might:
154
+
155
+ - **Flow into a proposal**: "Ready to start? I can create a change proposal."
156
+ - **Result in artifact updates**: "Updated design.md with these decisions"
157
+ - **Just provide clarity**: User has what they need, moves on
158
+ - **Continue later**: "We can pick this up anytime"
159
+
160
+ When things crystallize, you might offer a summary - but it's optional. Sometimes the thinking IS the value.
161
+
162
+ ---
163
+
164
+ ## Guardrails
165
+
166
+ - **Don't implement** - Never write code or implement features. Creating OpenSpec artifacts is fine, writing application code is not.
167
+ - **Don't fake understanding** - If something is unclear, dig deeper
168
+ - **Don't rush** - Discovery is thinking time, not task time
169
+ - **Don't force structure** - Let patterns emerge naturally
170
+ - **Don't auto-capture** - Offer to save insights, don't just do it
171
+ - **Do visualize** - A good diagram is worth many paragraphs
172
+ - **Do explore the codebase** - Ground discussions in reality
173
+ - **Do question assumptions** - Including the user's and your own