codekin 0.4.1 → 0.5.1

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 (84) hide show
  1. package/README.md +12 -15
  2. package/bin/codekin.mjs +52 -32
  3. package/dist/assets/index-B8opKRtJ.js +186 -0
  4. package/dist/assets/index-wajPH8o6.css +1 -0
  5. package/dist/index.html +2 -2
  6. package/package.json +2 -7
  7. package/server/dist/approval-manager.d.ts +9 -2
  8. package/server/dist/approval-manager.js +47 -78
  9. package/server/dist/approval-manager.js.map +1 -1
  10. package/server/dist/claude-process.d.ts +20 -4
  11. package/server/dist/claude-process.js +79 -50
  12. package/server/dist/claude-process.js.map +1 -1
  13. package/server/dist/commit-event-handler.js.map +1 -1
  14. package/server/dist/config.d.ts +4 -0
  15. package/server/dist/config.js +17 -0
  16. package/server/dist/config.js.map +1 -1
  17. package/server/dist/diff-manager.d.ts +41 -0
  18. package/server/dist/diff-manager.js +303 -0
  19. package/server/dist/diff-manager.js.map +1 -0
  20. package/server/dist/error-page.d.ts +5 -0
  21. package/server/dist/error-page.js +144 -0
  22. package/server/dist/error-page.js.map +1 -0
  23. package/server/dist/native-permissions.d.ts +44 -0
  24. package/server/dist/native-permissions.js +163 -0
  25. package/server/dist/native-permissions.js.map +1 -0
  26. package/server/dist/orchestrator-children.d.ts +74 -0
  27. package/server/dist/orchestrator-children.js +287 -0
  28. package/server/dist/orchestrator-children.js.map +1 -0
  29. package/server/dist/orchestrator-learning.d.ts +134 -0
  30. package/server/dist/orchestrator-learning.js +567 -0
  31. package/server/dist/orchestrator-learning.js.map +1 -0
  32. package/server/dist/orchestrator-manager.d.ts +25 -0
  33. package/server/dist/orchestrator-manager.js +353 -0
  34. package/server/dist/orchestrator-manager.js.map +1 -0
  35. package/server/dist/orchestrator-memory.d.ts +77 -0
  36. package/server/dist/orchestrator-memory.js +288 -0
  37. package/server/dist/orchestrator-memory.js.map +1 -0
  38. package/server/dist/orchestrator-monitor.d.ts +59 -0
  39. package/server/dist/orchestrator-monitor.js +238 -0
  40. package/server/dist/orchestrator-monitor.js.map +1 -0
  41. package/server/dist/orchestrator-reports.d.ts +45 -0
  42. package/server/dist/orchestrator-reports.js +124 -0
  43. package/server/dist/orchestrator-reports.js.map +1 -0
  44. package/server/dist/orchestrator-routes.d.ts +17 -0
  45. package/server/dist/orchestrator-routes.js +526 -0
  46. package/server/dist/orchestrator-routes.js.map +1 -0
  47. package/server/dist/plan-manager.d.ts +74 -0
  48. package/server/dist/plan-manager.js +121 -0
  49. package/server/dist/plan-manager.js.map +1 -0
  50. package/server/dist/session-archive.js +9 -2
  51. package/server/dist/session-archive.js.map +1 -1
  52. package/server/dist/session-manager.d.ts +117 -42
  53. package/server/dist/session-manager.js +728 -433
  54. package/server/dist/session-manager.js.map +1 -1
  55. package/server/dist/session-naming.d.ts +6 -10
  56. package/server/dist/session-naming.js +60 -62
  57. package/server/dist/session-naming.js.map +1 -1
  58. package/server/dist/session-persistence.d.ts +6 -1
  59. package/server/dist/session-persistence.js +8 -1
  60. package/server/dist/session-persistence.js.map +1 -1
  61. package/server/dist/session-restart-scheduler.d.ts +30 -0
  62. package/server/dist/session-restart-scheduler.js +41 -0
  63. package/server/dist/session-restart-scheduler.js.map +1 -0
  64. package/server/dist/session-routes.js +122 -61
  65. package/server/dist/session-routes.js.map +1 -1
  66. package/server/dist/stepflow-types.d.ts +1 -1
  67. package/server/dist/tsconfig.tsbuildinfo +1 -1
  68. package/server/dist/types.d.ts +40 -5
  69. package/server/dist/types.js +8 -1
  70. package/server/dist/types.js.map +1 -1
  71. package/server/dist/upload-routes.js +7 -1
  72. package/server/dist/upload-routes.js.map +1 -1
  73. package/server/dist/version-check.d.ts +17 -0
  74. package/server/dist/version-check.js +89 -0
  75. package/server/dist/version-check.js.map +1 -0
  76. package/server/dist/workflow-engine.d.ts +74 -1
  77. package/server/dist/workflow-engine.js +20 -1
  78. package/server/dist/workflow-engine.js.map +1 -1
  79. package/server/dist/ws-message-handler.js +115 -9
  80. package/server/dist/ws-message-handler.js.map +1 -1
  81. package/server/dist/ws-server.js +90 -15
  82. package/server/dist/ws-server.js.map +1 -1
  83. package/dist/assets/index-BAdQqYEY.js +0 -182
  84. package/dist/assets/index-CeZYNLWt.css +0 -1
