memorix 1.2.2 → 1.2.4
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/CHANGELOG.md +27 -0
- package/README.md +3 -3
- package/README.zh-CN.md +3 -3
- package/TEAM.md +86 -86
- package/dist/cli/index.js +5199 -4726
- package/dist/cli/index.js.map +1 -1
- package/dist/index.js +428 -49
- package/dist/index.js.map +1 -1
- package/dist/maintenance-runner.js +97 -18
- package/dist/maintenance-runner.js.map +1 -1
- package/dist/memcode-runtime/CHANGELOG.md +27 -0
- package/dist/sdk.js +428 -49
- package/dist/sdk.js.map +1 -1
- package/docs/1.2.4-PERSISTENT-MEMORY-DELIVERY.md +86 -0
- package/docs/AGENT_OPERATOR_PLAYBOOK.md +13 -1
- package/docs/API_REFERENCE.md +13 -3
- package/docs/DESIGN_DECISIONS.md +357 -357
- package/docs/dev-log/progress.txt +60 -9
- package/package.json +1 -1
- package/plugins/codex/memorix/.codex-plugin/plugin.json +1 -1
- package/src/audit/index.ts +156 -156
- package/src/cli/capability-map.ts +1 -1
- package/src/cli/command-guide.ts +4 -1
- package/src/cli/commands/agent-integrations.ts +5 -1
- package/src/cli/commands/audit-list.ts +89 -89
- package/src/cli/commands/background.ts +659 -659
- package/src/cli/commands/codegraph.ts +1 -1
- package/src/cli/commands/context.ts +9 -1
- package/src/cli/commands/formation.ts +48 -48
- package/src/cli/commands/git-hook-install.ts +111 -111
- package/src/cli/commands/handoff.ts +54 -54
- package/src/cli/commands/hooks-status.ts +63 -63
- package/src/cli/commands/ingest-commit.ts +153 -153
- package/src/cli/commands/ingest-image.ts +66 -66
- package/src/cli/commands/ingest-log.ts +180 -180
- package/src/cli/commands/ingest.ts +44 -44
- package/src/cli/commands/integrate-shared.ts +15 -15
- package/src/cli/commands/lock.ts +82 -82
- package/src/cli/commands/message.ts +104 -104
- package/src/cli/commands/poll.ts +58 -58
- package/src/cli/commands/purge-all-memory.ts +85 -85
- package/src/cli/commands/purge-project-memory.ts +83 -83
- package/src/cli/commands/reasoning.ts +118 -118
- package/src/cli/commands/resume.ts +31 -0
- package/src/cli/commands/serve-shared.ts +118 -118
- package/src/cli/commands/session.ts +15 -7
- package/src/cli/commands/skills.ts +114 -114
- package/src/cli/commands/task.ts +167 -167
- package/src/cli/commands/transfer.ts +47 -47
- package/src/cli/commands/uninstall-project-artifacts.ts +85 -85
- package/src/cli/index.ts +3 -1
- package/src/cli/tui/ChatView.tsx +234 -234
- package/src/cli/tui/CommandBar.tsx +312 -312
- package/src/cli/tui/ContextRail.tsx +118 -118
- package/src/cli/tui/HeaderBar.tsx +72 -72
- package/src/cli/tui/LogoBanner.tsx +51 -51
- package/src/cli/tui/Sidebar.tsx +179 -179
- package/src/cli/tui/index.ts +41 -41
- package/src/cli/tui/markdown-render.tsx +371 -371
- package/src/cli/tui/session-service.ts +3 -2
- package/src/cli/tui/use-mouse.ts +157 -157
- package/src/cli/tui/useNavigation.ts +56 -56
- package/src/cli/update-checker.ts +211 -211
- package/src/cli/version.ts +7 -7
- package/src/cli/workbench.ts +1 -1
- package/src/codegraph/auto-context.ts +54 -1
- package/src/codegraph/task-lens.ts +29 -0
- package/src/compact/token-budget.ts +89 -74
- package/src/config/toml-loader.ts +9 -5
- package/src/dashboard/project-classification.ts +64 -64
- package/src/embedding/fastembed-provider.ts +142 -142
- package/src/embedding/transformers-provider.ts +111 -111
- package/src/git/extractor.ts +209 -209
- package/src/git/hooks-path.ts +85 -85
- package/src/hooks/handler.ts +127 -66
- package/src/hooks/installers/index.ts +5 -4
- package/src/hooks/official-skills.ts +6 -4
- package/src/hooks/pattern-detector.ts +173 -173
- package/src/hooks/rules/memorix-agent-rules.md +9 -7
- package/src/hooks/significance-filter.ts +250 -250
- package/src/knowledge/context-assembly.ts +4 -1
- package/src/knowledge/workset.ts +89 -1
- package/src/llm/memory-manager.ts +328 -328
- package/src/llm/provider.ts +885 -885
- package/src/llm/quality.ts +248 -248
- package/src/memory/attribution-guard.ts +249 -249
- package/src/memory/disclosure-policy.ts +135 -135
- package/src/memory/entity-extractor.ts +197 -197
- package/src/memory/formation/evaluate.ts +217 -217
- package/src/memory/formation/extract.ts +361 -361
- package/src/memory/formation/index.ts +417 -417
- package/src/memory/formation/resolve.ts +344 -344
- package/src/memory/formation/types.ts +315 -315
- package/src/memory/freshness.ts +122 -122
- package/src/memory/graph.ts +197 -197
- package/src/memory/refs.ts +94 -94
- package/src/memory/secret-filter.ts +79 -79
- package/src/memory/session.ts +158 -9
- package/src/multimodal/image-loader.ts +143 -143
- package/src/orchestrate/adapters/claude-stream.ts +192 -192
- package/src/orchestrate/adapters/claude.ts +111 -111
- package/src/orchestrate/adapters/codex-stream.ts +134 -134
- package/src/orchestrate/adapters/codex.ts +41 -41
- package/src/orchestrate/adapters/gemini-stream.ts +166 -166
- package/src/orchestrate/adapters/gemini.ts +42 -42
- package/src/orchestrate/adapters/index.ts +73 -73
- package/src/orchestrate/adapters/opencode-stream.ts +143 -143
- package/src/orchestrate/adapters/opencode.ts +47 -47
- package/src/orchestrate/adapters/spawn-helper.ts +286 -286
- package/src/orchestrate/adapters/types.ts +77 -77
- package/src/orchestrate/capability-router.ts +284 -284
- package/src/orchestrate/context-compact.ts +188 -188
- package/src/orchestrate/cost-tracker.ts +219 -219
- package/src/orchestrate/error-recovery.ts +191 -191
- package/src/orchestrate/evidence.ts +140 -140
- package/src/orchestrate/ledger.ts +110 -110
- package/src/orchestrate/memorix-bridge.ts +343 -343
- package/src/orchestrate/output-budget.ts +80 -80
- package/src/orchestrate/permission.ts +152 -152
- package/src/orchestrate/pipeline-trace.ts +131 -131
- package/src/orchestrate/prompt-builder.ts +155 -155
- package/src/orchestrate/ring-buffer.ts +37 -37
- package/src/orchestrate/task-graph.ts +389 -389
- package/src/orchestrate/worktree.ts +232 -232
- package/src/project/aliases.ts +374 -374
- package/src/project/detector.ts +268 -268
- package/src/rules/adapters/claude-code.ts +99 -99
- package/src/rules/adapters/codex.ts +97 -97
- package/src/rules/adapters/copilot.ts +124 -124
- package/src/rules/adapters/cursor.ts +114 -114
- package/src/rules/adapters/kiro.ts +126 -126
- package/src/rules/adapters/trae.ts +56 -56
- package/src/rules/adapters/windsurf.ts +83 -83
- package/src/rules/syncer.ts +235 -235
- package/src/sdk.ts +299 -299
- package/src/search/intent-detector.ts +289 -289
- package/src/search/query-expansion.ts +52 -52
- package/src/server/formation-timeout.ts +27 -27
- package/src/server.ts +144 -10
- package/src/skills/mini-skills.ts +386 -386
- package/src/store/bun-sqlite-compat.ts +118 -15
- package/src/store/chat-store.ts +119 -119
- package/src/store/graph-store.ts +249 -249
- package/src/store/mini-skill-store.ts +349 -349
- package/src/store/persistence-json.ts +212 -212
- package/src/store/persistence.ts +291 -291
- package/src/store/project-affinity.ts +195 -195
- package/src/store/sqlite-db.ts +3 -3
- package/src/team/event-bus.ts +76 -76
- package/src/team/file-locks.ts +173 -173
- package/src/team/handoff.ts +161 -161
- package/src/team/messages.ts +203 -203
- package/src/team/poll.ts +132 -132
- package/src/team/tasks.ts +211 -211
- package/src/workspace/mcp-adapters/codex.ts +191 -191
- package/src/workspace/mcp-adapters/copilot.ts +105 -105
- package/src/workspace/mcp-adapters/cursor.ts +53 -53
- package/src/workspace/mcp-adapters/kiro.ts +64 -64
- package/src/workspace/mcp-adapters/opencode.ts +123 -123
- package/src/workspace/mcp-adapters/trae.ts +134 -134
- package/src/workspace/mcp-adapters/windsurf.ts +91 -91
- package/src/workspace/sanitizer.ts +60 -60
- package/src/workspace/workflow-sync.ts +131 -131
package/src/git/hooks-path.ts
CHANGED
|
@@ -1,85 +1,85 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Git hooks path resolver — worktree-safe.
|
|
3
|
-
*
|
|
4
|
-
* In a normal repo: .git is a directory → hooks at .git/hooks/
|
|
5
|
-
* In a git worktree: .git is a FILE containing "gitdir: /path/to/actual/git/dir"
|
|
6
|
-
* → hooks at that resolved path + /hooks/
|
|
7
|
-
*
|
|
8
|
-
* This utility ensures all hook install/uninstall/check operations
|
|
9
|
-
* work correctly in both scenarios.
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
import { existsSync, readFileSync, statSync, mkdirSync } from 'node:fs';
|
|
13
|
-
import path from 'node:path';
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Resolve the actual .git directory path, following worktree indirection.
|
|
17
|
-
*
|
|
18
|
-
* @param projectRoot - The root of the working tree (where .git lives)
|
|
19
|
-
* @returns Absolute path to the real git dir, or null if no .git found
|
|
20
|
-
*/
|
|
21
|
-
export function resolveGitDir(projectRoot: string): string | null {
|
|
22
|
-
const dotGit = path.join(projectRoot, '.git');
|
|
23
|
-
|
|
24
|
-
if (!existsSync(dotGit)) return null;
|
|
25
|
-
|
|
26
|
-
const stat = statSync(dotGit);
|
|
27
|
-
|
|
28
|
-
if (stat.isDirectory()) {
|
|
29
|
-
// Normal repo — .git is a directory
|
|
30
|
-
return dotGit;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
if (stat.isFile()) {
|
|
34
|
-
// Worktree — .git is a file: "gitdir: /path/to/actual/git/dir"
|
|
35
|
-
try {
|
|
36
|
-
const content = readFileSync(dotGit, 'utf-8').trim();
|
|
37
|
-
const match = content.match(/^gitdir:\s*(.+)$/);
|
|
38
|
-
if (match) {
|
|
39
|
-
const gitdir = match[1].trim();
|
|
40
|
-
// Resolve relative paths against the project root
|
|
41
|
-
const resolved = path.isAbsolute(gitdir)
|
|
42
|
-
? gitdir
|
|
43
|
-
: path.resolve(projectRoot, gitdir);
|
|
44
|
-
if (existsSync(resolved)) {
|
|
45
|
-
return resolved;
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
} catch {
|
|
49
|
-
// Unreadable .git file — fall through
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
return null;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* Resolve the hooks directory for a project (read-only — does NOT create directories).
|
|
58
|
-
* Handles both normal repos and git worktrees.
|
|
59
|
-
*
|
|
60
|
-
* @param projectRoot - The root of the working tree
|
|
61
|
-
* @returns Object with hooksDir and hookPath for post-commit, or null if no .git found
|
|
62
|
-
*/
|
|
63
|
-
export function resolveHooksDir(projectRoot: string): { hooksDir: string; hookPath: string } | null {
|
|
64
|
-
const gitDir = resolveGitDir(projectRoot);
|
|
65
|
-
if (!gitDir) return null;
|
|
66
|
-
|
|
67
|
-
const hooksDir = path.join(gitDir, 'hooks');
|
|
68
|
-
|
|
69
|
-
return {
|
|
70
|
-
hooksDir,
|
|
71
|
-
hookPath: path.join(hooksDir, 'post-commit'),
|
|
72
|
-
};
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
/**
|
|
76
|
-
* Resolve hooks directory AND ensure it exists on disk.
|
|
77
|
-
* Use this only in write paths (hook install / autoHook).
|
|
78
|
-
*/
|
|
79
|
-
export function ensureHooksDir(projectRoot: string): { hooksDir: string; hookPath: string } | null {
|
|
80
|
-
const resolved = resolveHooksDir(projectRoot);
|
|
81
|
-
if (!resolved) return null;
|
|
82
|
-
|
|
83
|
-
mkdirSync(resolved.hooksDir, { recursive: true });
|
|
84
|
-
return resolved;
|
|
85
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* Git hooks path resolver — worktree-safe.
|
|
3
|
+
*
|
|
4
|
+
* In a normal repo: .git is a directory → hooks at .git/hooks/
|
|
5
|
+
* In a git worktree: .git is a FILE containing "gitdir: /path/to/actual/git/dir"
|
|
6
|
+
* → hooks at that resolved path + /hooks/
|
|
7
|
+
*
|
|
8
|
+
* This utility ensures all hook install/uninstall/check operations
|
|
9
|
+
* work correctly in both scenarios.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import { existsSync, readFileSync, statSync, mkdirSync } from 'node:fs';
|
|
13
|
+
import path from 'node:path';
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Resolve the actual .git directory path, following worktree indirection.
|
|
17
|
+
*
|
|
18
|
+
* @param projectRoot - The root of the working tree (where .git lives)
|
|
19
|
+
* @returns Absolute path to the real git dir, or null if no .git found
|
|
20
|
+
*/
|
|
21
|
+
export function resolveGitDir(projectRoot: string): string | null {
|
|
22
|
+
const dotGit = path.join(projectRoot, '.git');
|
|
23
|
+
|
|
24
|
+
if (!existsSync(dotGit)) return null;
|
|
25
|
+
|
|
26
|
+
const stat = statSync(dotGit);
|
|
27
|
+
|
|
28
|
+
if (stat.isDirectory()) {
|
|
29
|
+
// Normal repo — .git is a directory
|
|
30
|
+
return dotGit;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
if (stat.isFile()) {
|
|
34
|
+
// Worktree — .git is a file: "gitdir: /path/to/actual/git/dir"
|
|
35
|
+
try {
|
|
36
|
+
const content = readFileSync(dotGit, 'utf-8').trim();
|
|
37
|
+
const match = content.match(/^gitdir:\s*(.+)$/);
|
|
38
|
+
if (match) {
|
|
39
|
+
const gitdir = match[1].trim();
|
|
40
|
+
// Resolve relative paths against the project root
|
|
41
|
+
const resolved = path.isAbsolute(gitdir)
|
|
42
|
+
? gitdir
|
|
43
|
+
: path.resolve(projectRoot, gitdir);
|
|
44
|
+
if (existsSync(resolved)) {
|
|
45
|
+
return resolved;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
} catch {
|
|
49
|
+
// Unreadable .git file — fall through
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Resolve the hooks directory for a project (read-only — does NOT create directories).
|
|
58
|
+
* Handles both normal repos and git worktrees.
|
|
59
|
+
*
|
|
60
|
+
* @param projectRoot - The root of the working tree
|
|
61
|
+
* @returns Object with hooksDir and hookPath for post-commit, or null if no .git found
|
|
62
|
+
*/
|
|
63
|
+
export function resolveHooksDir(projectRoot: string): { hooksDir: string; hookPath: string } | null {
|
|
64
|
+
const gitDir = resolveGitDir(projectRoot);
|
|
65
|
+
if (!gitDir) return null;
|
|
66
|
+
|
|
67
|
+
const hooksDir = path.join(gitDir, 'hooks');
|
|
68
|
+
|
|
69
|
+
return {
|
|
70
|
+
hooksDir,
|
|
71
|
+
hookPath: path.join(hooksDir, 'post-commit'),
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Resolve hooks directory AND ensure it exists on disk.
|
|
77
|
+
* Use this only in write paths (hook install / autoHook).
|
|
78
|
+
*/
|
|
79
|
+
export function ensureHooksDir(projectRoot: string): { hooksDir: string; hookPath: string } | null {
|
|
80
|
+
const resolved = resolveHooksDir(projectRoot);
|
|
81
|
+
if (!resolved) return null;
|
|
82
|
+
|
|
83
|
+
mkdirSync(resolved.hooksDir, { recursive: true });
|
|
84
|
+
return resolved;
|
|
85
|
+
}
|
package/src/hooks/handler.ts
CHANGED
|
@@ -22,6 +22,9 @@ import { detectBestPattern, patternToObservationType } from './pattern-detector.
|
|
|
22
22
|
import { isSignificantKnowledge, isRetrievedResult, isTrivialCommand } from './significance-filter.js';
|
|
23
23
|
import type { AgentName, HookEvent, HookOutput, NormalizedHookInput } from './types.js';
|
|
24
24
|
|
|
25
|
+
type HookInjectionMode = 'full' | 'minimal' | 'silent';
|
|
26
|
+
type HookContextTarget = 'hook-session-start' | 'hook-user-prompt';
|
|
27
|
+
|
|
25
28
|
// ─── Constants ───
|
|
26
29
|
|
|
27
30
|
/** Observation type → emoji mapping (single source of truth) */
|
|
@@ -282,16 +285,117 @@ function buildObservation(
|
|
|
282
285
|
|
|
283
286
|
// ─── Session Start Handler ───
|
|
284
287
|
|
|
288
|
+
async function getHookInjectionMode(input: NormalizedHookInput): Promise<HookInjectionMode> {
|
|
289
|
+
try {
|
|
290
|
+
const { getBehaviorConfig } = await import('../config/behavior.js');
|
|
291
|
+
return getBehaviorConfig({ projectRoot: input.cwd || undefined }).sessionInject;
|
|
292
|
+
} catch {
|
|
293
|
+
return 'minimal';
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
/**
|
|
298
|
+
* Assemble the one bounded project brief shared by hook delivery points.
|
|
299
|
+
* Hooks never retrieve a transcript: this returns only the normal Workset.
|
|
300
|
+
*/
|
|
301
|
+
async function buildHookProjectContext(
|
|
302
|
+
input: NormalizedHookInput,
|
|
303
|
+
task: string,
|
|
304
|
+
target: HookContextTarget,
|
|
305
|
+
): Promise<{ prompt: string; hasContinuation: boolean } | null> {
|
|
306
|
+
try {
|
|
307
|
+
const { detectProject } = await import('../project/detector.js');
|
|
308
|
+
const { getProjectDataDir } = await import('../store/persistence.js');
|
|
309
|
+
const { initObservationStore, getObservationStore: getStore } = await import('../store/obs-store.js');
|
|
310
|
+
const { initMiniSkillStore } = await import('../store/mini-skill-store.js');
|
|
311
|
+
const { initSessionStore } = await import('../store/session-store.js');
|
|
312
|
+
const { initAliasRegistry, registerAlias } = await import('../project/aliases.js');
|
|
313
|
+
const { MaintenanceTargetStore } = await import('../runtime/maintenance-targets.js');
|
|
314
|
+
const { buildAutoProjectContext, formatAutoProjectContextPrompt } = await import('../codegraph/auto-context.js');
|
|
315
|
+
const { filterReadableObservations } = await import('../memory/visibility.js');
|
|
316
|
+
|
|
317
|
+
const rawProject = detectProject(input.cwd || process.cwd());
|
|
318
|
+
if (!rawProject) return null;
|
|
319
|
+
const dataDir = await getProjectDataDir(rawProject.id);
|
|
320
|
+
|
|
321
|
+
initAliasRegistry(dataDir);
|
|
322
|
+
const canonicalId = await registerAlias(rawProject);
|
|
323
|
+
new MaintenanceTargetStore(dataDir).register({
|
|
324
|
+
projectId: canonicalId,
|
|
325
|
+
projectRoot: rawProject.rootPath,
|
|
326
|
+
dataDir,
|
|
327
|
+
});
|
|
328
|
+
await initObservationStore(dataDir);
|
|
329
|
+
await initMiniSkillStore(dataDir);
|
|
330
|
+
await initSessionStore(dataDir);
|
|
331
|
+
const activeObservations = filterReadableObservations(
|
|
332
|
+
await getStore().loadByProject(canonicalId, { status: 'active' }),
|
|
333
|
+
{ projectId: canonicalId },
|
|
334
|
+
);
|
|
335
|
+
const context = await buildAutoProjectContext({
|
|
336
|
+
project: { ...rawProject, id: canonicalId },
|
|
337
|
+
dataDir,
|
|
338
|
+
observations: activeObservations,
|
|
339
|
+
task,
|
|
340
|
+
refresh: 'auto',
|
|
341
|
+
reader: { projectId: canonicalId },
|
|
342
|
+
continuation: 'always',
|
|
343
|
+
enqueueRefresh: () => import('../runtime/lifecycle.js').then(({ enqueueCodegraphRefresh }) => {
|
|
344
|
+
enqueueCodegraphRefresh({
|
|
345
|
+
dataDir,
|
|
346
|
+
projectId: canonicalId,
|
|
347
|
+
source: target === 'hook-user-prompt' ? 'hook-user-prompt' : 'hook-session-start',
|
|
348
|
+
maxFiles: 5_000,
|
|
349
|
+
});
|
|
350
|
+
}),
|
|
351
|
+
deliveryTarget: target,
|
|
352
|
+
});
|
|
353
|
+
|
|
354
|
+
return {
|
|
355
|
+
prompt: formatAutoProjectContextPrompt(context),
|
|
356
|
+
hasContinuation: Boolean(
|
|
357
|
+
context.continuation?.previousSession || (context.continuation?.memories.length ?? 0) > 0,
|
|
358
|
+
),
|
|
359
|
+
};
|
|
360
|
+
} catch (error) {
|
|
361
|
+
// A context hint must never interrupt the host's turn. The structured
|
|
362
|
+
// error is intentionally kept in stderr for hook diagnostics.
|
|
363
|
+
console.error('[memorix] hook context failed:', (error as Error)?.message ?? error);
|
|
364
|
+
return null;
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
/**
|
|
369
|
+
* Claude Code ignores SessionStart systemMessage as model context. Its official
|
|
370
|
+
* UserPromptSubmit output accepts additionalContext, so explicit continuation
|
|
371
|
+
* requests are delivered there instead of relying on a rules-file suggestion.
|
|
372
|
+
*/
|
|
373
|
+
async function buildClaudeContinuationPromptContext(input: NormalizedHookInput): Promise<string | undefined> {
|
|
374
|
+
if (input.agent !== 'claude' || input.event !== 'user_prompt' || !input.userPrompt?.trim()) {
|
|
375
|
+
return undefined;
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
const { isContinuationTask } = await import('../codegraph/task-lens.js');
|
|
379
|
+
if (!isContinuationTask(input.userPrompt)) return undefined;
|
|
380
|
+
|
|
381
|
+
if (await getHookInjectionMode(input) === 'silent') return undefined;
|
|
382
|
+
|
|
383
|
+
const context = await buildHookProjectContext(input, input.userPrompt, 'hook-user-prompt');
|
|
384
|
+
if (!context?.hasContinuation) return undefined;
|
|
385
|
+
|
|
386
|
+
return [
|
|
387
|
+
'Memorix prepared a bounded prior-work brief for this explicit continuation request.',
|
|
388
|
+
'Treat it as background context; current code wins. Use it before broad Git or file-history archaeology.',
|
|
389
|
+
'',
|
|
390
|
+
context.prompt,
|
|
391
|
+
].join('\n');
|
|
392
|
+
}
|
|
393
|
+
|
|
285
394
|
async function handleSessionStart(input: NormalizedHookInput): Promise<{
|
|
286
395
|
observation: ReturnType<typeof buildObservation> | null;
|
|
287
396
|
output: HookOutput;
|
|
288
397
|
}> {
|
|
289
|
-
|
|
290
|
-
let injectMode: 'full' | 'minimal' | 'silent' = 'minimal';
|
|
291
|
-
try {
|
|
292
|
-
const { getBehaviorConfig } = await import('../config/behavior.js');
|
|
293
|
-
injectMode = getBehaviorConfig().sessionInject;
|
|
294
|
-
} catch { /* default to minimal */ }
|
|
398
|
+
const injectMode = await getHookInjectionMode(input);
|
|
295
399
|
|
|
296
400
|
if (injectMode === 'silent') {
|
|
297
401
|
return { observation: null, output: { continue: true } };
|
|
@@ -299,55 +403,8 @@ async function handleSessionStart(input: NormalizedHookInput): Promise<{
|
|
|
299
403
|
|
|
300
404
|
let contextSummary = '';
|
|
301
405
|
if (injectMode === 'full') {
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
const { getProjectDataDir } = await import('../store/persistence.js');
|
|
305
|
-
const { initObservationStore, getObservationStore: getStore } = await import('../store/obs-store.js');
|
|
306
|
-
const { initMiniSkillStore } = await import('../store/mini-skill-store.js');
|
|
307
|
-
const { initSessionStore } = await import('../store/session-store.js');
|
|
308
|
-
const { initAliasRegistry, registerAlias } = await import('../project/aliases.js');
|
|
309
|
-
const { MaintenanceTargetStore } = await import('../runtime/maintenance-targets.js');
|
|
310
|
-
const { buildAutoProjectContext, formatAutoProjectContextPrompt } = await import('../codegraph/auto-context.js');
|
|
311
|
-
const { filterReadableObservations } = await import('../memory/visibility.js');
|
|
312
|
-
|
|
313
|
-
const rawProject = detectProject(input.cwd || process.cwd());
|
|
314
|
-
if (!rawProject) throw new Error('No .git found');
|
|
315
|
-
const dataDir = await getProjectDataDir(rawProject.id);
|
|
316
|
-
|
|
317
|
-
initAliasRegistry(dataDir);
|
|
318
|
-
const canonicalId = await registerAlias(rawProject);
|
|
319
|
-
new MaintenanceTargetStore(dataDir).register({
|
|
320
|
-
projectId: canonicalId,
|
|
321
|
-
projectRoot: rawProject.rootPath,
|
|
322
|
-
dataDir,
|
|
323
|
-
});
|
|
324
|
-
await initObservationStore(dataDir);
|
|
325
|
-
await initMiniSkillStore(dataDir);
|
|
326
|
-
await initSessionStore(dataDir);
|
|
327
|
-
const activeObservations = filterReadableObservations(
|
|
328
|
-
await getStore().loadByProject(canonicalId, { status: 'active' }),
|
|
329
|
-
{ projectId: canonicalId },
|
|
330
|
-
);
|
|
331
|
-
const context = await buildAutoProjectContext({
|
|
332
|
-
project: { ...rawProject, id: canonicalId },
|
|
333
|
-
dataDir,
|
|
334
|
-
observations: activeObservations,
|
|
335
|
-
refresh: 'auto',
|
|
336
|
-
enqueueRefresh: () => import('../runtime/lifecycle.js').then(({ enqueueCodegraphRefresh }) => {
|
|
337
|
-
enqueueCodegraphRefresh({
|
|
338
|
-
dataDir,
|
|
339
|
-
projectId: canonicalId,
|
|
340
|
-
source: 'hook-session-start',
|
|
341
|
-
maxFiles: 5_000,
|
|
342
|
-
});
|
|
343
|
-
}),
|
|
344
|
-
deliveryTarget: 'hook-session-start',
|
|
345
|
-
});
|
|
346
|
-
contextSummary = `\n\n${formatAutoProjectContextPrompt(context)}`;
|
|
347
|
-
} catch (sessErr) {
|
|
348
|
-
// Diagnostic log — session start context injection failed
|
|
349
|
-
console.error('[memorix] session start context failed:', (sessErr as Error)?.message ?? sessErr);
|
|
350
|
-
}
|
|
406
|
+
const context = await buildHookProjectContext(input, 'Continue the current task.', 'hook-session-start');
|
|
407
|
+
if (context) contextSummary = `\n\n${context.prompt}`;
|
|
351
408
|
}
|
|
352
409
|
|
|
353
410
|
// Build system message based on inject mode
|
|
@@ -378,6 +435,10 @@ async function handleHookEventCore(input: NormalizedHookInput): Promise<{
|
|
|
378
435
|
output: HookOutput;
|
|
379
436
|
}> {
|
|
380
437
|
const defaultOutput: HookOutput = { continue: true };
|
|
438
|
+
const continuationMessage = await buildClaudeContinuationPromptContext(input);
|
|
439
|
+
const output = continuationMessage
|
|
440
|
+
? { ...defaultOutput, systemMessage: continuationMessage }
|
|
441
|
+
: defaultOutput;
|
|
381
442
|
|
|
382
443
|
// ─── Session lifecycle (special handling) ───
|
|
383
444
|
if (input.event === 'session_start') {
|
|
@@ -386,7 +447,7 @@ async function handleHookEventCore(input: NormalizedHookInput): Promise<{
|
|
|
386
447
|
if (input.event === 'session_end') {
|
|
387
448
|
const endContent = extractContent(input);
|
|
388
449
|
if (endContent.length < 50) {
|
|
389
|
-
return { observation: null, output
|
|
450
|
+
return { observation: null, output };
|
|
390
451
|
}
|
|
391
452
|
const draft = buildObservation(input, endContent, 'unknown');
|
|
392
453
|
const admission = assessHookAdmission({
|
|
@@ -399,13 +460,13 @@ async function handleHookEventCore(input: NormalizedHookInput): Promise<{
|
|
|
399
460
|
observation: admission.action === 'store'
|
|
400
461
|
? buildObservation(input, endContent, 'unknown', admission)
|
|
401
462
|
: null,
|
|
402
|
-
output
|
|
463
|
+
output,
|
|
403
464
|
};
|
|
404
465
|
}
|
|
405
466
|
if (input.event === 'post_compact') {
|
|
406
467
|
// Post-compaction: acknowledge the event, no observation needed.
|
|
407
468
|
// The real value is the side-effect (runHook pipe) already handled by the plugin.
|
|
408
|
-
return { observation: null, output
|
|
469
|
+
return { observation: null, output };
|
|
409
470
|
}
|
|
410
471
|
|
|
411
472
|
// ─── Classify & extract ───
|
|
@@ -415,7 +476,7 @@ async function handleHookEventCore(input: NormalizedHookInput): Promise<{
|
|
|
415
476
|
|
|
416
477
|
// Never-store category (memorix's own tools)
|
|
417
478
|
if (policy.store === 'never') {
|
|
418
|
-
return { observation: null, output
|
|
479
|
+
return { observation: null, output };
|
|
419
480
|
}
|
|
420
481
|
|
|
421
482
|
// ─── Significance Filter (Cipher-style noise rejection) ───
|
|
@@ -423,13 +484,13 @@ async function handleHookEventCore(input: NormalizedHookInput): Promise<{
|
|
|
423
484
|
if (category === 'command' && input.command) {
|
|
424
485
|
const realCmd = extractRealCommand(input.command);
|
|
425
486
|
if (isTrivialCommand(realCmd)) {
|
|
426
|
-
return { observation: null, output
|
|
487
|
+
return { observation: null, output };
|
|
427
488
|
}
|
|
428
489
|
}
|
|
429
490
|
|
|
430
491
|
// Skip retrieved/search results (prevent memory pollution)
|
|
431
492
|
if (isRetrievedResult(content)) {
|
|
432
|
-
return { observation: null, output
|
|
493
|
+
return { observation: null, output };
|
|
433
494
|
}
|
|
434
495
|
|
|
435
496
|
// Minimum length gate
|
|
@@ -437,7 +498,7 @@ async function handleHookEventCore(input: NormalizedHookInput): Promise<{
|
|
|
437
498
|
? MIN_PROMPT_LENGTH
|
|
438
499
|
: policy.minLength;
|
|
439
500
|
if (content.length < minLen) {
|
|
440
|
-
return { observation: null, output
|
|
501
|
+
return { observation: null, output };
|
|
441
502
|
}
|
|
442
503
|
|
|
443
504
|
// User prompts & AI responses are direct interaction — check significance
|
|
@@ -450,7 +511,7 @@ async function handleHookEventCore(input: NormalizedHookInput): Promise<{
|
|
|
450
511
|
if (effectiveStore !== 'always') {
|
|
451
512
|
const significance = isSignificantKnowledge(content);
|
|
452
513
|
if (!significance.isSignificant) {
|
|
453
|
-
return { observation: null, output
|
|
514
|
+
return { observation: null, output };
|
|
454
515
|
}
|
|
455
516
|
}
|
|
456
517
|
|
|
@@ -459,14 +520,14 @@ async function handleHookEventCore(input: NormalizedHookInput): Promise<{
|
|
|
459
520
|
const pattern = detectBestPattern(content);
|
|
460
521
|
const significance = isSignificantKnowledge(content);
|
|
461
522
|
if (!pattern && content.length < 200 && !significance.isSignificant) {
|
|
462
|
-
return { observation: null, output
|
|
523
|
+
return { observation: null, output };
|
|
463
524
|
}
|
|
464
525
|
}
|
|
465
526
|
|
|
466
527
|
// Cooldown (per-file or per-command, not per-tool-category)
|
|
467
528
|
const cooldownKey = buildCooldownKey(input, content);
|
|
468
529
|
if (isInCooldown(cooldownKey)) {
|
|
469
|
-
return { observation: null, output
|
|
530
|
+
return { observation: null, output };
|
|
470
531
|
}
|
|
471
532
|
markTriggered(cooldownKey);
|
|
472
533
|
|
|
@@ -481,7 +542,7 @@ async function handleHookEventCore(input: NormalizedHookInput): Promise<{
|
|
|
481
542
|
observation: admission.action === 'store'
|
|
482
543
|
? buildObservation(input, content, category, admission)
|
|
483
544
|
: null,
|
|
484
|
-
output
|
|
545
|
+
output,
|
|
485
546
|
};
|
|
486
547
|
}
|
|
487
548
|
|
|
@@ -1210,17 +1210,18 @@ function getAgentRulesContent(agent?: AgentName, scope: 'project' | 'global' = '
|
|
|
1210
1210
|
'',
|
|
1211
1211
|
'## Start with Memory Autopilot',
|
|
1212
1212
|
'',
|
|
1213
|
-
`Default first step for non-trivial coding work: call \x60memorix_project_context\x60 with the user's actual task before progress files, dev-log reads, ad-hoc file reads, or git archaeology. Memorix will choose a task-lensed brief (bugfix, feature, release, onboarding, refactor, docs, test, or general). Treat its "Start here" files as the first ${contextNoun} files to inspect.`,
|
|
1213
|
+
`Default first step for non-trivial coding work: call \x60memorix_project_context\x60 with the user's actual task before progress files, dev-log reads, ad-hoc file reads, or git archaeology. Memorix will choose a task-lensed brief (bugfix, feature, release, onboarding, refactor, docs, test, or general). When the task is continuing prior work, the same brief also includes a bounded prior-work projection. Treat its "Start here" files as the first ${contextNoun} files to inspect.`,
|
|
1214
1214
|
'',
|
|
1215
|
-
'If the MCP tool is not visible yet but the client supports tool discovery or dynamic loading, search/select \x60memorix_project_context\x60 first.
|
|
1215
|
+
'If the MCP tool is not visible yet but the client supports tool discovery or dynamic loading, search/select \x60memorix_project_context\x60 first. Continuation fallback is mandatory: when the user asks to continue, resume, take over, or explain prior work and MCP cannot be called in this turn, run exactly one CLI brief with the user\'s real task before inspecting files, Git history, progress notes, or guessing: \x60memorix resume "<task>" --json\x60. For a new task, use \x60memorix context "<task>" --json\x60 instead. The absence of \x60.memorix\x60 or visible memory files never proves project memory is empty. If that one command fails, report it and proceed normally. Do not probe help, enumerate commands, chain broad searches, wait indefinitely on MCP startup, or hand-write tool-call syntax.',
|
|
1216
1216
|
'',
|
|
1217
|
-
'Use \x60memorix_context_pack\x60 when
|
|
1217
|
+
'After a successful \x60memorix_project_context\x60 result, the brief is the default retrieval boundary. Do not call more Memorix retrieval tools after a complete brief. Use \x60memorix_context_pack\x60, \x60memorix_search\x60, or \x60memorix_detail\x60 only when the brief lacks a specific reference, freshness field, or fact needed for the task, or when the user explicitly asks for deeper history. In MCP, name that missing fact in \x60purpose\x60 when intentionally expanding beyond the brief. Do not retrieve the same decision twice just to confirm an already-complete brief.',
|
|
1218
|
+
'If the user asks for read-only work or says not to modify files, do not call \x60memorix_store\x60 just to record an assessment. Store only when the user explicitly asks to preserve it.',
|
|
1218
1219
|
'',
|
|
1219
1220
|
'## When to search memory',
|
|
1220
1221
|
'',
|
|
1221
1222
|
'Use \x60memorix_graph_context\x60 for explicit memory graph questions or broad graph overview after the autopilot brief is not enough.',
|
|
1222
1223
|
'',
|
|
1223
|
-
`Use \x60memorix_search\x60 when prior ${contextNoun} context would help — for example:`,
|
|
1224
|
+
`Use \x60memorix_search\x60 when prior ${contextNoun} context would help and the Autopilot brief did not already answer the question — for example:`,
|
|
1224
1225
|
'- The user asks about a past decision, bug, or change',
|
|
1225
1226
|
'- You need to understand why something was designed a certain way',
|
|
1226
1227
|
"- You're continuing work that started in a previous session",
|
|
@@ -31,7 +31,8 @@ export const OFFICIAL_MEMORIX_SKILLS: OfficialMemorixSkill[] = [
|
|
|
31
31
|
'',
|
|
32
32
|
'| Situation | Prefer | CLI fallback |',
|
|
33
33
|
'|---|---|---|',
|
|
34
|
-
'| Starting
|
|
34
|
+
'| Starting a coding task and needing the best task-lensed project map | `memorix_project_context` with the user\'s task | `memorix context "<task>" --json` |',
|
|
35
|
+
'| Continuing prior project work | `memorix_project_context` with the user\'s task | `memorix resume "<task>" --json` |',
|
|
35
36
|
'| Need structured refs/freshness for code-bound memories | `memorix_context_pack` | `memorix codegraph context-pack --task "<topic>"` |',
|
|
36
37
|
'| Explicit memory graph question | `memorix_graph_context` | `memorix memory graph-context --query "<topic>"` |',
|
|
37
38
|
'| Specific past decision, bug, file, or change | `memorix_search` | `memorix memory search --query "<topic>"` |',
|
|
@@ -44,9 +45,10 @@ export const OFFICIAL_MEMORIX_SKILLS: OfficialMemorixSkill[] = [
|
|
|
44
45
|
'',
|
|
45
46
|
'- Default first step for non-trivial coding work: call `memorix_project_context` before progress files, dev-log reads, ad-hoc file reads, or git archaeology. Pass the user\'s actual task so Memorix can choose a bugfix, feature, release, onboarding, refactor, docs, test, or general brief. Start by reading its suggested files.',
|
|
46
47
|
'- In Claude Code headless/print-mode, an initial MCP `pending` status is not a failure by itself. Prefer MCP first: use the client\'s tool discovery/dynamic loading to find `memorix_project_context` when it is not in the first visible tool list.',
|
|
47
|
-
'-
|
|
48
|
-
'-
|
|
49
|
-
'-
|
|
48
|
+
'- Continuation fallback is mandatory: when the user asks to continue, resume, take over, or explain prior work and MCP cannot be called in this turn, run `memorix resume "<task>" --json` exactly once before inspecting files, Git history, progress notes, or guessing. The absence of `.memorix` or visible memory files never proves project memory is empty. For a new task, use `memorix context "<task>" --json` instead. If that one command fails, report it and proceed normally; do not probe help, enumerate commands, or chain broad searches.',
|
|
49
|
+
'- After a successful `memorix_project_context`, the brief is the default retrieval boundary. Do not call more Memorix retrieval tools after a complete brief. Use Context Pack, search, or detail only when the brief lacks a specific reference, freshness field, or fact needed for the task, or when the user explicitly asks for deeper history. In MCP, name that missing fact in `purpose` when intentionally expanding beyond the brief. Do not retrieve the same decision twice just to confirm an already-complete brief.',
|
|
50
|
+
'- If the user asks for read-only work or says not to modify files, do not call `memorix_store` just to record an assessment. Store only when the user explicitly asks to preserve it.',
|
|
51
|
+
'- Use `memorix_search` for a specific decision, bug, file, or prior change that the project context did not answer. Fetch detail only for a result you still need after the brief.',
|
|
50
52
|
'- Treat current code-bound memory as a map. Treat stale, suspect, or unbound memory as a lead that must be verified against the current code.',
|
|
51
53
|
'- Skip memory lookup for greetings, tiny one-off edits, or questions fully answered by the current file.',
|
|
52
54
|
'- If a fresh project has no memories, proceed normally and do not repeat the same empty search in the same turn.',
|