opencodekit 0.21.10 → 0.23.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 (213) hide show
  1. package/README.md +1 -1
  2. package/dist/index.js +4 -25
  3. package/dist/template/.opencode/.template-manifest.json +115 -188
  4. package/dist/template/.opencode/AGENTS.md +127 -484
  5. package/dist/template/.opencode/README.md +2 -2
  6. package/dist/template/.opencode/agent/build.md +158 -356
  7. package/dist/template/.opencode/agent/explore.md +0 -1
  8. package/dist/template/.opencode/agent/plan.md +7 -16
  9. package/dist/template/.opencode/agent/review.md +0 -1
  10. package/dist/template/.opencode/agent/scout.md +2 -3
  11. package/dist/template/.opencode/agent/vision.md +0 -1
  12. package/dist/template/.opencode/artifacts/.active +1 -0
  13. package/dist/template/.opencode/artifacts/example/plan.md +12 -0
  14. package/dist/template/.opencode/artifacts/example/progress.md +4 -0
  15. package/dist/template/.opencode/artifacts/example/research.md +4 -0
  16. package/dist/template/.opencode/artifacts/example/spec.md +16 -0
  17. package/dist/template/.opencode/artifacts/todo.md +5 -0
  18. package/dist/template/.opencode/artifacts/verify.log +4 -0
  19. package/dist/template/.opencode/command/clarify.md +46 -0
  20. package/dist/template/.opencode/command/commit.md +53 -0
  21. package/dist/template/.opencode/command/create.md +29 -71
  22. package/dist/template/.opencode/command/design.md +1 -2
  23. package/dist/template/.opencode/command/explore.md +3 -4
  24. package/dist/template/.opencode/command/fix.md +55 -0
  25. package/dist/template/.opencode/command/improve-architecture.md +55 -0
  26. package/dist/template/.opencode/command/init.md +86 -69
  27. package/dist/template/.opencode/command/plan.md +30 -60
  28. package/dist/template/.opencode/command/pr.md +10 -28
  29. package/dist/template/.opencode/command/refactor.md +65 -0
  30. package/dist/template/.opencode/command/research.md +7 -29
  31. package/dist/template/.opencode/command/review-codebase.md +6 -13
  32. package/dist/template/.opencode/command/ship.md +136 -78
  33. package/dist/template/.opencode/command/test.md +66 -0
  34. package/dist/template/.opencode/command/ui-review.md +2 -4
  35. package/dist/template/.opencode/command/verify.md +15 -23
  36. package/dist/template/.opencode/dcp.jsonc +96 -85
  37. package/dist/template/.opencode/memory/README.md +4 -6
  38. package/dist/template/.opencode/memory/_templates/adr.md +45 -0
  39. package/dist/template/.opencode/memory/_templates/prd.md +1 -1
  40. package/dist/template/.opencode/memory/_templates/roadmap.md +1 -1
  41. package/dist/template/.opencode/memory/_templates/state.md +1 -1
  42. package/dist/template/.opencode/memory/project/gotchas.md +4 -4
  43. package/dist/template/.opencode/memory/project/project.md +2 -2
  44. package/dist/template/.opencode/memory/project/roadmap.md +1 -1
  45. package/dist/template/.opencode/memory/project/state.md +2 -2
  46. package/dist/template/.opencode/memory/project/tech-stack.md +2 -2
  47. package/dist/template/.opencode/memory/session-context.md +1 -1
  48. package/dist/template/.opencode/opencode.json +14 -152
  49. package/dist/template/.opencode/plugin/README.md +2 -2
  50. package/dist/template/.opencode/plugin/guard.ts +62 -0
  51. package/dist/template/.opencode/plugin/{lib/memory-admin-tools.ts → memory/admin.ts} +4 -4
  52. package/dist/template/.opencode/plugin/{lib → memory}/capture.ts +1 -1
  53. package/dist/template/.opencode/plugin/{lib → memory}/compile.ts +2 -2
  54. package/dist/template/.opencode/plugin/{lib → memory}/context.ts +1 -1
  55. package/dist/template/.opencode/plugin/{lib → memory}/curator.ts +1 -1
  56. package/dist/template/.opencode/plugin/{lib → memory}/db/observations.ts +102 -3
  57. package/dist/template/.opencode/plugin/{lib → memory}/db/schema.ts +43 -1
  58. package/dist/template/.opencode/plugin/{lib → memory}/db/types.ts +22 -0
  59. package/dist/template/.opencode/plugin/{lib/memory-db.ts → memory/db.ts} +1 -1
  60. package/dist/template/.opencode/plugin/{lib → memory}/distill.ts +1 -1
  61. package/dist/template/.opencode/plugin/{lib/memory-helpers.ts → memory/helpers.ts} +5 -1
  62. package/dist/template/.opencode/plugin/{lib/memory-hooks.ts → memory/hooks.ts} +1 -1
  63. package/dist/template/.opencode/plugin/{lib → memory}/index-generator.ts +2 -2
  64. package/dist/template/.opencode/plugin/{lib → memory}/inject.ts +1 -1
  65. package/dist/template/.opencode/plugin/{lib → memory}/lint.ts +2 -2
  66. package/dist/template/.opencode/plugin/memory/tools.ts +322 -0
  67. package/dist/template/.opencode/plugin/{lib → memory}/validate.ts +2 -2
  68. package/dist/template/.opencode/plugin/memory.ts +7 -17
  69. package/dist/template/.opencode/plugin/srcwalk.ts +721 -0
  70. package/dist/template/.opencode/skill/agent-code-quality-gate/SKILL.md +98 -0
  71. package/dist/template/.opencode/skill/behavioral-kernel/SKILL.md +52 -0
  72. package/dist/template/.opencode/skill/brainstorming/SKILL.md +1 -1
  73. package/dist/template/.opencode/skill/browser-testing-with-devtools/SKILL.md +85 -0
  74. package/dist/template/.opencode/skill/code-cleanup/SKILL.md +114 -0
  75. package/dist/template/.opencode/skill/code-navigation/SKILL.md +142 -0
  76. package/dist/template/.opencode/skill/code-review-and-quality/SKILL.md +131 -0
  77. package/dist/template/.opencode/skill/context-engineering/SKILL.md +1 -1
  78. package/dist/template/.opencode/skill/debugging-and-error-recovery/SKILL.md +109 -0
  79. package/dist/template/.opencode/skill/deep-module-design/SKILL.md +207 -0
  80. package/dist/template/.opencode/skill/development-lifecycle/SKILL.md +26 -45
  81. package/dist/template/.opencode/skill/gemini-large-context/SKILL.md +4 -4
  82. package/dist/template/.opencode/skill/git-workflow-and-versioning/SKILL.md +77 -0
  83. package/dist/template/.opencode/skill/grill-me/SKILL.md +140 -0
  84. package/dist/template/.opencode/skill/memory-system/SKILL.md +9 -10
  85. package/dist/template/.opencode/skill/opensrc/references/example-workflow.md +1 -1
  86. package/dist/template/.opencode/skill/planning-and-task-breakdown/SKILL.md +116 -0
  87. package/dist/template/.opencode/skill/shipping-and-launch/SKILL.md +95 -0
  88. package/dist/template/.opencode/skill/source-driven-development/SKILL.md +103 -0
  89. package/dist/template/.opencode/skill/spec-driven-development/SKILL.md +121 -0
  90. package/dist/template/.opencode/skill/srcwalk/SKILL.md +161 -0
  91. package/dist/template/.opencode/skill/subagent-driven-development/SKILL.md +1 -1
  92. package/dist/template/.opencode/skill/ubiquitous-language/SKILL.md +184 -0
  93. package/dist/template/.opencode/skill/using-git-worktrees/SKILL.md +6 -6
  94. package/dist/template/.opencode/skill/verification-before-completion/SKILL.md +6 -6
  95. package/dist/template/.opencode/skill/verification-before-completion/references/VERIFICATION_PROTOCOL.md +5 -5
  96. package/package.json +76 -76
  97. package/dist/template/.opencode/AGENT_ALIGNMENT.md +0 -564
  98. package/dist/template/.opencode/agent/painter.md +0 -83
  99. package/dist/template/.opencode/command/compound.md +0 -240
  100. package/dist/template/.opencode/command/curate.md +0 -299
  101. package/dist/template/.opencode/command/handoff.md +0 -149
  102. package/dist/template/.opencode/command/health.md +0 -356
  103. package/dist/template/.opencode/command/init-context.md +0 -297
  104. package/dist/template/.opencode/command/init-user.md +0 -125
  105. package/dist/template/.opencode/command/iterate.md +0 -200
  106. package/dist/template/.opencode/command/lfg.md +0 -173
  107. package/dist/template/.opencode/command/resume.md +0 -78
  108. package/dist/template/.opencode/command/status.md +0 -126
  109. package/dist/template/.opencode/command/ui-slop-check.md +0 -169
  110. package/dist/template/.opencode/plans/1768385996691-silent-wizard.md +0 -247
  111. package/dist/template/.opencode/plans/1770006237537-mighty-otter.md +0 -418
  112. package/dist/template/.opencode/plans/1770006913647-glowing-forest.md +0 -170
  113. package/dist/template/.opencode/plans/1770013678126-witty-planet.md +0 -278
  114. package/dist/template/.opencode/plans/1770112267595-shiny-rocket.md +0 -258
  115. package/dist/template/.opencode/plans/swarm-protocol.md +0 -123
  116. package/dist/template/.opencode/plugin/lib/memory-tools.ts +0 -535
  117. package/dist/template/.opencode/skill/agent-evals/SKILL.md +0 -208
  118. package/dist/template/.opencode/skill/anti-ai-slop/SKILL.md +0 -76
  119. package/dist/template/.opencode/skill/augment-context-engine/SKILL.md +0 -122
  120. package/dist/template/.opencode/skill/augment-context-engine/mcp.json +0 -6
  121. package/dist/template/.opencode/skill/beads/SKILL.md +0 -182
  122. package/dist/template/.opencode/skill/beads/references/BEST_PRACTICES.md +0 -27
  123. package/dist/template/.opencode/skill/beads/references/BOUNDARIES.md +0 -219
  124. package/dist/template/.opencode/skill/beads/references/DEPENDENCIES.md +0 -124
  125. package/dist/template/.opencode/skill/beads/references/EXAMPLES.md +0 -45
  126. package/dist/template/.opencode/skill/beads/references/FILE_CLAIMING.md +0 -101
  127. package/dist/template/.opencode/skill/beads/references/GIT_SYNC.md +0 -25
  128. package/dist/template/.opencode/skill/beads/references/HIERARCHY.md +0 -71
  129. package/dist/template/.opencode/skill/beads/references/MULTI_AGENT.md +0 -40
  130. package/dist/template/.opencode/skill/beads/references/RESUMABILITY.md +0 -177
  131. package/dist/template/.opencode/skill/beads/references/SESSION_PROTOCOL.md +0 -61
  132. package/dist/template/.opencode/skill/beads/references/TASK_CREATION.md +0 -38
  133. package/dist/template/.opencode/skill/beads/references/TROUBLESHOOTING.md +0 -38
  134. package/dist/template/.opencode/skill/beads/references/WORKFLOWS.md +0 -226
  135. package/dist/template/.opencode/skill/brand-asset-protocol/SKILL.md +0 -222
  136. package/dist/template/.opencode/skill/code-search-patterns/SKILL.md +0 -224
  137. package/dist/template/.opencode/skill/code-simplification/SKILL.md +0 -211
  138. package/dist/template/.opencode/skill/context-condensation/SKILL.md +0 -149
  139. package/dist/template/.opencode/skill/context-initialization/SKILL.md +0 -69
  140. package/dist/template/.opencode/skill/context-management/SKILL.md +0 -390
  141. package/dist/template/.opencode/skill/deep-research/SKILL.md +0 -384
  142. package/dist/template/.opencode/skill/design-direction-advisor/SKILL.md +0 -139
  143. package/dist/template/.opencode/skill/dispatching-parallel-agents/SKILL.md +0 -191
  144. package/dist/template/.opencode/skill/executing-plans/SKILL.md +0 -247
  145. package/dist/template/.opencode/skill/figma-go/SKILL.md +0 -65
  146. package/dist/template/.opencode/skill/finishing-a-development-branch/SKILL.md +0 -357
  147. package/dist/template/.opencode/skill/full-output-enforcement/SKILL.md +0 -62
  148. package/dist/template/.opencode/skill/gh-address-comments/SKILL.md +0 -29
  149. package/dist/template/.opencode/skill/gh-address-comments/scripts/fetch_comments.py +0 -237
  150. package/dist/template/.opencode/skill/gh-fix-ci/SKILL.md +0 -38
  151. package/dist/template/.opencode/skill/gh-fix-ci/scripts/inspect_pr_checks.py +0 -509
  152. package/dist/template/.opencode/skill/hi-fi-prototype-html/SKILL.md +0 -253
  153. package/dist/template/.opencode/skill/html-deck-export/SKILL.md +0 -189
  154. package/dist/template/.opencode/skill/index-knowledge/SKILL.md +0 -413
  155. package/dist/template/.opencode/skill/memory-grounding/SKILL.md +0 -68
  156. package/dist/template/.opencode/skill/playwriter/SKILL.md +0 -158
  157. package/dist/template/.opencode/skill/portless/SKILL.md +0 -109
  158. package/dist/template/.opencode/skill/prd/SKILL.md +0 -146
  159. package/dist/template/.opencode/skill/prd-task/SKILL.md +0 -182
  160. package/dist/template/.opencode/skill/prd-task/references/prd-schema.json +0 -124
  161. package/dist/template/.opencode/skill/prompt-leverage/SKILL.md +0 -90
  162. package/dist/template/.opencode/skill/prompt-leverage/references/framework.md +0 -91
  163. package/dist/template/.opencode/skill/prompt-leverage/scripts/augment_prompt.py +0 -157
  164. package/dist/template/.opencode/skill/receiving-code-review/SKILL.md +0 -263
  165. package/dist/template/.opencode/skill/reconcile/SKILL.md +0 -183
  166. package/dist/template/.opencode/skill/reflection-checkpoints/SKILL.md +0 -183
  167. package/dist/template/.opencode/skill/requesting-code-review/SKILL.md +0 -443
  168. package/dist/template/.opencode/skill/requesting-code-review/references/specialist-profiles.md +0 -108
  169. package/dist/template/.opencode/skill/requesting-code-review/review.md +0 -160
  170. package/dist/template/.opencode/skill/rtk-command-compression/SKILL.md +0 -134
  171. package/dist/template/.opencode/skill/screenshot/SKILL.md +0 -48
  172. package/dist/template/.opencode/skill/screenshot/scripts/ensure_macos_permissions.sh +0 -54
  173. package/dist/template/.opencode/skill/screenshot/scripts/macos_display_info.swift +0 -22
  174. package/dist/template/.opencode/skill/screenshot/scripts/macos_permissions.swift +0 -40
  175. package/dist/template/.opencode/skill/screenshot/scripts/macos_window_info.swift +0 -126
  176. package/dist/template/.opencode/skill/screenshot/scripts/take_screenshot.ps1 +0 -163
  177. package/dist/template/.opencode/skill/screenshot/scripts/take_screenshot.py +0 -585
  178. package/dist/template/.opencode/skill/security-threat-model/SKILL.md +0 -36
  179. package/dist/template/.opencode/skill/security-threat-model/references/prompt-template.md +0 -255
  180. package/dist/template/.opencode/skill/security-threat-model/references/security-controls-and-assets.md +0 -32
  181. package/dist/template/.opencode/skill/sharing-skills/SKILL.md +0 -214
  182. package/dist/template/.opencode/skill/skill-creator/SKILL.md +0 -181
  183. package/dist/template/.opencode/skill/skill-installer/SKILL.md +0 -58
  184. package/dist/template/.opencode/skill/skill-installer/scripts/github_utils.py +0 -21
  185. package/dist/template/.opencode/skill/skill-installer/scripts/install-skill-from-github.py +0 -313
  186. package/dist/template/.opencode/skill/skill-installer/scripts/list-skills.py +0 -106
  187. package/dist/template/.opencode/skill/swarm-coordination/SKILL.md +0 -244
  188. package/dist/template/.opencode/skill/swarm-coordination/references/architecture.md +0 -39
  189. package/dist/template/.opencode/skill/swarm-coordination/references/delegation-worker-protocol.md +0 -145
  190. package/dist/template/.opencode/skill/swarm-coordination/references/dependency-graph.md +0 -50
  191. package/dist/template/.opencode/skill/swarm-coordination/references/drift-check.md +0 -90
  192. package/dist/template/.opencode/skill/swarm-coordination/references/integration-beads.md +0 -20
  193. package/dist/template/.opencode/skill/swarm-coordination/references/launch-flow.md +0 -186
  194. package/dist/template/.opencode/skill/swarm-coordination/references/reconciler.md +0 -172
  195. package/dist/template/.opencode/skill/swarm-coordination/references/tier-enforcement.md +0 -78
  196. package/dist/template/.opencode/skill/swarm-coordination/references/tmux-integration.md +0 -134
  197. package/dist/template/.opencode/skill/systematic-debugging/SKILL.md +0 -402
  198. package/dist/template/.opencode/skill/terse-output-mode/SKILL.md +0 -95
  199. package/dist/template/.opencode/skill/think-in-code/SKILL.md +0 -136
  200. package/dist/template/.opencode/skill/ux-quality-gates/SKILL.md +0 -137
  201. package/dist/template/.opencode/skill/v1-run/SKILL.md +0 -175
  202. package/dist/template/.opencode/skill/v1-run/mcp.json +0 -6
  203. package/dist/template/.opencode/skill/verification-gates/SKILL.md +0 -63
  204. package/dist/template/.opencode/skill/visual-analysis/SKILL.md +0 -154
  205. package/dist/template/.opencode/skill/web-design-guidelines/SKILL.md +0 -46
  206. package/dist/template/.opencode/skill/workspace-setup/SKILL.md +0 -76
  207. package/dist/template/.opencode/skill/writing-plans/SKILL.md +0 -320
  208. /package/dist/template/.opencode/plugin/{lib → memory}/compact.ts +0 -0
  209. /package/dist/template/.opencode/plugin/{lib → memory}/db/graph.ts +0 -0
  210. /package/dist/template/.opencode/plugin/{lib → memory}/db/maintenance.ts +0 -0
  211. /package/dist/template/.opencode/plugin/{lib → memory}/db/pipeline.ts +0 -0
  212. /package/dist/template/.opencode/plugin/{lib → memory}/notify.ts +0 -0
  213. /package/dist/template/.opencode/plugin/{lib → memory}/operation-log.ts +0 -0
