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.
- package/README.md +1 -1
- package/dist/index.js +4 -25
- package/dist/template/.opencode/.template-manifest.json +115 -188
- package/dist/template/.opencode/AGENTS.md +127 -484
- package/dist/template/.opencode/README.md +2 -2
- package/dist/template/.opencode/agent/build.md +158 -356
- package/dist/template/.opencode/agent/explore.md +0 -1
- package/dist/template/.opencode/agent/plan.md +7 -16
- package/dist/template/.opencode/agent/review.md +0 -1
- package/dist/template/.opencode/agent/scout.md +2 -3
- package/dist/template/.opencode/agent/vision.md +0 -1
- package/dist/template/.opencode/artifacts/.active +1 -0
- package/dist/template/.opencode/artifacts/example/plan.md +12 -0
- package/dist/template/.opencode/artifacts/example/progress.md +4 -0
- package/dist/template/.opencode/artifacts/example/research.md +4 -0
- package/dist/template/.opencode/artifacts/example/spec.md +16 -0
- package/dist/template/.opencode/artifacts/todo.md +5 -0
- package/dist/template/.opencode/artifacts/verify.log +4 -0
- package/dist/template/.opencode/command/clarify.md +46 -0
- package/dist/template/.opencode/command/commit.md +53 -0
- package/dist/template/.opencode/command/create.md +29 -71
- package/dist/template/.opencode/command/design.md +1 -2
- package/dist/template/.opencode/command/explore.md +3 -4
- package/dist/template/.opencode/command/fix.md +55 -0
- package/dist/template/.opencode/command/improve-architecture.md +55 -0
- package/dist/template/.opencode/command/init.md +86 -69
- package/dist/template/.opencode/command/plan.md +30 -60
- package/dist/template/.opencode/command/pr.md +10 -28
- package/dist/template/.opencode/command/refactor.md +65 -0
- package/dist/template/.opencode/command/research.md +7 -29
- package/dist/template/.opencode/command/review-codebase.md +6 -13
- package/dist/template/.opencode/command/ship.md +136 -78
- package/dist/template/.opencode/command/test.md +66 -0
- package/dist/template/.opencode/command/ui-review.md +2 -4
- package/dist/template/.opencode/command/verify.md +15 -23
- package/dist/template/.opencode/dcp.jsonc +96 -85
- package/dist/template/.opencode/memory/README.md +4 -6
- package/dist/template/.opencode/memory/_templates/adr.md +45 -0
- package/dist/template/.opencode/memory/_templates/prd.md +1 -1
- package/dist/template/.opencode/memory/_templates/roadmap.md +1 -1
- package/dist/template/.opencode/memory/_templates/state.md +1 -1
- package/dist/template/.opencode/memory/project/gotchas.md +4 -4
- package/dist/template/.opencode/memory/project/project.md +2 -2
- package/dist/template/.opencode/memory/project/roadmap.md +1 -1
- package/dist/template/.opencode/memory/project/state.md +2 -2
- package/dist/template/.opencode/memory/project/tech-stack.md +2 -2
- package/dist/template/.opencode/memory/session-context.md +1 -1
- package/dist/template/.opencode/opencode.json +14 -152
- package/dist/template/.opencode/plugin/README.md +2 -2
- package/dist/template/.opencode/plugin/guard.ts +62 -0
- package/dist/template/.opencode/plugin/{lib/memory-admin-tools.ts → memory/admin.ts} +4 -4
- package/dist/template/.opencode/plugin/{lib → memory}/capture.ts +1 -1
- package/dist/template/.opencode/plugin/{lib → memory}/compile.ts +2 -2
- package/dist/template/.opencode/plugin/{lib → memory}/context.ts +1 -1
- package/dist/template/.opencode/plugin/{lib → memory}/curator.ts +1 -1
- package/dist/template/.opencode/plugin/{lib → memory}/db/observations.ts +102 -3
- package/dist/template/.opencode/plugin/{lib → memory}/db/schema.ts +43 -1
- package/dist/template/.opencode/plugin/{lib → memory}/db/types.ts +22 -0
- package/dist/template/.opencode/plugin/{lib/memory-db.ts → memory/db.ts} +1 -1
- package/dist/template/.opencode/plugin/{lib → memory}/distill.ts +1 -1
- package/dist/template/.opencode/plugin/{lib/memory-helpers.ts → memory/helpers.ts} +5 -1
- package/dist/template/.opencode/plugin/{lib/memory-hooks.ts → memory/hooks.ts} +1 -1
- package/dist/template/.opencode/plugin/{lib → memory}/index-generator.ts +2 -2
- package/dist/template/.opencode/plugin/{lib → memory}/inject.ts +1 -1
- package/dist/template/.opencode/plugin/{lib → memory}/lint.ts +2 -2
- package/dist/template/.opencode/plugin/memory/tools.ts +322 -0
- package/dist/template/.opencode/plugin/{lib → memory}/validate.ts +2 -2
- package/dist/template/.opencode/plugin/memory.ts +7 -17
- package/dist/template/.opencode/plugin/srcwalk.ts +721 -0
- package/dist/template/.opencode/skill/agent-code-quality-gate/SKILL.md +98 -0
- package/dist/template/.opencode/skill/behavioral-kernel/SKILL.md +52 -0
- package/dist/template/.opencode/skill/brainstorming/SKILL.md +1 -1
- package/dist/template/.opencode/skill/browser-testing-with-devtools/SKILL.md +85 -0
- package/dist/template/.opencode/skill/code-cleanup/SKILL.md +114 -0
- package/dist/template/.opencode/skill/code-navigation/SKILL.md +142 -0
- package/dist/template/.opencode/skill/code-review-and-quality/SKILL.md +131 -0
- package/dist/template/.opencode/skill/context-engineering/SKILL.md +1 -1
- package/dist/template/.opencode/skill/debugging-and-error-recovery/SKILL.md +109 -0
- package/dist/template/.opencode/skill/deep-module-design/SKILL.md +207 -0
- package/dist/template/.opencode/skill/development-lifecycle/SKILL.md +26 -45
- package/dist/template/.opencode/skill/gemini-large-context/SKILL.md +4 -4
- package/dist/template/.opencode/skill/git-workflow-and-versioning/SKILL.md +77 -0
- package/dist/template/.opencode/skill/grill-me/SKILL.md +140 -0
- package/dist/template/.opencode/skill/memory-system/SKILL.md +9 -10
- package/dist/template/.opencode/skill/opensrc/references/example-workflow.md +1 -1
- package/dist/template/.opencode/skill/planning-and-task-breakdown/SKILL.md +116 -0
- package/dist/template/.opencode/skill/shipping-and-launch/SKILL.md +95 -0
- package/dist/template/.opencode/skill/source-driven-development/SKILL.md +103 -0
- package/dist/template/.opencode/skill/spec-driven-development/SKILL.md +121 -0
- package/dist/template/.opencode/skill/srcwalk/SKILL.md +161 -0
- package/dist/template/.opencode/skill/subagent-driven-development/SKILL.md +1 -1
- package/dist/template/.opencode/skill/ubiquitous-language/SKILL.md +184 -0
- package/dist/template/.opencode/skill/using-git-worktrees/SKILL.md +6 -6
- package/dist/template/.opencode/skill/verification-before-completion/SKILL.md +6 -6
- package/dist/template/.opencode/skill/verification-before-completion/references/VERIFICATION_PROTOCOL.md +5 -5
- package/package.json +76 -76
- package/dist/template/.opencode/AGENT_ALIGNMENT.md +0 -564
- package/dist/template/.opencode/agent/painter.md +0 -83
- package/dist/template/.opencode/command/compound.md +0 -240
- package/dist/template/.opencode/command/curate.md +0 -299
- package/dist/template/.opencode/command/handoff.md +0 -149
- package/dist/template/.opencode/command/health.md +0 -356
- package/dist/template/.opencode/command/init-context.md +0 -297
- package/dist/template/.opencode/command/init-user.md +0 -125
- package/dist/template/.opencode/command/iterate.md +0 -200
- package/dist/template/.opencode/command/lfg.md +0 -173
- package/dist/template/.opencode/command/resume.md +0 -78
- package/dist/template/.opencode/command/status.md +0 -126
- package/dist/template/.opencode/command/ui-slop-check.md +0 -169
- package/dist/template/.opencode/plans/1768385996691-silent-wizard.md +0 -247
- package/dist/template/.opencode/plans/1770006237537-mighty-otter.md +0 -418
- package/dist/template/.opencode/plans/1770006913647-glowing-forest.md +0 -170
- package/dist/template/.opencode/plans/1770013678126-witty-planet.md +0 -278
- package/dist/template/.opencode/plans/1770112267595-shiny-rocket.md +0 -258
- package/dist/template/.opencode/plans/swarm-protocol.md +0 -123
- package/dist/template/.opencode/plugin/lib/memory-tools.ts +0 -535
- package/dist/template/.opencode/skill/agent-evals/SKILL.md +0 -208
- package/dist/template/.opencode/skill/anti-ai-slop/SKILL.md +0 -76
- package/dist/template/.opencode/skill/augment-context-engine/SKILL.md +0 -122
- package/dist/template/.opencode/skill/augment-context-engine/mcp.json +0 -6
- package/dist/template/.opencode/skill/beads/SKILL.md +0 -182
- package/dist/template/.opencode/skill/beads/references/BEST_PRACTICES.md +0 -27
- package/dist/template/.opencode/skill/beads/references/BOUNDARIES.md +0 -219
- package/dist/template/.opencode/skill/beads/references/DEPENDENCIES.md +0 -124
- package/dist/template/.opencode/skill/beads/references/EXAMPLES.md +0 -45
- package/dist/template/.opencode/skill/beads/references/FILE_CLAIMING.md +0 -101
- package/dist/template/.opencode/skill/beads/references/GIT_SYNC.md +0 -25
- package/dist/template/.opencode/skill/beads/references/HIERARCHY.md +0 -71
- package/dist/template/.opencode/skill/beads/references/MULTI_AGENT.md +0 -40
- package/dist/template/.opencode/skill/beads/references/RESUMABILITY.md +0 -177
- package/dist/template/.opencode/skill/beads/references/SESSION_PROTOCOL.md +0 -61
- package/dist/template/.opencode/skill/beads/references/TASK_CREATION.md +0 -38
- package/dist/template/.opencode/skill/beads/references/TROUBLESHOOTING.md +0 -38
- package/dist/template/.opencode/skill/beads/references/WORKFLOWS.md +0 -226
- package/dist/template/.opencode/skill/brand-asset-protocol/SKILL.md +0 -222
- package/dist/template/.opencode/skill/code-search-patterns/SKILL.md +0 -224
- package/dist/template/.opencode/skill/code-simplification/SKILL.md +0 -211
- package/dist/template/.opencode/skill/context-condensation/SKILL.md +0 -149
- package/dist/template/.opencode/skill/context-initialization/SKILL.md +0 -69
- package/dist/template/.opencode/skill/context-management/SKILL.md +0 -390
- package/dist/template/.opencode/skill/deep-research/SKILL.md +0 -384
- package/dist/template/.opencode/skill/design-direction-advisor/SKILL.md +0 -139
- package/dist/template/.opencode/skill/dispatching-parallel-agents/SKILL.md +0 -191
- package/dist/template/.opencode/skill/executing-plans/SKILL.md +0 -247
- package/dist/template/.opencode/skill/figma-go/SKILL.md +0 -65
- package/dist/template/.opencode/skill/finishing-a-development-branch/SKILL.md +0 -357
- package/dist/template/.opencode/skill/full-output-enforcement/SKILL.md +0 -62
- package/dist/template/.opencode/skill/gh-address-comments/SKILL.md +0 -29
- package/dist/template/.opencode/skill/gh-address-comments/scripts/fetch_comments.py +0 -237
- package/dist/template/.opencode/skill/gh-fix-ci/SKILL.md +0 -38
- package/dist/template/.opencode/skill/gh-fix-ci/scripts/inspect_pr_checks.py +0 -509
- package/dist/template/.opencode/skill/hi-fi-prototype-html/SKILL.md +0 -253
- package/dist/template/.opencode/skill/html-deck-export/SKILL.md +0 -189
- package/dist/template/.opencode/skill/index-knowledge/SKILL.md +0 -413
- package/dist/template/.opencode/skill/memory-grounding/SKILL.md +0 -68
- package/dist/template/.opencode/skill/playwriter/SKILL.md +0 -158
- package/dist/template/.opencode/skill/portless/SKILL.md +0 -109
- package/dist/template/.opencode/skill/prd/SKILL.md +0 -146
- package/dist/template/.opencode/skill/prd-task/SKILL.md +0 -182
- package/dist/template/.opencode/skill/prd-task/references/prd-schema.json +0 -124
- package/dist/template/.opencode/skill/prompt-leverage/SKILL.md +0 -90
- package/dist/template/.opencode/skill/prompt-leverage/references/framework.md +0 -91
- package/dist/template/.opencode/skill/prompt-leverage/scripts/augment_prompt.py +0 -157
- package/dist/template/.opencode/skill/receiving-code-review/SKILL.md +0 -263
- package/dist/template/.opencode/skill/reconcile/SKILL.md +0 -183
- package/dist/template/.opencode/skill/reflection-checkpoints/SKILL.md +0 -183
- package/dist/template/.opencode/skill/requesting-code-review/SKILL.md +0 -443
- package/dist/template/.opencode/skill/requesting-code-review/references/specialist-profiles.md +0 -108
- package/dist/template/.opencode/skill/requesting-code-review/review.md +0 -160
- package/dist/template/.opencode/skill/rtk-command-compression/SKILL.md +0 -134
- package/dist/template/.opencode/skill/screenshot/SKILL.md +0 -48
- package/dist/template/.opencode/skill/screenshot/scripts/ensure_macos_permissions.sh +0 -54
- package/dist/template/.opencode/skill/screenshot/scripts/macos_display_info.swift +0 -22
- package/dist/template/.opencode/skill/screenshot/scripts/macos_permissions.swift +0 -40
- package/dist/template/.opencode/skill/screenshot/scripts/macos_window_info.swift +0 -126
- package/dist/template/.opencode/skill/screenshot/scripts/take_screenshot.ps1 +0 -163
- package/dist/template/.opencode/skill/screenshot/scripts/take_screenshot.py +0 -585
- package/dist/template/.opencode/skill/security-threat-model/SKILL.md +0 -36
- package/dist/template/.opencode/skill/security-threat-model/references/prompt-template.md +0 -255
- package/dist/template/.opencode/skill/security-threat-model/references/security-controls-and-assets.md +0 -32
- package/dist/template/.opencode/skill/sharing-skills/SKILL.md +0 -214
- package/dist/template/.opencode/skill/skill-creator/SKILL.md +0 -181
- package/dist/template/.opencode/skill/skill-installer/SKILL.md +0 -58
- package/dist/template/.opencode/skill/skill-installer/scripts/github_utils.py +0 -21
- package/dist/template/.opencode/skill/skill-installer/scripts/install-skill-from-github.py +0 -313
- package/dist/template/.opencode/skill/skill-installer/scripts/list-skills.py +0 -106
- package/dist/template/.opencode/skill/swarm-coordination/SKILL.md +0 -244
- package/dist/template/.opencode/skill/swarm-coordination/references/architecture.md +0 -39
- package/dist/template/.opencode/skill/swarm-coordination/references/delegation-worker-protocol.md +0 -145
- package/dist/template/.opencode/skill/swarm-coordination/references/dependency-graph.md +0 -50
- package/dist/template/.opencode/skill/swarm-coordination/references/drift-check.md +0 -90
- package/dist/template/.opencode/skill/swarm-coordination/references/integration-beads.md +0 -20
- package/dist/template/.opencode/skill/swarm-coordination/references/launch-flow.md +0 -186
- package/dist/template/.opencode/skill/swarm-coordination/references/reconciler.md +0 -172
- package/dist/template/.opencode/skill/swarm-coordination/references/tier-enforcement.md +0 -78
- package/dist/template/.opencode/skill/swarm-coordination/references/tmux-integration.md +0 -134
- package/dist/template/.opencode/skill/systematic-debugging/SKILL.md +0 -402
- package/dist/template/.opencode/skill/terse-output-mode/SKILL.md +0 -95
- package/dist/template/.opencode/skill/think-in-code/SKILL.md +0 -136
- package/dist/template/.opencode/skill/ux-quality-gates/SKILL.md +0 -137
- package/dist/template/.opencode/skill/v1-run/SKILL.md +0 -175
- package/dist/template/.opencode/skill/v1-run/mcp.json +0 -6
- package/dist/template/.opencode/skill/verification-gates/SKILL.md +0 -63
- package/dist/template/.opencode/skill/visual-analysis/SKILL.md +0 -154
- package/dist/template/.opencode/skill/web-design-guidelines/SKILL.md +0 -46
- package/dist/template/.opencode/skill/workspace-setup/SKILL.md +0 -76
- package/dist/template/.opencode/skill/writing-plans/SKILL.md +0 -320
- /package/dist/template/.opencode/plugin/{lib → memory}/compact.ts +0 -0
- /package/dist/template/.opencode/plugin/{lib → memory}/db/graph.ts +0 -0
- /package/dist/template/.opencode/plugin/{lib → memory}/db/maintenance.ts +0 -0
- /package/dist/template/.opencode/plugin/{lib → memory}/db/pipeline.ts +0 -0
- /package/dist/template/.opencode/plugin/{lib → memory}/notify.ts +0 -0
- /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 "./
|
|
18
|
-
import { hasWord } from "./
|
|
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-
|
|
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
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
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 "./
|
|
34
|
-
import { createHooks } from "./
|
|
35
|
-
import { createCoreTools } from "./
|
|
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
|