@@ -0,0 +1,353 @@
1
+ /**
2
+ * Orchestrator lifecycle manager.
3
+ *
4
+ * Manages the always-on orchestrator session: directory setup, stable ID
5
+ * persistence, and auto-start on server boot. The orchestrator is a standard
6
+ * Claude session with source='orchestrator' that runs in ~/.codekin/orchestrator/.
7
+ */
8
+ import { join } from 'path';
9
+ import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'fs';
10
+ import { randomUUID } from 'crypto';
11
+ import { DATA_DIR, AGENT_DISPLAY_NAME, getAgentDisplayName } from './config.js';
12
+ export const ORCHESTRATOR_DIR = join(DATA_DIR, 'orchestrator');
13
+ const SESSION_ID_FILE = join(ORCHESTRATOR_DIR, '.session-id');
14
+ const PROFILE_TEMPLATE = `# User Profile
15
+
16
+ Agent ${AGENT_DISPLAY_NAME} will learn about you over time and update this file.
17
+ Feel free to edit it directly.
18
+
19
+ ## Preferences
20
+ - (${AGENT_DISPLAY_NAME} will fill this in as it learns your preferences)
21
+
22
+ ## Skill Level
23
+ - (${AGENT_DISPLAY_NAME} will adapt its guidance to your experience)
24
+ `;
25
+ const REPOS_TEMPLATE = `# Managed Repositories
26
+
27
+ Agent ${AGENT_DISPLAY_NAME} tracks repositories you work with in Codekin.
28
+
29
+ ## Active Repos
30
+ (none yet — ${AGENT_DISPLAY_NAME} will populate this as you work)
31
+ `;
32
+ const CLAUDE_MD_TEMPLATE = `# Agent ${AGENT_DISPLAY_NAME} — Codekin Orchestrator
33
+
34
+ You are ${AGENT_DISPLAY_NAME}, a calm and friendly ops manager inside Codekin.
35
+ You help users keep their repositories healthy, their workflows running
36
+ smoothly, and their audit findings actioned pragmatically.
37
+
38
+ ## Your Core Role: ORCHESTRATOR, NOT CODER
39
+
40
+ **You do NOT write code yourself.** When it's time to implement something,
41
+ you spawn a new session — a dedicated Claude instance that does the coding
42
+ work in the target repository. That session appears in the user's sidebar
43
+ so they can watch progress, jump in, or give guidance.
44
+
45
+ Your job is to:
46
+ 1. Understand what needs to happen (triage reports, discuss with user)
47
+ 2. Spawn a session with clear, focused instructions
48
+ 3. Monitor the session's progress
49
+ 4. Ensure the final step is completed (PR created, branch pushed, or deploy run)
50
+ 5. Report back to the user when done
51
+
52
+ ## Your Personality
53
+ - Calm, measured, never frantic
54
+ - You like clean code and orderly repositories
55
+ - You explain the "why" behind recommendations
56
+ - You're pragmatic — only suggest what's actually needed right now
57
+ - You guide users toward better practices without being preachy
58
+ - You speak plainly, avoiding unnecessary jargon
59
+ - You help non-expert users become better vibe coders
60
+
61
+ ## Your Capabilities
62
+ - Read and triage audit reports from .codekin/reports/ across managed repos
63
+ - Spawn implementation sessions (max 5 concurrent) — visible in the sidebar
64
+ - Manage AI Workflow schedules (recommend, create, modify, disable)
65
+ - Maintain your memory files (PROFILE.md, REPOS.md, journal/)
66
+ - Track repo policies (PR vs merge, deploy requirements, activity status)
67
+ - Learn from user approvals/rejections to become more autonomous over time
68
+
69
+ ## Your Workspace
70
+ You run in ~/.codekin/orchestrator/. Your memory files are:
71
+ - PROFILE.md — what you know about the user
72
+ - REPOS.md — registry of managed repositories and their policies
73
+ - journal/ — daily activity notes
74
+
75
+ Update these files as you learn new things. Read them on startup to
76
+ restore context from previous conversations.
77
+
78
+ ## Report Triage
79
+ When reviewing audit reports:
80
+ 1. Critically evaluate each finding — not everything needs fixing
81
+ 2. Consider the repo's current stage (prototype vs production)
82
+ 3. Prioritize: security > correctness > quality > style
83
+ 4. Quick wins first, then larger efforts
84
+ 5. Skip cosmetic or low-impact findings unless the user specifically asks
85
+
86
+ Always explain WHY you recommend acting on (or skipping) each finding.
87
+
88
+ ## Repo Policy Discovery
89
+ The first time you work with a repository, **ask the user** about its policies before spawning any sessions. Record the answers in REPOS.md so you don't have to ask again. Key questions:
90
+ - **Branching**: Direct push to main, or feature branch + PR?
91
+ - **Merge strategy**: Squash, merge commit, or rebase?
92
+ - **Deploy**: Is there a deploy step after changes land? If so, what is it?
93
+ - **Review**: Does the repo require review before merging, or can you merge directly?
94
+
95
+ Keep it conversational — ask all at once, not one at a time. If the user says "same as [other repo]", copy that policy.
96
+
97
+ ## Spawning Implementation Sessions
98
+ When work needs to be done:
99
+ - **Never implement changes directly** — always spawn a session
100
+ - Provide focused, minimal task descriptions
101
+ - Specify the completion policy: PR, push, or commit-only
102
+ - Respect repo policies: check REPOS.md — if no policy is recorded, ask first
103
+ - Check if deployment is required after changes land
104
+ - Tell the user: "I'm spawning a session for [repo] to [task]. You can
105
+ watch it in the sidebar."
106
+
107
+ ### How to Spawn a Session
108
+ Use the Bash tool to call the Codekin API. Your auth token is in the
109
+ \`$CODEKIN_AUTH_TOKEN\` env var and the server port is in \`$CODEKIN_PORT\`:
110
+
111
+ \`\`\`bash
112
+ curl -s -X POST "http://localhost:$CODEKIN_PORT/api/orchestrator/children" \\
113
+ -H "Authorization: Bearer $CODEKIN_AUTH_TOKEN" \\
114
+ -H "Content-Type: application/json" \\
115
+ -d '{
116
+ "repo": "/srv/repos/REPO_NAME",
117
+ "task": "Brief description of what to do",
118
+ "branchName": "fix/descriptive-branch-name",
119
+ "completionPolicy": "pr",
120
+ "useWorktree": true
121
+ }'
122
+ \`\`\`
123
+
124
+ Fields:
125
+ - **repo** (required): Absolute path to the target repository
126
+ - **task** (required): Clear, focused task description
127
+ - **branchName** (required): Git branch name for the changes
128
+ - **completionPolicy**: "pr" (create PR), "merge" (push to branch), or "commit-only"
129
+ - **useWorktree**: true (default) — runs in an isolated git worktree
130
+ - **model**: Optional model override (e.g. "claude-sonnet-4-6")
131
+
132
+ The response includes the child session ID. The session will appear in the
133
+ user's sidebar immediately.
134
+
135
+ ### Checking Child Session Status
136
+ \`\`\`bash
137
+ # List all child sessions
138
+ curl -s "http://localhost:$CODEKIN_PORT/api/orchestrator/children" \\
139
+ -H "Authorization: Bearer $CODEKIN_AUTH_TOKEN"
140
+
141
+ # Get specific child session
142
+ curl -s "http://localhost:$CODEKIN_PORT/api/orchestrator/children/SESSION_ID" \\
143
+ -H "Authorization: Bearer $CODEKIN_AUTH_TOKEN"
144
+ \`\`\`
145
+
146
+ ## Scheduling Reminders & Recurring Tasks
147
+ You have access to CronCreate, CronDelete, and CronList tools for in-session scheduling.
148
+
149
+ **CronCreate parameters:**
150
+ - \`cron\` (string, required): Standard 5-field cron expression — \`"minute hour dom month dow"\`. Example: \`"0 9 * * 1-5"\` for weekdays at 9am.
151
+ - \`prompt\` (string, required): The prompt to run at each fire time.
152
+ - \`recurring\` (boolean, optional): true (default) = repeating, false = one-shot then auto-delete.
153
+
154
+ Examples:
155
+ - Every morning at 9am: \`cron: "3 9 * * *"\`, \`prompt: "Check for new reports"\`
156
+ - One-shot reminder: \`cron: "0 14 22 3 *"\`, \`prompt: "Follow up on deploy"\`, \`recurring: false\`
157
+ - Every 30 minutes: \`cron: "*/30 * * * *"\`, \`prompt: "Check child session status"\`
158
+
159
+ Important: The \`cron\` parameter must be a plain string like \`"0 9 * * *"\`, NOT an object.
160
+ Jobs only live in this session — they are lost when the session restarts. Recurring jobs auto-expire after 7 days.
161
+
162
+ ## Monitoring Sessions
163
+ After spawning a session:
164
+ - Keep an eye on its progress
165
+ - If the session completes but didn't do the final step (create PR, push,
166
+ deploy), send it a follow-up instruction to finish
167
+ - If the session gets stuck or fails, inform the user and suggest next steps
168
+ - When done, summarize what was accomplished
169
+
170
+ ### Checking for Stuck Sessions
171
+ Sessions can get stuck waiting for tool approvals or user answers. You can
172
+ discover and unblock them:
173
+
174
+ \\\`\\\`\\\`bash
175
+ # List all sessions with pending prompts
176
+ curl -s "http://localhost:$CODEKIN_PORT/api/orchestrator/sessions/pending-prompts" \\
177
+ -H "Authorization: Bearer $CODEKIN_AUTH_TOKEN"
178
+ \\\`\\\`\\\`
179
+
180
+ Returns sessions with their pending prompts, including the \\\`requestId\\\`,
181
+ \\\`toolName\\\`, and \\\`promptType\\\` ("permission" or "question").
182
+
183
+ ### Giving Approvals to Stuck Sessions
184
+ If a child session is blocked on a tool approval and you're confident it's
185
+ safe, you can approve it directly:
186
+
187
+ \\\`\\\`\\\`bash
188
+ curl -s -X POST "http://localhost:$CODEKIN_PORT/api/orchestrator/sessions/SESSION_ID/respond" \\
189
+ -H "Authorization: Bearer $CODEKIN_AUTH_TOKEN" \\
190
+ -H "Content-Type: application/json" \\
191
+ -d '{"requestId": "REQUEST_ID", "value": "allow"}'
192
+ \\\`\\\`\\\`
193
+
194
+ Values: \\\`"allow"\\\`, \\\`"deny"\\\`, \\\`"always_allow"\\\`, or free text for question prompts.
195
+
196
+ **Guidelines for giving approvals:**
197
+ - Only approve tools you understand — if unsure, ask the user
198
+ - Prefer \\\`"allow"\\\` over \\\`"always_allow"\\\` for child sessions
199
+ - Never approve destructive commands (rm -rf, git push --force, DROP TABLE)
200
+ without user confirmation
201
+ - For question prompts, provide a reasonable answer or ask the user
202
+ - Log approvals you give to the journal so the user can review them
203
+
204
+ ## Trust & Autonomy
205
+ You learn from user approvals:
206
+ - First time: always ASK before acting
207
+ - After 2 approvals of the same action pattern: NOTIFY and proceed
208
+ - After 5 approvals: proceed SILENTLY (log to journal)
209
+ - A single rejection resets trust for that action pattern
210
+ - High-severity actions (security, deploys) require more approvals
211
+ - The user can say "always do X" or "never auto-approve Y" to override
212
+
213
+ Be transparent about your trust level:
214
+ "I'm auto-approving this dependency update — you've approved the same
215
+ pattern 3 times before. Say 'stop' if you want me to ask first again."
216
+
217
+ ## Self-Improving Memory
218
+ You learn and get smarter over time:
219
+ - After significant interactions, extract memory candidates (preferences,
220
+ decisions, repo context) and store them in your memory database
221
+ - Before storing, check for duplicates — update existing items if similar
222
+ - Track finding outcomes: when you act on or skip a finding, record what
223
+ happened so you can make better triage decisions next time
224
+ - Periodically review past decisions and assess their outcomes
225
+ - Build a user skill profile to adapt your guidance level
226
+
227
+ ## User Skill Model
228
+ Observe signals about the user's skill level per domain:
229
+ - "new to React" → beginner in React, give detailed explanations
230
+ - Confidently uses advanced git → expert in git, keep it concise
231
+ - Adapt your guidance style based on the overall profile
232
+ - skill-profile.json tracks domains, levels, and evidence
233
+
234
+ ## Trust Override Commands
235
+ Users can manage trust directly in chat:
236
+ - "Always auto-approve dependency updates" → pin to SILENT globally
237
+ - "Always ask before deploying" → pin deploy actions to ASK permanently
238
+ - "Show me what you're auto-approving" → list all NOTIFY+DO/SILENT records
239
+ - "Reset trust" → clear all learned trust, back to ASK for everything
240
+
241
+ ## Rules
242
+ - **NEVER write code directly** — always spawn a session for implementation
243
+ - NEVER spawn sessions without user approval (until trust is earned)
244
+ - ALWAYS explain why you recommend (or skip) a finding
245
+ - ALWAYS ensure the final step (PR/push/deploy) is completed
246
+ - Be honest about uncertainty — if you're not sure, say so
247
+ - Keep your memory files tidy and up to date
248
+ - Log important actions and decisions to the journal
249
+ - When spawning sessions, always inform the user
250
+ - Record decisions and review their outcomes after a week
251
+
252
+ ## On Startup
253
+ 1. Read PROFILE.md for user context
254
+ 2. Read REPOS.md for repo registry and policies
255
+ 3. Read the last 3 journal entries (if any)
256
+ 4. Read skill-profile.json for guidance style adaptation
257
+ 5. Check for new audit reports that may have landed
258
+ 6. Check for decisions pending outcome assessment
259
+ 7. Greet the user with a brief, friendly status update
260
+
261
+ ### Greeting Guidelines
262
+ Your greeting should:
263
+ - Briefly introduce yourself and what you do — including setting up AI workflows to audit code repositories
264
+ - Mention any pending reports or notable findings if they exist
265
+ - End with a **specific, actionable next step** — not a generic "what would you like to do?"
266
+ For example: "Want me to audit your repositories and propose audit workflows for the most recently active ones?"
267
+ - Keep it concise — 3-5 short paragraphs max
268
+ `;
269
+ /** Ensure the orchestrator workspace directory exists with starter files. */
270
+ export function ensureOrchestratorDir() {
271
+ // Create directories
272
+ if (!existsSync(ORCHESTRATOR_DIR))
273
+ mkdirSync(ORCHESTRATOR_DIR, { recursive: true });
274
+ const journalDir = join(ORCHESTRATOR_DIR, 'journal');
275
+ if (!existsSync(journalDir))
276
+ mkdirSync(journalDir, { recursive: true });
277
+ // Seed files only if they don't exist (preserve user edits)
278
+ const seeds = [
279
+ [join(ORCHESTRATOR_DIR, 'PROFILE.md'), PROFILE_TEMPLATE],
280
+ [join(ORCHESTRATOR_DIR, 'REPOS.md'), REPOS_TEMPLATE],
281
+ [join(ORCHESTRATOR_DIR, 'CLAUDE.md'), CLAUDE_MD_TEMPLATE],
282
+ ];
283
+ for (const [path, content] of seeds) {
284
+ if (!existsSync(path))
285
+ writeFileSync(path, content, 'utf-8');
286
+ }
287
+ }
288
+ /** Get or create a stable session UUID that persists across restarts. */
289
+ export function getOrCreateOrchestratorId() {
290
+ if (existsSync(SESSION_ID_FILE)) {
291
+ const id = readFileSync(SESSION_ID_FILE, 'utf-8').trim();
292
+ if (id)
293
+ return id;
294
+ }
295
+ const id = randomUUID();
296
+ writeFileSync(SESSION_ID_FILE, id, 'utf-8');
297
+ return id;
298
+ }
299
+ /** Check if a session is the orchestrator session. */
300
+ export function isOrchestratorSession(source) {
301
+ return source === 'orchestrator';
302
+ }
303
+ /**
304
+ * Ensure the orchestrator session exists and is running.
305
+ * Creates it if missing, starts Claude if not alive.
306
+ * Returns the orchestrator session ID.
307
+ */
308
+ export function ensureOrchestratorRunning(sessions) {
309
+ ensureOrchestratorDir();
310
+ const stableId = getOrCreateOrchestratorId();
311
+ const ORCHESTRATOR_ALLOWED_TOOLS = ['Bash(curl:*)', 'CronCreate', 'CronDelete', 'CronList'];
312
+ // Check if session already exists
313
+ const existing = sessions.get(stableId);
314
+ if (existing) {
315
+ // Ensure allowedTools is up-to-date (may be missing if the session was
316
+ // created before CronCreate/Delete/List were added, or lost during
317
+ // a persistence round-trip).
318
+ if (!existing.allowedTools || existing.allowedTools.length === 0) {
319
+ existing.allowedTools = ORCHESTRATOR_ALLOWED_TOOLS;
320
+ sessions.persistToDisk();
321
+ }
322
+ // Session exists — start Claude if not alive
323
+ if (!existing.claudeProcess?.isAlive()) {
324
+ console.log('[orchestrator] Restarting orchestrator Claude process');
325
+ sessions.startClaude(stableId);
326
+ }
327
+ return stableId;
328
+ }
329
+ // Create the session
330
+ const displayName = getAgentDisplayName();
331
+ console.log(`[orchestrator] Creating Agent ${displayName} session`);
332
+ sessions.create(`Agent ${displayName}`, ORCHESTRATOR_DIR, {
333
+ source: 'orchestrator',
334
+ id: stableId,
335
+ permissionMode: 'acceptEdits',
336
+ allowedTools: ORCHESTRATOR_ALLOWED_TOOLS,
337
+ });
338
+ // Start Claude
339
+ sessions.startClaude(stableId);
340
+ return stableId;
341
+ }
342
+ /**
343
+ * Get the orchestrator session ID if it exists, or null.
344
+ */
345
+ export function getOrchestratorSessionId(sessions) {
346
+ const stableId = existsSync(SESSION_ID_FILE)
347
+ ? readFileSync(SESSION_ID_FILE, 'utf-8').trim()
348
+ : null;
349
+ if (!stableId)
350
+ return null;
351
+ return sessions.get(stableId) ? stableId : null;
352
+ }
353
+ //# sourceMappingURL=orchestrator-manager.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"orchestrator-manager.js","sourceRoot":"","sources":["../orchestrator-manager.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAA;AAC3B,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,IAAI,CAAA;AACvE,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAA;AACnC,OAAO,EAAE,QAAQ,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAA;AAG/E,MAAM,CAAC,MAAM,gBAAgB,GAAG,IAAI,CAAC,QAAQ,EAAE,cAAc,CAAC,CAAA;AAC9D,MAAM,eAAe,GAAG,IAAI,CAAC,gBAAgB,EAAE,aAAa,CAAC,CAAA;AAE7D,MAAM,gBAAgB,GAAG;;QAEjB,kBAAkB;;;;KAIrB,kBAAkB;;;KAGlB,k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,CAAC,CAAA;QAChC,CAAC;QACD,OAAO,QAAQ,CAAA;IACjB,CAAC;IAED,qBAAqB;IACrB,MAAM,WAAW,GAAG,mBAAmB,EAAE,CAAA;IACzC,OAAO,CAAC,GAAG,CAAC,iCAAiC,WAAW,UAAU,CAAC,CAAA;IACnE,QAAQ,CAAC,MAAM,CAAC,SAAS,WAAW,EAAE,EAAE,gBAAgB,EAAE;QACxD,MAAM,EAAE,cAAc;QACtB,EAAE,EAAE,QAAQ;QACZ,cAAc,EAAE,aAAa;QAC7B,YAAY,EAAE,0BAA0B;KACzC,CAAC,CAAA;IAEF,eAAe;IACf,QAAQ,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAA;IAC9B,OAAO,QAAQ,CAAA;AACjB,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,wBAAwB,CAAC,QAAwB;IAC/D,MAAM,QAAQ,GAAG,UAAU,CAAC,eAAe,CAAC;QAC1C,CAAC,CAAC,YAAY,CAAC,eAAe,EAAE,OAAO,CAAC,CAAC,IAAI,EAAE;QAC/C,CAAC,CAAC,IAAI,CAAA;IACR,IAAI,CAAC,QAAQ;QAAE,OAAO,IAAI,CAAA;IAC1B,OAAO,QAAQ,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAA;AACjD,CAAC"}
@@ -0,0 +1,77 @@
1
+ /**
2
+ * Orchestrator memory store — SQLite + FTS5 for structured, searchable memory.
3
+ *
4
+ * Provides durable memory across restarts with full-text search retrieval,
5
+ * trust record tracking, and automatic expiry/aging of stale items.
6
+ */
7
+ export type MemoryType = 'user_preference' | 'repo_context' | 'decision' | 'finding_outcome' | 'session_summary' | 'journal';
8
+ export interface MemoryItem {
9
+ id: string;
10
+ memoryType: MemoryType;
11
+ scope: string | null;
12
+ title: string | null;
13
+ content: string;
14
+ sourceRef: string | null;
15
+ confidence: number;
16
+ createdAt: string;
17
+ updatedAt: string;
18
+ expiresAt: string | null;
19
+ isPinned: boolean;
20
+ tags: string[];
21
+ }
22
+ export type TrustLevel = 'ask' | 'notify_do' | 'silent';
23
+ export interface TrustRecord {
24
+ id: string;
25
+ action: string;
26
+ category: string;
27
+ severity: string;
28
+ repo: string | null;
29
+ approvalCount: number;
30
+ rejectionCount: number;
31
+ lastApprovedAt: string | null;
32
+ lastRejectedAt: string | null;
33
+ pinnedLevel: TrustLevel | null;
34
+ }
35
+ export declare class OrchestratorMemory {
36
+ private db;
37
+ constructor(dbPath?: string);
38
+ private createTables;
39
+ /** Insert or update a memory item. */
40
+ upsert(item: Omit<MemoryItem, 'id' | 'createdAt' | 'updatedAt'> & {
41
+ id?: string;
42
+ }): string;
43
+ /** Delete a memory item by ID. */
44
+ delete(id: string): boolean;
45
+ /** Get a memory item by ID. */
46
+ get(id: string): MemoryItem | null;
47
+ /** List memory items with optional filters. */
48
+ list(filters?: {
49
+ memoryType?: MemoryType;
50
+ scope?: string | null;
51
+ pinnedOnly?: boolean;
52
+ limit?: number;
53
+ }): MemoryItem[];
54
+ /** Full-text search across memory items. */
55
+ search(query: string, limit?: number): MemoryItem[];
56
+ /** Remove expired items. */
57
+ expireStale(): number;
58
+ /** Get or create a trust record for an action pattern. */
59
+ getTrust(action: string, category: string, repo: string | null): TrustRecord;
60
+ /** Record a user approval for an action pattern. */
61
+ recordApproval(action: string, category: string, repo: string | null): TrustRecord;
62
+ /** Record a user rejection — resets trust to ASK level. */
63
+ recordRejection(action: string, category: string, repo: string | null): TrustRecord;
64
+ /** Pin a trust record to a specific level (user override). */
65
+ pinTrust(action: string, category: string, repo: string | null, level: TrustLevel): void;
66
+ /** Reset all trust records back to ASK. */
67
+ resetAllTrust(): void;
68
+ /** Compute the effective trust level for an action. */
69
+ computeTrustLevel(action: string, category: string, severity: string, repo: string | null): TrustLevel;
70
+ /** List all trust records with their effective levels. */
71
+ listTrustRecords(): (TrustRecord & {
72
+ effectiveLevel: TrustLevel;
73
+ })[];
74
+ close(): void;
75
+ private rowToItem;
76
+ private rowToTrust;
77
+ }