@@ -0,0 +1,322 @@
1
+ /**
2
+ * Core Memory Tools
3
+ *
4
+ * Two tools aligned with pikit memory extension:
5
+ * - observation: create observations OR give feedback on existing ones
6
+ * - memory-search: search observations by text OR read memory files by path
7
+ */
8
+
9
+ import { tool, type ToolContext } from "@opencode-ai/plugin/tool";
10
+ import {
11
+ type ConfidenceLevel,
12
+ type ObservationSource,
13
+ type ObservationType,
14
+ type HallType,
15
+ VALID_HALLS,
16
+ } from "./db/types.js";
17
+ import {
18
+ autoDetectFiles,
19
+ parseCSV,
20
+ formatObservation,
21
+ TYPE_ICONS,
22
+ VALID_TYPES,
23
+ } from "./helpers.js";
24
+ import { validateObservation } from "./validate.js";
25
+ import {
26
+ storeObservation,
27
+ getObservationById,
28
+ searchObservationsFTS,
29
+ recordFeedback,
30
+ markObservationsRetrieved,
31
+ } from "./db/observations.js";
32
+ import { getMemoryFile } from "./db/maintenance.js";
33
+
34
+ // ============================================================================
35
+ // Error Handling Wrapper
36
+ // ============================================================================
37
+
38
+ function withDBErrorHandling<T extends Record<string, unknown>>(
39
+ handler: (args: T) => string | Promise<string>,
40
+ ): (args: T, context: ToolContext) => Promise<string> {
41
+ return async (args: T, _context: ToolContext) => {
42
+ try {
43
+ return await handler(args);
44
+ } catch (err) {
45
+ const msg = err instanceof Error ? err.message : String(err);
46
+ return `Error: ${msg}`;
47
+ }
48
+ };
49
+ }
50
+
51
+ // ============================================================================
52
+ // Tool Definitions
53
+ // ============================================================================
54
+
55
+ interface CoreToolDeps {
56
+ handoffDir: string;
57
+ }
58
+
59
+ export function createCoreTools(deps: CoreToolDeps) {
60
+ const { handoffDir } = deps;
61
+
62
+ return {
63
+ // --------------------------------------------------------------------
64
+ // observation: Create or give feedback
65
+ // --------------------------------------------------------------------
66
+ observation: tool({
67
+ description: `Create a durable observation for future retrieval, or mark an existing one as helpful/harmful.
68
+ Pass id+feedback for feedback mode; pass type+title for create mode.
69
+
70
+ Create mode captures decisions, bugs, features, patterns, discoveries, learnings, or warnings.
71
+ Feedback mode lets you rate past observations.
72
+
73
+ Create mode examples:
74
+ observation({ type: "decision", title: "Use JWT for auth", narrative: "Stateless across services.", confidence: "high" })
75
+ observation({ type: "bugfix", title: "Fix null pointer", files_modified: "src/auth.ts" })
76
+
77
+ Feedback mode examples:
78
+ observation({ id: 42, feedback: "helpful" })
79
+ observation({ id: 42, feedback: "harmful", reason: "Outdated information" })`,
80
+ args: {
81
+ // --- Create mode params ---
82
+ type: tool.schema
83
+ .string()
84
+ .optional()
85
+ .describe(
86
+ "Observation type for create mode: decision, bugfix, feature, pattern, discovery, learning, warning",
87
+ ),
88
+ title: tool.schema.string().optional().describe("Short title (create mode)"),
89
+ subtitle: tool.schema.string().optional().describe("Optional subtitle"),
90
+ facts: tool.schema
91
+ .string()
92
+ .optional()
93
+ .describe("Comma-separated key facts"),
94
+ narrative: tool.schema
95
+ .string()
96
+ .optional()
97
+ .describe("Detailed context"),
98
+ content: tool.schema
99
+ .string()
100
+ .optional()
101
+ .describe("Alias for narrative"),
102
+ concepts: tool.schema
103
+ .string()
104
+ .optional()
105
+ .describe("Comma-separated concepts"),
106
+ files_read: tool.schema
107
+ .string()
108
+ .optional()
109
+ .describe("Comma-separated files read"),
110
+ files_modified: tool.schema
111
+ .string()
112
+ .optional()
113
+ .describe("Comma-separated files modified"),
114
+ files: tool.schema
115
+ .string()
116
+ .optional()
117
+ .describe("Alias for files_modified"),
118
+ bead_id: tool.schema.string().optional().describe("Related bead ID"),
119
+ confidence: tool.schema
120
+ .string()
121
+ .optional()
122
+ .describe("high, medium, or low"),
123
+ supersedes: tool.schema
124
+ .string()
125
+ .optional()
126
+ .describe("Observation ID this supersedes"),
127
+ source: tool.schema
128
+ .string()
129
+ .optional()
130
+ .describe("manual, curator, or imported"),
131
+ hall: tool.schema
132
+ .string()
133
+ .optional()
134
+ .describe("Navigation hall: facts, events, discoveries, preferences, advice"),
135
+
136
+ // --- Feedback mode params ---
137
+ id: tool.schema
138
+ .number()
139
+ .optional()
140
+ .describe("Observation ID for feedback mode"),
141
+ feedback: tool.schema
142
+ .string()
143
+ .optional()
144
+ .describe('"helpful" or "harmful" (feedback mode)'),
145
+ reason: tool.schema
146
+ .string()
147
+ .optional()
148
+ .describe("Optional reason for feedback"),
149
+ },
150
+ execute: withDBErrorHandling(async (args) => {
151
+ // --- Feedback mode: observation #id marked helpful/harmful ---
152
+ if (args.id !== undefined && args.feedback !== undefined) {
153
+ const obsId = Number(args.id);
154
+ if (!Number.isInteger(obsId)) return "❌ id must be an integer.";
155
+ const fb = String(args.feedback);
156
+ if (fb !== "helpful" && fb !== "harmful") return '❌ feedback must be "helpful" or "harmful".';
157
+
158
+ const result = recordFeedback(obsId, fb, args.reason as string | undefined);
159
+ if (!result.success) return `❌ ${result.error ?? "Failed to record feedback."}`;
160
+
161
+ return [
162
+ `✅ Observation #${obsId} marked as ${fb}.`,
163
+ `- Feedback: ${result.helpfulCount} helpful / ${result.harmfulCount} harmful`,
164
+ ].join("\n");
165
+ }
166
+
167
+ // --- Create mode: store a new observation ---
168
+ if (!args.type || !args.title) {
169
+ return "❌ Provide type+title to create an observation, or id+feedback to give feedback.";
170
+ }
171
+
172
+ const obsType = args.type as ObservationType;
173
+ if (!VALID_TYPES.includes(obsType)) {
174
+ return `Error: Invalid type "${args.type}". Valid: ${VALID_TYPES.join(", ")}`;
175
+ }
176
+
177
+ const confidence = (args.confidence ?? "high") as ConfidenceLevel;
178
+ if (!["high", "medium", "low"].includes(confidence)) {
179
+ return `Error: Invalid confidence "${args.confidence}". Valid: high, medium, low`;
180
+ }
181
+
182
+ const narrative = args.narrative ?? args.content;
183
+ const facts = parseCSV(args.facts);
184
+ const concepts = parseCSV(args.concepts);
185
+ let filesRead = parseCSV(args.files_read);
186
+ const filesModified = parseCSV(args.files_modified ?? args.files);
187
+
188
+ // Auto-detect files from narrative if not explicitly provided
189
+ if (!filesRead && narrative) {
190
+ const detected = autoDetectFiles(narrative);
191
+ if (detected.length > 0) filesRead = detected;
192
+ }
193
+
194
+ let supersedes: number | undefined;
195
+ if (args.supersedes) {
196
+ const parsed = Number.parseInt(args.supersedes, 10);
197
+ if (!Number.isNaN(parsed)) supersedes = parsed;
198
+ }
199
+
200
+ const source = (args.source ?? "manual") as ObservationSource;
201
+ const hall = args.hall as HallType | undefined;
202
+
203
+ // Validation gate: check for duplicates, contradictions, low quality
204
+ const validation = validateObservation({
205
+ type: obsType,
206
+ title: args.title,
207
+ facts,
208
+ narrative,
209
+ concepts,
210
+ confidence,
211
+ });
212
+
213
+ if (validation.verdict === "reject") {
214
+ const reasons = validation.issues.map(i => i.message).join("; ");
215
+ const dupHint = validation.duplicateOf
216
+ ? ` Use \`observation({ supersedes: "${validation.duplicateOf}", ... })\` to update it.`
217
+ : "";
218
+ return `Rejected: ${reasons}.${dupHint}`;
219
+ }
220
+
221
+ const id = storeObservation({
222
+ type: obsType,
223
+ title: args.title,
224
+ subtitle: args.subtitle,
225
+ facts,
226
+ narrative,
227
+ concepts,
228
+ files_read: filesRead,
229
+ files_modified: filesModified,
230
+ confidence,
231
+ bead_id: args.bead_id,
232
+ supersedes,
233
+ source,
234
+ hall,
235
+ });
236
+
237
+ const warnings = validation.issues.length > 0
238
+ ? `\n⚠️ Warnings: ${validation.issues.map(i => i.message).join("; ")}`
239
+ : "";
240
+
241
+ return `${TYPE_ICONS[obsType] ?? "📌"} Observation #${id} stored [${obsType}] "${args.title}" (confidence: ${confidence}, source: ${source})${warnings}`;
242
+ }),
243
+ }),
244
+
245
+ // --------------------------------------------------------------------
246
+ // memory-search: Search or read memory
247
+ // --------------------------------------------------------------------
248
+ "memory-search": tool({
249
+ description: `Search observations by text query / #id references, or read a memory file by path.
250
+ Pass file=path to read a memory file; pass query=text to search observations.
251
+
252
+ Search modes:
253
+ - query only: Search observations using FTS5 (falls back to LIKE)
254
+ - query + type: Filter observations by type (decision, bugfix, etc.)
255
+ - file=path: Read a memory file (e.g. persona/default, scenes/<id>)
256
+ - #id refs: Lookup observations by ID number`,
257
+ args: {
258
+ query: tool.schema
259
+ .string()
260
+ .optional()
261
+ .describe("Search query or #id references"),
262
+ type: tool.schema
263
+ .string()
264
+ .optional()
265
+ .describe("Optional observation type filter"),
266
+ limit: tool.schema
267
+ .number()
268
+ .optional()
269
+ .describe("Maximum results, default 10"),
270
+ file: tool.schema
271
+ .string()
272
+ .optional()
273
+ .describe("Memory file path (e.g. persona/default, scenes/<id>)"),
274
+ },
275
+ execute: withDBErrorHandling(async (args) => {
276
+ const limit = Math.min(args.limit ?? 10, 50);
277
+
278
+ // --- File mode: read a memory file by path ---
279
+ if (args.file) {
280
+ const filePath = String(args.file);
281
+ const row = getMemoryFile(filePath);
282
+ if (!row) return `Memory file not found: ${filePath}`;
283
+ return row.content;
284
+ }
285
+
286
+ // --- ID refs mode: resolve #N references ---
287
+ if (args.query) {
288
+ const query = String(args.query);
289
+ const idRefs = [...query.matchAll(/#(\d+)/g)].map(m => parseInt(m[1], 10));
290
+ if (idRefs.length > 0) {
291
+ const rows = idRefs
292
+ .map(id => getObservationById(id))
293
+ .filter((r): r is NonNullable<typeof r> => r !== null);
294
+ if (rows.length === 0) return "No observations found for the requested IDs.";
295
+ return rows.map(r => formatObservation(r)).join("\n\n---\n\n");
296
+ }
297
+ }
298
+
299
+ // --- Search mode ---
300
+ const query = args.query ? String(args.query).trim() : "";
301
+ const scope = (args.type ?? "observations") as string;
302
+ const typeFilter = VALID_TYPES.includes(scope as ObservationType)
303
+ ? (scope as ObservationType)
304
+ : undefined;
305
+
306
+ let rows;
307
+ try {
308
+ rows = searchObservationsFTS(query, { type: typeFilter, limit });
309
+ } catch {
310
+ return "Search failed.";
311
+ }
312
+
313
+ if (rows.length === 0) return "No matching observations found.";
314
+
315
+ // Track retrieval
316
+ markObservationsRetrieved(rows.map(r => r.id));
317
+
318
+ return rows.map(r => formatObservation(r)).join("\n\n---\n\n");
319
+ }),
320
+ }),
321
+ };
322
+ }
@@ -14,8 +14,8 @@
14
14
  */
15
15
 
16
16
  import type { ObservationInput, ObservationRow } from "./db/types.js";
17
- import { getMemoryDB } from "./memory-db.js";
18
- import { hasWord } from "./memory-helpers.js";
17
+ import { getMemoryDB } from "./db.js";
18
+ import { hasWord } from "./helpers.js";
19
19
  import { appendOperationLog } from "./operation-log.js";
20
20
 
21
21
  // ============================================================================
@@ -10,29 +10,19 @@
10
10
  * 4. LTM Injection — system.transform → relevance-scored knowledge
11
11
  * 5. Context Management — messages.transform → token budget enforcement
12
12
  *
13
- * Tools: observation, memory-search, memory-get, memory-read,
14
- * memory-update, memory-timeline, memory-graph-add, memory-graph-query,
15
- * memory-graph-invalidate, memory-compact, memory-admin
13
+ * Tools: observation, memory-search, memory-admin
16
14
  *
17
15
  * Module structure:
18
16
  * memory.ts — Plugin entry (this file)
19
- * lib/memory-helpers.ts Constants, compaction utilities, formatting
20
- * lib/memory-tools.ts Core tools (observation, search, get, read, update, timeline)
21
- * lib/memory-admin-tools.ts Admin tools (memory-admin)
22
- * lib/memory-hooks.ts — Event hooks, transforms, compaction
23
- * lib/memory-db.ts — Database barrel (re-exports from lib/db/*.ts)
24
- * lib/capture.ts — Message capture module
25
- * lib/distill.ts — Heuristic distillation engine
26
- * lib/curator.ts — Pattern-based knowledge extraction
27
- * lib/inject.ts — LTM relevance scoring + injection
28
- * lib/context.ts — Context window management
29
- */
17
+ * memory/tools.ts Core tools (observation, memory-search)
18
+ * memory/admin.ts Admin tools (memory-admin)
19
+ * memory/hooks.ts Event hooks, transforms, compaction */
30
20
 
31
21
  import path from "node:path";
32
22
  import type { Plugin } from "@opencode-ai/plugin";
33
- import { createAdminTools } from "./lib/memory-admin-tools.js";
34
- import { createHooks } from "./lib/memory-hooks.js";
35
- import { createCoreTools } from "./lib/memory-tools.js";
23
+ import { createAdminTools } from "./memory/admin.js";
24
+ import { createHooks } from "./memory/hooks.js";
25
+ import { createCoreTools } from "./memory/tools.js";
36
26
 
37
27
  // ============================================================================
38
28
  // Plugin Export