kenaz 0.3.17 → 0.3.19
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/core/.claude/commands/agent-worker.md +1 -1
- package/core/.claude/commands/architect.md +1 -2
- package/core/.claude/commands/spec.md +1 -1
- package/core/.claude/commands//347/224/242/345/223/201.md +1 -1
- package/core/.claude/hooks/__tests__/task-1977-dedupe-guard.test.js +8 -8
- package/core/.claude/hooks/synapse-first-investigation.js +15 -0
- package/core/.claude/skills/architect_agent/SKILL.md +11 -92
- package/core/.claude/skills/assessment_agent/SKILL.md +0 -1
- package/core/.claude/skills/backend_engineer/SKILL.md +3 -6
- package/core/.claude/skills/code_reviewer/SKILL.md +1 -1
- package/core/.claude/skills/code_reviewer/patterns.yaml +1 -1
- package/core/.claude/skills/designer/SKILL.md +3 -6
- package/core/.claude/skills/dev_agent/SKILL.md +30 -491
- package/core/.claude/skills/developer/SKILL.md +3 -6
- package/core/.claude/skills/feature_agent/SKILL.md +3 -17
- package/core/.claude/skills/product_manager/SKILL.md +29 -1064
- package/core/.claude/skills/qa_engineer/SKILL.md +12 -17
- package/core/.claude/skills/spec_optimizer/SKILL.md +25 -275
- package/core/.claude/skills/sre_agent/SKILL.md +3 -6
- package/core/.collaboration/README.md +2 -3
- package/core/.collaboration/core/task-api.js +5 -138
- package/core/.collaboration/docs/CLI.md +0 -2
- package/core/.failure/INDEX.yaml +6 -40
- package/core/.failure/agent-execution/FAIL-013-search-cwd-drift-and-case-mismatch.yaml +1 -1
- package/core/.failure/tools/README.md +9 -227
- package/core/.formation/bifrost/exec.js +29 -4
- package/core/.formation/bifrost/launch.js +1 -6
- package/core/.formation/bifrost/launch.test.js +1 -1
- package/core/.formation/bifrost/provider-launch.js +18 -11
- package/core/.formation/bifrost/provider-launch.test.js +26 -2
- package/core/.formation/bifrost/shared/ansuz-boot-policy.js +3 -3
- package/core/.formation/bifrost/shared/ansuz-boot-policy.test.js +1 -2
- package/core/.formation/tools/__tests__/dispatch-cwd-project.test.js +42 -0
- package/core/.formation/tools/__tests__/m1-hmap-convid.test.js +1 -124
- package/core/.formation/tools/__tests__/subagent-executor.test.js +3 -2
- package/core/.formation/tools/dispatch.js +15 -2
- package/core/.formation/tools/loader.js +17 -140
- package/core/.formation/tools/post-complete.js +0 -31
- package/core/.rule/INDEX.yaml +0 -18
- package/core/.rule/general/agent-workflow.yaml +14 -164
- package/core/.rule/general/project-self-containment.yaml +8 -19
- package/core/.rule/general/rust-verify-target.yaml +6 -5
- package/core/.rule/general/synapse-code-intelligence.yaml +3 -3
- package/core/.specialist/Amelia/capability.yaml +12 -12
- package/core/.specialist/Amelia/workflow.yaml +2 -2
- package/core/.specialist/Ansuz/SYSTEM_DOC.md +20 -578
- package/core/.specialist/Ansuz/cognitive_principles.yaml +2 -3
- package/core/.specialist/Ansuz/concepts/boot_rules_summary.yaml +0 -1
- package/core/.specialist/Ansuz/concepts/deep_knowledge_pointers.yaml +1 -2
- package/core/.specialist/Ansuz/core.yaml +6 -108
- package/core/.specialist/Ansuz/guards/lesson_guards.yaml +0 -3
- package/core/.specialist/Ansuz/identity_contract.yaml +0 -1
- package/core/.specialist/Ansuz/knowledge.yaml +0 -4
- package/core/.specialist/Ansuz/rule.yaml +0 -1
- package/core/.specialist/Ansuz/tools/handoff-session-identity.test.js +6 -150
- package/core/.specialist/tests/runtime-discovery/README.md +1 -1
- package/core/.specialist/tools/__tests__/task-2374-usage-counter.test.js +1 -12
- package/core/.specialist/tools/prompt-files.test.js +1 -0
- package/core/.specialist/tools/task-bridge.js +1 -66
- package/core/.system/README.md +11 -552
- package/core/.system/collaboration/README.md +10 -174
- package/core/CLAUDE.md +1 -6
- package/core/KENAZ_CORE_VERSION +1 -1
- package/core/dev/scripts/js-yaml-resolution.test.js +1 -1
- package/core/dev/scripts/run-rust-tests.js +30 -46
- package/core/dev/scripts/run-rust-tests.test.js +17 -0
- package/core/dev/scripts/rust-verify-worktree.js +4 -4
- package/core/dev/scripts/verify-target-dir.js +6 -6
- package/core/plugins/kenaz/INVENTORY.md +8 -8
- package/core/plugins/kenaz/commands/architect.md +1 -2
- package/core/plugins/kenaz/commands/spec.md +1 -1
- package/core/plugins/kenaz/commands//347/224/242/345/223/201.md +1 -1
- package/core/plugins/kenaz/guidance.md +1 -1
- package/core/plugins/kenaz/scripts/sync.js +1 -1
- package/core/plugins/kenaz/scripts/ygg.js +6 -0
- package/core/plugins/kenaz/skills/architect_agent/SKILL.md +11 -92
- package/core/plugins/kenaz/skills/assessment_agent/SKILL.md +0 -1
- package/core/plugins/kenaz/skills/backend_engineer/SKILL.md +3 -6
- package/core/plugins/kenaz/skills/code_reviewer/SKILL.md +1 -1
- package/core/plugins/kenaz/skills/code_reviewer/patterns.yaml +1 -1
- package/core/plugins/kenaz/skills/designer/SKILL.md +3 -6
- package/core/plugins/kenaz/skills/dev_agent/SKILL.md +30 -491
- package/core/plugins/kenaz/skills/developer/SKILL.md +3 -6
- package/core/plugins/kenaz/skills/feature_agent/SKILL.md +3 -17
- package/core/plugins/kenaz/skills/product_manager/SKILL.md +29 -1064
- package/core/plugins/kenaz/skills/qa_engineer/SKILL.md +12 -17
- package/core/plugins/kenaz/skills/spec_optimizer/SKILL.md +25 -275
- package/core/plugins/kenaz/skills/sre_agent/SKILL.md +3 -6
- package/package.json +6 -6
- package/core/.claude/commands/archive.md +0 -24
- package/core/.claude/commands/init.md +0 -112
- package/core/.claude/commands/legacy_dev.md +0 -18
- package/core/.claude/commands/product-review.md +0 -131
- package/core/.claude/commands/strategy.md +0 -141
- package/core/.claude/commands/sunny.md +0 -1
- package/core/.claude/commands//347/224/242/345/223/201/346/252/242/350/246/226.md +0 -129
- package/core/.claude/commands//351/200/262/345/272/246.md +0 -15
- package/core/.claude/hooks/__tests__/substrate.test.js +0 -122
- package/core/.claude/hooks/_substrate-paths.js +0 -95
- package/core/.claude/hooks/context-check.js +0 -51
- package/core/.claude/hooks/fatigue-check.js +0 -52
- package/core/.claude/hooks/handoff-snapshot-on-commit.js +0 -154
- package/core/.claude/hooks/handoff-snapshot-on-question.js +0 -158
- package/core/.claude/hooks/handoff-staleness.js +0 -197
- package/core/.claude/hooks/jev-thalamus-context.js +0 -17
- package/core/.claude/hooks/jev-thalamus-context.test.js +0 -41
- package/core/.claude/hooks/lease-release.js +0 -119
- package/core/.claude/hooks/lease-touch.js +0 -96
- package/core/.claude/hooks/reflex-feedback.js +0 -5
- package/core/.claude/hooks/session-init.ps1 +0 -49
- package/core/.claude/hooks/sound-event.js +0 -70
- package/core/.claude/hooks/sound-event.sh +0 -37
- package/core/.claude/hooks/stream-delta.js +0 -169
- package/core/.claude/no-hooks.settings.json +0 -3
- package/core/.claude/skills/legacy_dev/SKILL.md +0 -202
- package/core/.claude/skills/sunny/SKILL.md +0 -74
- package/core/.collaboration/cli/commands/assign.js +0 -39
- package/core/.collaboration/cli/commands/claim.js +0 -33
- package/core/.collaboration/cli/commands/complete.js +0 -44
- package/core/.collaboration/cli/commands/create.js +0 -110
- package/core/.collaboration/cli/commands/get.js +0 -83
- package/core/.collaboration/cli/commands/index.js +0 -52
- package/core/.collaboration/cli/commands/list.js +0 -51
- package/core/.collaboration/cli/commands/lock.js +0 -45
- package/core/.collaboration/cli/commands/rebuild.js +0 -39
- package/core/.collaboration/cli/commands/search.js +0 -61
- package/core/.collaboration/cli/commands/stats.js +0 -61
- package/core/.collaboration/cli/commands/transfer.js +0 -41
- package/core/.collaboration/cli/commands/unlock.js +0 -48
- package/core/.collaboration/cli/formatters/help-formatter.js +0 -70
- package/core/.collaboration/cli/formatters/index.js +0 -7
- package/core/.collaboration/cli/task-cli.js +0 -46
- package/core/.collaboration/cli/utils/arg-parser.js +0 -74
- package/core/.collaboration/cli/utils/git-user.js +0 -25
- package/core/.collaboration/cli/utils/index.js +0 -9
- package/core/.collaboration/cli/utils/output.js +0 -10
- package/core/.collaboration/config/default.yaml +0 -189
- package/core/.collaboration/core/conflict-resolver.js +0 -461
- package/core/.collaboration/core/conflict-resolver.test.js +0 -389
- package/core/.collaboration/core/migrate-legacy.js +0 -260
- package/core/.collaboration/docs/API.md +0 -787
- package/core/.collaboration/docs/ARCHITECTURE.md +0 -596
- package/core/.collaboration/docs/FAQ.md +0 -695
- package/core/.collaboration/docs/MIGRATION.md +0 -804
- package/core/.collaboration/docs/examples/README.md +0 -320
- package/core/.collaboration/docs/examples/advanced-queries.js +0 -261
- package/core/.collaboration/docs/examples/basic-usage.js +0 -184
- package/core/.collaboration/docs/examples/team-workflow.js +0 -352
- package/core/.failure/agent-execution/FAIL-001-agent-no-output.yaml +0 -391
- package/core/.failure/agent-execution/FAIL-007-pm-lead-wrong-team-invocation.yaml +0 -0
- package/core/.failure/agent-execution/FAIL-010-phase0-poem-format-skipped.yaml +0 -28
- package/core/.failure/agent-execution/FAIL-010-skipping-cognitive-checkpoint-after-verification.yaml +0 -59
- package/core/.failure/agent-execution/FAIL-012-grep-shortcut-during-investigation.yaml +0 -85
- package/core/.failure/architecture/FAIL-006-python-version-compatibility.yaml +0 -445
- package/core/.failure/pipeline/FAIL-003-queue-pollution.yaml +0 -335
- package/core/.failure/pipeline/README.md +0 -95
- package/core/.failure/retired/FAIL-009-skipping-synapse-pulse-before-code-change.yaml +0 -49
- package/core/.failure/tools/USAGE_GUIDE.md +0 -323
- package/core/.failure/tools/check_failures.ps1 +0 -387
- package/core/.failure/tools/log_failure.ps1 +0 -474
- package/core/.formation/.episode-input.json +0 -10
- package/core/.formation/.merge-lock +0 -1
- package/core/.formation/lead.yaml +0 -118
- package/core/.formation/legacy.bak/designer.yaml +0 -57
- package/core/.formation/legacy.bak/pm.yaml +0 -57
- package/core/.formation/legacy.bak/qa.yaml +0 -57
- package/core/.formation/legacy.bak/review.yaml +0 -62
- package/core/.formation/legacy.bak/scheduler.yaml +0 -129
- package/core/.formation/legacy.bak/sre.yaml +0 -57
- package/core/.formation/role-map.yaml +0 -274
- package/core/.formation/roles/_shared/modules/code_review.yaml +0 -98
- package/core/.formation/roles/_shared/modules/security.yaml +0 -103
- package/core/.formation/roles/_shared/modules/testing.yaml +0 -14
- package/core/.formation/roles/backend/role.yaml +0 -93
- package/core/.formation/roles/code_reviewer/role.yaml +0 -102
- package/core/.formation/roles/database_optimizer/role.yaml +0 -107
- package/core/.formation/roles/designer/role.yaml +0 -66
- package/core/.formation/roles/developer/role.yaml +0 -75
- package/core/.formation/roles/frontend/role.yaml +0 -134
- package/core/.formation/roles/incident_response/role.yaml +0 -89
- package/core/.formation/roles/qa/role.yaml +0 -89
- package/core/.formation/roles/security/role.yaml +0 -87
- package/core/.formation/roles/sre/role.yaml +0 -66
- package/core/.formation/skills/coordinator.yaml +0 -52
- package/core/.formation/solo/diagnosis.yaml +0 -78
- package/core/.formation/solo/strategy.yaml +0 -121
- package/core/.formation/tests/hello.txt +0 -2
- package/core/.formation/tools/coordinator.js +0 -350
- package/core/.formation/tools/jev-correction.js +0 -214
- package/core/.formation/tools/jev-correction.test.js +0 -178
- package/core/.formation/tools/log-reader.js +0 -232
- package/core/.formation/tools/revert-daemon-state.js +0 -162
- package/core/.formation/tools/test-drift.js +0 -148
- package/core/.formation/unit/heimdall.yaml +0 -96
- package/core/.formation/unit/plan.yaml +0 -67
- package/core/.formation/unit/think.yaml +0 -58
- package/core/.kenaz/MUNINN_SNAPSHOT9_EPISODE.json +0 -32
- package/core/.kenaz/MUNINN_SNAPSHOT9_RUNE.json +0 -23
- package/core/.kenaz/MUNINN_SNAPSHOT9_SUMMARY.md +0 -89
- package/core/.kenaz/ash_TASK_1428-20260507.json +0 -14
- package/core/.kenaz/muninn_episode_write.ps1 +0 -17
- package/core/.kenaz/muninn_snapshot11_rune_candidates.md +0 -63
- package/core/.kenaz/muninn_snapshot1_rune_candidates.md +0 -49
- package/core/.kenaz/runes_TASK_1428.json +0 -57
- package/core/.kenaz/tmp_heimdall_proposal_8d3e392.json +0 -13
- package/core/.kenaz/tmp_props.json +0 -1
- package/core/.kenaz/tmp_sounddrop_t1_prompt.txt +0 -371
- package/core/.rule/MECHANIZED.md +0 -61
- package/core/.rule/general/cortex-memory-recall.yaml +0 -446
- package/core/.rule/general/pipeline.yaml +0 -246
- package/core/.rule/general/sunny-access-control.yaml +0 -60
- package/core/.rule/general/system-invariants.yaml +0 -231
- package/core/.rule/pipeline/PPL-002-completed-task-archival.yaml +0 -528
- package/core/.rule/pipeline/auto-update.yaml +0 -282
- package/core/.rule/pipeline/task-execution.yaml +0 -365
- package/core/.specialist/Ansuz/concepts/phase_protocol.yaml +0 -65
- package/core/.specialist/Ansuz/experiments/boot_ablation_replay.js +0 -197
- package/core/.specialist/Ansuz/tools/bootstrap-anchors.js +0 -289
- package/core/.specialist/Ansuz/workflow.yaml +0 -1225
- package/core/.specialist/experiments/rg_benchmark.js +0 -523
- package/core/.specialist/experiments/rg_benchmark_results.json +0 -27
- package/core/.specialist/tools/jev-optional-context.js +0 -107
- package/core/.specialist/tools/jev-optional-context.test.js +0 -152
- package/core/.specialist/tools/memory-action-log.js +0 -839
- package/core/.specialist/tools/phase-gate.js +0 -3534
- package/core/.specialist/tools/phase-gate.test.js +0 -85
- package/core/.specialist/tools/precompute-runner.js +0 -444
- package/core/.specialist/tools/rule-engine.js +0 -621
- package/core/.specialist/tools/task-bridge-jev.test.js +0 -170
- package/core/.synapse/memory-shared.json.sync +0 -1
- package/core/.system/agent-skills/README.md +0 -724
- package/core/.system/cli-tools/README.md +0 -724
- package/core/.system/cortex/MODULES.md +0 -1046
- package/core/.system/dashboard/FRONTEND.md +0 -812
- package/core/.system/dashboard/README.md +0 -737
- package/core/.system/failure/README.md +0 -723
- package/core/.system/formation/LEGACY_SKILLS.md +0 -974
- package/core/.system/formation/POST_COMPLETE.md +0 -602
- package/core/.system/formation/README.md +0 -1094
- package/core/.system/formation/TOOLS_REFERENCE.md +0 -1145
- package/core/.system/kenaz/README.md +0 -787
- package/core/.system/memory/README.md +0 -719
- package/core/.system/pipeline/README.md +0 -712
- package/core/.system/rule/README.md +0 -794
- package/core/.system/sunny/README.md +0 -476
- package/core/.system/sunny/RULES.json +0 -89
- package/core/.system/sunny/knowledge/INDEX.md +0 -37
- package/core/.system/sunny/knowledge/agent-teams-api.md +0 -0
- package/core/.system/sunny/knowledge/ansuz-specialist.md +0 -500
- package/core/.system/sunny/knowledge/claude-cli-spawn.md +0 -177
- package/core/.system/sunny/knowledge/collaboration-api.md +0 -925
- package/core/.system/sunny/teammates/README.md +0 -107
- package/core/.system/sunny/teammates/how_to_use.yaml +0 -101
- package/core/.system/sunny/teammates/tools/headless/launcher.js +0 -318
- package/core/.system/sunny/teammates/tools/powershell/launcher.js +0 -241
- package/core/.system/sunny/teammates/tools/powershell/start.bat +0 -50
- package/core/.system/sunny/teammates/tools/utils/env.js +0 -96
- package/core/.system/sunny/teammates/tools/utils/format-output.js +0 -329
- package/core/.system/sunny/tools.json +0 -101
- package/core/dev/scripts/cleanup-queue.js +0 -184
- package/core/dev/scripts/cleanup_queue.js +0 -86
- package/core/dev/scripts/legacy/README.md +0 -39
- package/core/dev/scripts/legacy/dev_agent_scheduler.ps1.bak +0 -536
- package/core/dev/scripts/legacy/multi_agent_scheduler.ps1.bak +0 -1978
- package/core/dev/scripts/matrix/CLI_README.md +0 -214
- package/core/dev/scripts/matrix/README.md +0 -310
- package/core/dev/scripts/matrix/package-lock.json +0 -4266
- package/core/dev/scripts/matrix/package.json +0 -55
- package/core/dev/scripts/matrix/src/abbreviations.ts +0 -295
- package/core/dev/scripts/matrix/src/cli/commands/convert.ts +0 -211
- package/core/dev/scripts/matrix/src/cli/commands/create.ts +0 -95
- package/core/dev/scripts/matrix/src/cli/commands/delete.ts +0 -102
- package/core/dev/scripts/matrix/src/cli/commands/list-tags.ts.wip +0 -140
- package/core/dev/scripts/matrix/src/cli/commands/manage-tags.ts.wip +0 -173
- package/core/dev/scripts/matrix/src/cli/commands/query.ts +0 -261
- package/core/dev/scripts/matrix/src/cli/commands/read.ts +0 -77
- package/core/dev/scripts/matrix/src/cli/commands/stats.ts.wip +0 -168
- package/core/dev/scripts/matrix/src/cli/commands/tokens.ts.wip +0 -126
- package/core/dev/scripts/matrix/src/cli/commands/update.ts +0 -147
- package/core/dev/scripts/matrix/src/cli/commands/validate.ts +0 -275
- package/core/dev/scripts/matrix/src/cli/index.ts +0 -350
- package/core/dev/scripts/matrix/src/cli/utils/file-handler.ts +0 -72
- package/core/dev/scripts/matrix/src/cli/utils/logger.ts +0 -65
- package/core/dev/scripts/matrix/src/index.ts +0 -62
- package/core/dev/scripts/matrix/src/indexer/tag-indexer.ts +0 -165
- package/core/dev/scripts/matrix/src/parser.ts +0 -281
- package/core/dev/scripts/matrix/src/serializer.ts +0 -151
- package/core/dev/scripts/matrix/src/validator.ts +0 -301
- package/core/dev/scripts/matrix/tests/abbreviations.test.ts +0 -122
- package/core/dev/scripts/matrix/tests/cli.test.ts +0 -177
- package/core/dev/scripts/matrix/tests/convert.test.ts +0 -143
- package/core/dev/scripts/matrix/tests/parser.test.ts +0 -203
- package/core/dev/scripts/matrix/tests/query.test.ts +0 -85
- package/core/dev/scripts/matrix/tests/serializer.test.ts +0 -197
- package/core/dev/scripts/matrix/tests/validate.test.ts +0 -141
- package/core/dev/scripts/matrix/tests/validator.test.ts +0 -167
- package/core/dev/scripts/matrix/tsconfig.json +0 -20
- package/core/dev/scripts/matrix/types/index.d.ts +0 -111
- package/core/dev/scripts/matrix/types/index.d.ts.map +0 -1
- package/core/dev/scripts/matrix/types/index.js +0 -8
- package/core/dev/scripts/matrix/types/index.js.map +0 -1
- package/core/dev/scripts/matrix/types/index.ts +0 -124
- package/core/dev/scripts/memory-usage-report.js +0 -152
- package/core/dev/scripts/probe/ansuz-scaffold-ablation.js +0 -579
- package/core/dev/scripts/probe/ansuz-scaffold-ablation.test.js +0 -244
- package/core/dev/scripts/probe/hook-latency-probe.js +0 -315
- package/core/dev/scripts/probe/hook-latency-probe.test.js +0 -105
- package/core/dev/scripts/probe/prediction-signal-auc.js +0 -483
- package/core/dev/scripts/probe/prediction-signal-auc.test.js +0 -200
- package/core/dev/scripts/test-pty-ws-tunnel.js +0 -229
- package/core/dev/scripts/validate_pipeline.js +0 -197
- package/core/dev/spikes/task2145-evidence-20261004/backend-log-excerpt.txt +0 -56
- package/core/dev/spikes/task2145-evidence-20261004/graph.shadow +0 -0
- package/core/dev/spikes/task2145-evidence-20261004/graph.wal +0 -0
- package/core/dev/spikes/task2145-evidence-20261004/graph_corrupt_suspect.marker +0 -1
- package/core/plugins/kenaz/commands/strategy.md +0 -141
|
@@ -1,719 +0,0 @@
|
|
|
1
|
-
> REMOVED 2026-10-11 (TASK_2411): the memory system (Synapse/Hippocampus/Cortex/Alaya recall) no longer exists in code.
|
|
2
|
-
> Kept for history only; do not follow it. Lessons now: `kenaz learn` and native memory files.
|
|
3
|
-
|
|
4
|
-
# .memory 記憶系統
|
|
5
|
-
|
|
6
|
-
## 系統概述
|
|
7
|
-
|
|
8
|
-
`.memory/` 是 Kenaz AI 專案的**智能記憶系統**,模擬人腦記憶機制,為 AI Agent 提供持久化知識儲存與檢索能力。
|
|
9
|
-
|
|
10
|
-
**設計理念**:
|
|
11
|
-
- **自動化記憶**:Agent 自動判斷什麼值得記憶,自動分類標籤
|
|
12
|
-
- **語義檢索**:透過 Kenaz Cortex 進行語義搜尋與向量檢索
|
|
13
|
-
- **雙層架構**:主記憶(跨專案)+ 專案記憶(專案專屬)
|
|
14
|
-
- **優先級繼承**:專案記憶 > 主記憶 > 系統預設
|
|
15
|
-
|
|
16
|
-
**核心功能**:
|
|
17
|
-
```
|
|
18
|
-
Agent 工作流程
|
|
19
|
-
↓
|
|
20
|
-
1. 任務開始前 → 查詢相關記憶(避免重複踩坑)
|
|
21
|
-
↓
|
|
22
|
-
2. 任務執行中 → 實時存取知識(模式、解決方案)
|
|
23
|
-
↓
|
|
24
|
-
3. 任務完成後 → 自動記錄經驗(決策、失敗、模式)
|
|
25
|
-
```
|
|
26
|
-
|
|
27
|
-
---
|
|
28
|
-
|
|
29
|
-
## 目錄結構
|
|
30
|
-
|
|
31
|
-
```
|
|
32
|
-
.memory/
|
|
33
|
-
├── README.md # 本文件
|
|
34
|
-
├── CORTEX_GUIDE.md # Cortex 系統整合指南
|
|
35
|
-
├── SECURITY_TOKEN_OPTIMIZATION.md # 安全與 Token 優化
|
|
36
|
-
│
|
|
37
|
-
├── registry.json # 記憶索引(元數據)
|
|
38
|
-
├── access.yaml # 存取控制配置
|
|
39
|
-
├── CONTEXT.md # 當前狀態摘要
|
|
40
|
-
├── COMPLETED_TASKS.json # 已完成任務記錄
|
|
41
|
-
│
|
|
42
|
-
├── decisions/ # decision 類型記憶(決策記錄)
|
|
43
|
-
├── failures/ # failure 類型記憶(失敗經驗)
|
|
44
|
-
├── patterns/ # pattern 類型記憶(可複用模式)
|
|
45
|
-
├── insights/ # insight 類型記憶(洞察理解)
|
|
46
|
-
├── contexts/ # context 類型記憶(狀態快照)
|
|
47
|
-
├── references/ # reference 類型記憶(外部資源)
|
|
48
|
-
│
|
|
49
|
-
├── logs/ # 記憶系統日誌
|
|
50
|
-
│ └── README.md
|
|
51
|
-
│
|
|
52
|
-
├── config/ # 記憶系統配置
|
|
53
|
-
│ └── memory-config.yaml
|
|
54
|
-
│
|
|
55
|
-
├── schema/ # 記憶條目 Schema
|
|
56
|
-
│ └── memory-entry.schema.json
|
|
57
|
-
│
|
|
58
|
-
└── tools/ # 記憶工具腳本
|
|
59
|
-
├── memory-tools.js # CRUD 工具(add, get, search, list, update, delete)
|
|
60
|
-
├── memory-agent.js # 自動記憶 Agent(on-task-completed, should-remember)
|
|
61
|
-
├── README.md # 工具使用指南
|
|
62
|
-
├── MEMORY_AGENT_README.md # 自動記憶機制說明
|
|
63
|
-
├── LEARNING_MECHANISM.md # 學習機制設計
|
|
64
|
-
└── prompts/ # Agent 使用的 Prompt 模板
|
|
65
|
-
└── auto-classify.prompt.md
|
|
66
|
-
```
|
|
67
|
-
|
|
68
|
-
---
|
|
69
|
-
|
|
70
|
-
## 雙層記憶架構
|
|
71
|
-
|
|
72
|
-
### 系統架構圖
|
|
73
|
-
|
|
74
|
-
```
|
|
75
|
-
┌─────────────────────────────────────────────────────────────────┐
|
|
76
|
-
│ Cortex 系統 │
|
|
77
|
-
│ │
|
|
78
|
-
│ ┌──────────────┐ ┌──────────────┐ ┌──────────────┐ │
|
|
79
|
-
│ │ 記憶中心 │ │ 檢索引擎 │ │ 規則層 │ │
|
|
80
|
-
│ │ (.memory/) │ │(kenaz-cortex)│ │ (.rule/) │ │
|
|
81
|
-
│ │ │ │ │ │ │ │
|
|
82
|
-
│ │ • 經驗儲存 │ │ • 語義搜尋 │ │ • 強制約束 │ │
|
|
83
|
-
│ │ • 模式學習 │ │ • 向量檢索 │ │ • 行為規範 │ │
|
|
84
|
-
│ │ • 失敗記錄 │ │ • 混合排序 │ │ • 優先級 │ │
|
|
85
|
-
│ └──────────────┘ └──────────────┘ └──────────────┘ │
|
|
86
|
-
│ │
|
|
87
|
-
│ ┌──────────────────────────────────────────────────────────┐ │
|
|
88
|
-
│ │ 主記憶 (.kenaz/main-memory/) │ │
|
|
89
|
-
│ │ 開發者維護 • 全局知識庫 • 唯讀繼承 │ │
|
|
90
|
-
│ └──────────────────────────────────────────────────────────┘ │
|
|
91
|
-
└─────────────────────────────────────────────────────────────────┘
|
|
92
|
-
```
|
|
93
|
-
|
|
94
|
-
### 雙層架構定義
|
|
95
|
-
|
|
96
|
-
| 層級 | 位置 | 性質 | 內容 | 維護方式 |
|
|
97
|
-
|------|------|------|------|---------|
|
|
98
|
-
| **主記憶** | `.kenaz/main-memory/` | 唯讀、全局 | Kenaz 系統知識、通用最佳實踐 | 開發者手動更新 |
|
|
99
|
-
| **專案記憶** | `.memory/` | 讀寫、專案專屬 | 決策、失敗經驗、模式、洞察 | Agent 自動生成 + 開發者審查 |
|
|
100
|
-
|
|
101
|
-
### 優先級繼承機制
|
|
102
|
-
|
|
103
|
-
查詢記憶時遵循以下優先級:
|
|
104
|
-
|
|
105
|
-
```
|
|
106
|
-
1. 專案記憶 (.memory/) ← 當前專案專屬,最高優先級
|
|
107
|
-
↓ 專案規則覆蓋主記憶
|
|
108
|
-
2. 主記憶 (.kenaz/main-memory/) ← 跨專案共享,中等優先級
|
|
109
|
-
↓ 主記憶覆蓋系統預設
|
|
110
|
-
3. 系統預設 (Claude Code 內建) ← 全局,最低優先級
|
|
111
|
-
```
|
|
112
|
-
|
|
113
|
-
**規則**:優先級高的記憶會覆蓋優先級低的記憶。
|
|
114
|
-
|
|
115
|
-
**範例**:
|
|
116
|
-
```yaml
|
|
117
|
-
# 主記憶:通用 JSON BOM 問題解決方案
|
|
118
|
-
K-SOL-001: "使用 fix_json.js 修復 JSON BOM 問題"
|
|
119
|
-
|
|
120
|
-
# 專案記憶:專案特定的處理方式
|
|
121
|
-
MEM-2026-0211-003: "本專案統一使用 PowerShell 腳本處理 BOM"
|
|
122
|
-
↓
|
|
123
|
-
# 查詢結果:專案記憶優先(專案有特定流程)
|
|
124
|
-
```
|
|
125
|
-
|
|
126
|
-
---
|
|
127
|
-
|
|
128
|
-
## 記憶類型
|
|
129
|
-
|
|
130
|
-
### 類型定義
|
|
131
|
-
|
|
132
|
-
| 類型 | 說明 | 觸發場景 | 範例 |
|
|
133
|
-
|------|------|---------|------|
|
|
134
|
-
| **decision** | 決策記錄 | 架構選型、技術決策、權衡取捨 | 選擇 React 而非 Vue 的原因 |
|
|
135
|
-
| **failure** | 失敗經驗 | Bug、錯誤、踩坑經歷 | FAIL-003: TASK_QUEUE 污染問題 |
|
|
136
|
-
| **pattern** | 可複用模式 | 程式碼片段、流程範本、最佳實踐 | Team 調用的標準流程 |
|
|
137
|
-
| **insight** | 洞察理解 | 對系統的新認識、發現 | Cortex V2 的 4 層檢索架構 |
|
|
138
|
-
| **context** | 狀態快照 | 專案當前進度、重要狀態 | 專案當前有 88 個已完成任務 |
|
|
139
|
-
| **reference** | 外部資源 | 文檔連結、API 參考 | Supabase RLS 文檔連結 |
|
|
140
|
-
|
|
141
|
-
### 記憶條目結構
|
|
142
|
-
|
|
143
|
-
```yaml
|
|
144
|
-
# 記憶條目標準格式(存儲於 .memory/<type>/MEM-YYYY-MMDD-NNN.json)
|
|
145
|
-
memory_entry:
|
|
146
|
-
# ========== 基本識別 ==========
|
|
147
|
-
id: "MEM-2026-0211-001" # 唯一 ID
|
|
148
|
-
version: 1 # 版本號(支援更新)
|
|
149
|
-
type: "decision" # 記憶類型
|
|
150
|
-
|
|
151
|
-
# ========== 適用範圍 ==========
|
|
152
|
-
scope:
|
|
153
|
-
level: "feature" # project | feature | task | session
|
|
154
|
-
project_id: "kenaz-ai"
|
|
155
|
-
feature_id: "F-009"
|
|
156
|
-
task_id: "TASK_153"
|
|
157
|
-
|
|
158
|
-
# ========== 創建者資訊 ==========
|
|
159
|
-
actor:
|
|
160
|
-
agent_type: "strategy" # 創建的 Agent 類型
|
|
161
|
-
formation: "squad" # 所屬陣型
|
|
162
|
-
session_id: "sess_abc123"
|
|
163
|
-
|
|
164
|
-
# ========== 時間軸 ==========
|
|
165
|
-
temporal:
|
|
166
|
-
created_at: "2026-02-11T10:30:00Z"
|
|
167
|
-
updated_at: "2026-02-11T10:30:00Z"
|
|
168
|
-
last_accessed: "2026-02-11T12:00:00Z"
|
|
169
|
-
access_count: 5
|
|
170
|
-
|
|
171
|
-
# ========== 重要性評分 ==========
|
|
172
|
-
scoring:
|
|
173
|
-
importance: 4 # 1-5,Agent 評估
|
|
174
|
-
confidence: 0.85 # 0-1,正確性信心度
|
|
175
|
-
|
|
176
|
-
# ========== 關聯性 ==========
|
|
177
|
-
relations:
|
|
178
|
-
- target_id: "MEM-2026-0210-005"
|
|
179
|
-
relation_type: "extends" # extends | contradicts | supports | replaces
|
|
180
|
-
confidence: 0.9
|
|
181
|
-
|
|
182
|
-
# ========== 語義標籤 ==========
|
|
183
|
-
tags: ["architecture", "formation-system", "performance"]
|
|
184
|
-
|
|
185
|
-
# ========== 實際內容 ==========
|
|
186
|
-
content:
|
|
187
|
-
title: "Formation 系統採用多陣型模式的原因"
|
|
188
|
-
summary: "選擇 unit/solo/squad/legion 四種陣型而非單一模式..."
|
|
189
|
-
full: |
|
|
190
|
-
## 決策背景
|
|
191
|
-
在設計 Formation 系統時,考慮了多種協作模式...
|
|
192
|
-
|
|
193
|
-
# ========== 向量嵌入(Cortex 使用) ==========
|
|
194
|
-
embedding:
|
|
195
|
-
model: "text-embedding-3-small"
|
|
196
|
-
vector: [0.123, -0.456, ...]
|
|
197
|
-
|
|
198
|
-
# ========== 元數據 ==========
|
|
199
|
-
meta:
|
|
200
|
-
source_file: ".formation/solo/strategy.yaml"
|
|
201
|
-
git_commit: "abc123"
|
|
202
|
-
checksum: "sha256:..."
|
|
203
|
-
```
|
|
204
|
-
|
|
205
|
-
---
|
|
206
|
-
|
|
207
|
-
## Agent 使用指南
|
|
208
|
-
|
|
209
|
-
### 核心規則:AGT-001
|
|
210
|
-
|
|
211
|
-
**遵循 AGT-001 規則:記憶點優先**(定義於 `.rule/general/agent-workflow.yaml`)
|
|
212
|
-
|
|
213
|
-
> **任務開始前必須檢查 .memory/ 是否有相關記憶,避免重複做已經做過的事。**
|
|
214
|
-
|
|
215
|
-
### 使用場景
|
|
216
|
-
|
|
217
|
-
#### 1. 任務開始前(查詢記憶)
|
|
218
|
-
|
|
219
|
-
**必須執行**:檢查相關記憶,避免重複錯誤
|
|
220
|
-
|
|
221
|
-
```bash
|
|
222
|
-
# 方法 1:語義搜尋(推薦)
|
|
223
|
-
node .memory/tools/memory-tools.js search "團隊調用"
|
|
224
|
-
|
|
225
|
-
# 方法 2:按類型過濾
|
|
226
|
-
node .memory/tools/memory-tools.js search "" --type decision
|
|
227
|
-
|
|
228
|
-
# 方法 3:按重要性過濾
|
|
229
|
-
node .memory/tools/memory-tools.js search "" --minImportance 4
|
|
230
|
-
|
|
231
|
-
# 方法 4:組合搜尋
|
|
232
|
-
node .memory/tools/memory-tools.js search "架構" --type decision --minImportance 3
|
|
233
|
-
```
|
|
234
|
-
|
|
235
|
-
**輸出結果**:
|
|
236
|
-
- 匹配的記憶數量
|
|
237
|
-
- 記憶標題、摘要、重要性
|
|
238
|
-
- 相關標籤與關聯記憶
|
|
239
|
-
|
|
240
|
-
**範例輸出**:
|
|
241
|
-
```
|
|
242
|
-
Found 3 memories matching "團隊調用":
|
|
243
|
-
|
|
244
|
-
1. MEM-2026-0211-005 (decision) - Importance: 4
|
|
245
|
-
Title: "Team 調用標準流程"
|
|
246
|
-
Summary: "使用 run-team.js --team=X --task=Y 調用 Team..."
|
|
247
|
-
Tags: team, workflow, formation
|
|
248
|
-
|
|
249
|
-
2. MEM-2026-0210-012 (pattern) - Importance: 3
|
|
250
|
-
Title: "Leader-Worker 協作模式"
|
|
251
|
-
Summary: "Leader 負責協調,Worker 獨立執行任務..."
|
|
252
|
-
Tags: pattern, team, architecture
|
|
253
|
-
```
|
|
254
|
-
|
|
255
|
-
#### 2. 任務執行中(存取記憶)
|
|
256
|
-
|
|
257
|
-
```bash
|
|
258
|
-
# 獲取特定記憶的完整內容
|
|
259
|
-
node .memory/tools/memory-tools.js get MEM-2026-0211-001
|
|
260
|
-
|
|
261
|
-
# 列出所有記憶
|
|
262
|
-
node .memory/tools/memory-tools.js list
|
|
263
|
-
|
|
264
|
-
# 列出特定類型的記憶
|
|
265
|
-
node .memory/tools/memory-tools.js list --type failure
|
|
266
|
-
```
|
|
267
|
-
|
|
268
|
-
#### 3. 任務完成後(記錄記憶)
|
|
269
|
-
|
|
270
|
-
**自動記憶觸發**(由 Formation 系統自動調用):
|
|
271
|
-
|
|
272
|
-
```bash
|
|
273
|
-
# 任務完成時自動評估是否需要記憶
|
|
274
|
-
node .memory/tools/memory-agent.js on-task-completed \
|
|
275
|
-
--task-id TASK_158 \
|
|
276
|
-
--summary "記憶系統基礎架構完成"
|
|
277
|
-
```
|
|
278
|
-
|
|
279
|
-
**手動記憶操作**(Agent 或開發者):
|
|
280
|
-
|
|
281
|
-
```bash
|
|
282
|
-
# 記錄決策
|
|
283
|
-
node .memory/tools/memory-tools.js add \
|
|
284
|
-
--type decision \
|
|
285
|
-
--title "選擇 React 框架" \
|
|
286
|
-
--summary "因為生態系成熟、團隊熟悉度高" \
|
|
287
|
-
--importance 4 \
|
|
288
|
-
--tags "frontend,architecture"
|
|
289
|
-
|
|
290
|
-
# 記錄失敗經驗
|
|
291
|
-
node .memory/tools/memory-tools.js add \
|
|
292
|
-
--type failure \
|
|
293
|
-
--title "並行任務衝突" \
|
|
294
|
-
--summary "同時啟動兩個 Team 會覆蓋 state.json" \
|
|
295
|
-
--importance 5 \
|
|
296
|
-
--tags "pipeline,concurrency"
|
|
297
|
-
|
|
298
|
-
# 記錄可複用模式
|
|
299
|
-
node .memory/tools/memory-tools.js add \
|
|
300
|
-
--type pattern \
|
|
301
|
-
--title "Team 調用標準流程" \
|
|
302
|
-
--summary "使用 run-team.js --team=X --task=Y" \
|
|
303
|
-
--importance 3 \
|
|
304
|
-
--tags "team,workflow"
|
|
305
|
-
```
|
|
306
|
-
|
|
307
|
-
#### 4. 更新記憶
|
|
308
|
-
|
|
309
|
-
```bash
|
|
310
|
-
# 更新記憶內容
|
|
311
|
-
node .memory/tools/memory-tools.js update MEM-2026-0211-001 \
|
|
312
|
-
--title "新標題" \
|
|
313
|
-
--importance 5 \
|
|
314
|
-
--tags "new,tags"
|
|
315
|
-
```
|
|
316
|
-
|
|
317
|
-
#### 5. 刪除記憶
|
|
318
|
-
|
|
319
|
-
```bash
|
|
320
|
-
# 刪除記憶(慎用)
|
|
321
|
-
node .memory/tools/memory-tools.js delete MEM-2026-0211-001
|
|
322
|
-
```
|
|
323
|
-
|
|
324
|
-
---
|
|
325
|
-
|
|
326
|
-
## Cortex 檢索層級
|
|
327
|
-
|
|
328
|
-
Agent 查詢時,Cortex 按以下層級處理:
|
|
329
|
-
|
|
330
|
-
```
|
|
331
|
-
Agent 查詢 Cortex
|
|
332
|
-
↓
|
|
333
|
-
Layer 1: 規則層(.rule/, CLAUDE.md, .failure/)
|
|
334
|
-
↓
|
|
335
|
-
Layer 1.5: 記憶層(.memory/)← 自動載入高重要性記憶
|
|
336
|
-
↓
|
|
337
|
-
Layer 2-4: 架構層、智能檢索層、全局驗證層
|
|
338
|
-
```
|
|
339
|
-
|
|
340
|
-
### 智能載入策略
|
|
341
|
-
|
|
342
|
-
**根據任務類型動態調整載入深度:**
|
|
343
|
-
|
|
344
|
-
| 任務類型 | 載入記憶數 | 載入字段 | Max Tokens |
|
|
345
|
-
|---------|-----------|---------|------------|
|
|
346
|
-
| **簡單任務** | 5 | title, summary | 500 |
|
|
347
|
-
| **P2/P3 任務** | 10 | title, summary, tags | 1000 |
|
|
348
|
-
| **P0/P1 任務** | 15-20 | title, summary, full, relations | 2000 |
|
|
349
|
-
|
|
350
|
-
**混合排序策略**:
|
|
351
|
-
|
|
352
|
-
```python
|
|
353
|
-
score = relevance * 0.5 + recency * 0.2 + importance * 0.3
|
|
354
|
-
```
|
|
355
|
-
|
|
356
|
-
- **relevance**: 語義相似度(向量距離)
|
|
357
|
-
- **recency**: 時間衰減(70 天半衰期)
|
|
358
|
-
- **importance**: 重要性分數(1-5)
|
|
359
|
-
|
|
360
|
-
---
|
|
361
|
-
|
|
362
|
-
## 重要性評分指南
|
|
363
|
-
|
|
364
|
-
### 評分標準
|
|
365
|
-
|
|
366
|
-
| 分數 | 說明 | 適用場景 |
|
|
367
|
-
|------|------|---------|
|
|
368
|
-
| **5** | 極重要 | 架構決策、核心原則、關鍵失敗 |
|
|
369
|
-
| **4** | 很重要 | 功能設計、重要模式、嚴重問題 |
|
|
370
|
-
| **3** | 中等 | 一般決策、常用模式、中等問題 |
|
|
371
|
-
| **2** | 較低 | 小優化、輔助資訊、小問題 |
|
|
372
|
-
| **1** | 最低 | 臨時筆記、瑣碎資訊 |
|
|
373
|
-
|
|
374
|
-
### 自動評估機制
|
|
375
|
-
|
|
376
|
-
```javascript
|
|
377
|
-
// .memory/tools/memory-agent.js
|
|
378
|
-
|
|
379
|
-
function calculateImportance(event) {
|
|
380
|
-
let score = 3; // 預設中等
|
|
381
|
-
|
|
382
|
-
// 規則 1:失敗必記(+2)
|
|
383
|
-
if (event.type === 'failure') score += 2;
|
|
384
|
-
|
|
385
|
-
// 規則 2:架構決策(+2)
|
|
386
|
-
if (event.type === 'decision' && event.scope.level === 'project') score += 2;
|
|
387
|
-
|
|
388
|
-
// 規則 3:可複用模式(+1)
|
|
389
|
-
if (event.type === 'pattern' && event.reuse_count > 1) score += 1;
|
|
390
|
-
|
|
391
|
-
// 規則 4:影響範圍(+1)
|
|
392
|
-
if (event.scope.level === 'global') score += 1;
|
|
393
|
-
|
|
394
|
-
return Math.min(5, score); // 限制最大值 5
|
|
395
|
-
}
|
|
396
|
-
```
|
|
397
|
-
|
|
398
|
-
---
|
|
399
|
-
|
|
400
|
-
## 安全性
|
|
401
|
-
|
|
402
|
-
### 敏感資訊過濾
|
|
403
|
-
|
|
404
|
-
寫入記憶時自動過濾敏感資訊:
|
|
405
|
-
|
|
406
|
-
```javascript
|
|
407
|
-
// .memory/tools/security-filter.js
|
|
408
|
-
|
|
409
|
-
const patterns = [
|
|
410
|
-
/sk-[a-zA-Z0-9]{48}/g, // OpenAI API Key
|
|
411
|
-
/password\s*[=:]\s*\S+/gi, // 密碼
|
|
412
|
-
/token\s*[=:]\s*[a-zA-Z0-9]+/gi, // Token
|
|
413
|
-
/supabase.*key.*anon/gi, // Supabase Anon Key
|
|
414
|
-
];
|
|
415
|
-
|
|
416
|
-
function filterSensitive(content) {
|
|
417
|
-
let filtered = content;
|
|
418
|
-
for (const pattern of patterns) {
|
|
419
|
-
filtered = filtered.replace(pattern, '[REDACTED]');
|
|
420
|
-
}
|
|
421
|
-
return filtered;
|
|
422
|
-
}
|
|
423
|
-
```
|
|
424
|
-
|
|
425
|
-
### 專案隔離
|
|
426
|
-
|
|
427
|
-
- 每個專案使用獨立的記憶系統(`.memory/` 目錄)
|
|
428
|
-
- Cortex 使用專案 hash 作為 Collection 名稱
|
|
429
|
-
- 專案 A 的記憶在專案 B 中不可見
|
|
430
|
-
|
|
431
|
-
### 存取控制
|
|
432
|
-
|
|
433
|
-
```yaml
|
|
434
|
-
# .memory/access.yaml
|
|
435
|
-
|
|
436
|
-
access_control:
|
|
437
|
-
read:
|
|
438
|
-
- all_agents # 所有 Agent 可讀取
|
|
439
|
-
- human_developers # 所有開發者可讀取
|
|
440
|
-
write:
|
|
441
|
-
- agents: # Agent 可自動寫入
|
|
442
|
-
- strategy
|
|
443
|
-
- developer
|
|
444
|
-
- backend
|
|
445
|
-
- formation_lead
|
|
446
|
-
- human_developers # 開發者手動寫入
|
|
447
|
-
delete:
|
|
448
|
-
- human_developers # 僅開發者可刪除
|
|
449
|
-
```
|
|
450
|
-
|
|
451
|
-
---
|
|
452
|
-
|
|
453
|
-
## Token 優化策略
|
|
454
|
-
|
|
455
|
-
### 智能裁剪
|
|
456
|
-
|
|
457
|
-
根據任務優先級動態調整:
|
|
458
|
-
|
|
459
|
-
```yaml
|
|
460
|
-
# P0/P1 任務(高優先級)
|
|
461
|
-
high_priority:
|
|
462
|
-
max_memories: 20
|
|
463
|
-
fields: [title, summary, full, relations]
|
|
464
|
-
max_tokens_per_memory: 150
|
|
465
|
-
total_max_tokens: 2000
|
|
466
|
-
|
|
467
|
-
# P2/P3 任務(中優先級)
|
|
468
|
-
medium_priority:
|
|
469
|
-
max_memories: 10
|
|
470
|
-
fields: [title, summary]
|
|
471
|
-
max_tokens_per_memory: 80
|
|
472
|
-
total_max_tokens: 1000
|
|
473
|
-
|
|
474
|
-
# 簡單任務(低優先級)
|
|
475
|
-
low_priority:
|
|
476
|
-
max_memories: 5
|
|
477
|
-
fields: [title, summary]
|
|
478
|
-
max_tokens_per_memory: 50
|
|
479
|
-
total_max_tokens: 500
|
|
480
|
-
```
|
|
481
|
-
|
|
482
|
-
### Session 快取
|
|
483
|
-
|
|
484
|
-
```javascript
|
|
485
|
-
// 同一 session 內避免重複查詢
|
|
486
|
-
const cache = new Map();
|
|
487
|
-
|
|
488
|
-
function getCachedMemory(query) {
|
|
489
|
-
const cacheKey = hash(query);
|
|
490
|
-
if (cache.has(cacheKey)) {
|
|
491
|
-
return cache.get(cacheKey);
|
|
492
|
-
}
|
|
493
|
-
const result = queryMemory(query);
|
|
494
|
-
cache.set(cacheKey, result);
|
|
495
|
-
return result;
|
|
496
|
-
}
|
|
497
|
-
```
|
|
498
|
-
|
|
499
|
-
詳細優化策略參考:`.memory/SECURITY_TOKEN_OPTIMIZATION.md`
|
|
500
|
-
|
|
501
|
-
---
|
|
502
|
-
|
|
503
|
-
## 與其他系統的關係
|
|
504
|
-
|
|
505
|
-
### 優先級順序
|
|
506
|
-
|
|
507
|
-
```
|
|
508
|
-
1. .rule/ (最高優先級 - 必須遵守的規則)
|
|
509
|
-
2. .failure/ (失敗經驗 - 應避免的模式)
|
|
510
|
-
3. .memory/ (經驗記錄 - 參考學習)
|
|
511
|
-
4. CLAUDE.md (專案指導 - 工作流程)
|
|
512
|
-
```
|
|
513
|
-
|
|
514
|
-
### 與 .failure/ 的關係
|
|
515
|
-
|
|
516
|
-
- `.failure/` 是傳統的失敗記錄系統(YAML 格式)
|
|
517
|
-
- `.memory/failures/` 整合了 `.failure/` 的內容(JSON 格式)
|
|
518
|
-
- 新的失敗經驗優先記錄到 `.memory/failures/`
|
|
519
|
-
- 兩個系統可以共存,Cortex 同時索引兩處
|
|
520
|
-
|
|
521
|
-
**遷移方向**:
|
|
522
|
-
```
|
|
523
|
-
.failure/ (YAML) → .memory/failures/ (JSON + Cortex 索引)
|
|
524
|
-
```
|
|
525
|
-
|
|
526
|
-
### 與 kenaz-cortex 的關係
|
|
527
|
-
|
|
528
|
-
- 記憶系統作為 **Layer 1.5** 整合到 Cortex
|
|
529
|
-
- 使用 ChromaDB 進行向量存儲
|
|
530
|
-
- 支持語義檢索和混合排名
|
|
531
|
-
|
|
532
|
-
**整合架構**:
|
|
533
|
-
```
|
|
534
|
-
Cortex 檢索引擎
|
|
535
|
-
↓
|
|
536
|
-
Layer 1.5: 記憶層 (.memory/)
|
|
537
|
-
↓
|
|
538
|
-
ChromaDB 向量資料庫
|
|
539
|
-
```
|
|
540
|
-
|
|
541
|
-
---
|
|
542
|
-
|
|
543
|
-
## 工作流程整合
|
|
544
|
-
|
|
545
|
-
### Agent 執行前(查詢記憶)
|
|
546
|
-
|
|
547
|
-
```bash
|
|
548
|
-
# 查詢失敗經驗(避免重複錯誤)
|
|
549
|
-
node .memory/tools/memory-tools.js search \
|
|
550
|
-
--query="與任務相關的失敗" \
|
|
551
|
-
--type=failure \
|
|
552
|
-
--limit=5
|
|
553
|
-
|
|
554
|
-
# 查詢成功模式(參考有效方法)
|
|
555
|
-
node .memory/tools/memory-tools.js search \
|
|
556
|
-
--query="任務關鍵詞" \
|
|
557
|
-
--type=pattern \
|
|
558
|
-
--limit=5
|
|
559
|
-
```
|
|
560
|
-
|
|
561
|
-
### Agent 執行完成後(自動記憶)
|
|
562
|
-
|
|
563
|
-
```javascript
|
|
564
|
-
// Formation 系統自動調用
|
|
565
|
-
node .memory/tools/memory-agent.js on-task-completed \
|
|
566
|
-
--task-id TASK_158 \
|
|
567
|
-
--summary "記憶系統基礎架構完成"
|
|
568
|
-
|
|
569
|
-
// 自動判斷:
|
|
570
|
-
// - 成功 → 記錄為 pattern 類型
|
|
571
|
-
// - 失敗 → 記錄為 failure 類型
|
|
572
|
-
// - 決策 → 記錄為 decision 類型
|
|
573
|
-
```
|
|
574
|
-
|
|
575
|
-
### 定期維護(每週)
|
|
576
|
-
|
|
577
|
-
```bash
|
|
578
|
-
# 檢視所有記憶
|
|
579
|
-
node .memory/tools/memory-tools.js list --limit=100
|
|
580
|
-
|
|
581
|
-
# 清理過時記憶(手動評估)
|
|
582
|
-
node .memory/tools/memory-tools.js search "" --minImportance 1 | \
|
|
583
|
-
grep "2025" | \
|
|
584
|
-
# 檢視後決定是否刪除
|
|
585
|
-
```
|
|
586
|
-
|
|
587
|
-
---
|
|
588
|
-
|
|
589
|
-
## 常見問題(FAQ)
|
|
590
|
-
|
|
591
|
-
### Q1: 記憶會自動刪除嗎?
|
|
592
|
-
|
|
593
|
-
**A**: 不會。所有記憶永久保留,需手動管理。建議定期檢視低重要性記憶(importance < 2)並決定是否刪除。
|
|
594
|
-
|
|
595
|
-
### Q2: 如何避免記憶爆炸?
|
|
596
|
-
|
|
597
|
-
**A**: 透過以下機制控制:
|
|
598
|
-
1. **智能裁剪**:只載入相關記憶(混合排序 top-K)
|
|
599
|
-
2. **重要性評分**:低重要性記憶不會被 Cortex 優先載入
|
|
600
|
-
3. **Token 限制**:動態調整載入深度(簡單任務 500 tokens,複雜任務 2000 tokens)
|
|
601
|
-
|
|
602
|
-
### Q3: 專案記憶和主記憶有什麼區別?
|
|
603
|
-
|
|
604
|
-
**A**:
|
|
605
|
-
- **專案記憶** (`.memory/`):專案專屬,Agent 自動生成,讀寫
|
|
606
|
-
- **主記憶** (`.kenaz/main-memory/`):跨專案共享,開發者維護,唯讀
|
|
607
|
-
|
|
608
|
-
查詢時專案記憶優先。
|
|
609
|
-
|
|
610
|
-
### Q4: 如何更新主記憶?
|
|
611
|
-
|
|
612
|
-
**A**: 主記憶僅開發者手動更新:
|
|
613
|
-
1. 在 `.kenaz/main-memory/` 對應目錄建立 Markdown 文件
|
|
614
|
-
2. 更新 `registry.json` 新增索引條目
|
|
615
|
-
3. 更新 `version.yaml` 記錄變更
|
|
616
|
-
4. 建立 Git commit
|
|
617
|
-
|
|
618
|
-
### Q5: 記憶工具不存在怎麼辦?
|
|
619
|
-
|
|
620
|
-
**A**:
|
|
621
|
-
```bash
|
|
622
|
-
# 檢查記憶工具
|
|
623
|
-
ls .memory/tools/
|
|
624
|
-
|
|
625
|
-
# 如果不存在,參考 docs/specs/MEMORY_SYSTEM_SPEC.md 建立基礎架構
|
|
626
|
-
```
|
|
627
|
-
|
|
628
|
-
---
|
|
629
|
-
|
|
630
|
-
## 故障排查
|
|
631
|
-
|
|
632
|
-
### 記憶工具不存在
|
|
633
|
-
|
|
634
|
-
```bash
|
|
635
|
-
# 檢查記憶工具
|
|
636
|
-
ls .memory/tools/
|
|
637
|
-
|
|
638
|
-
# 如果不存在,執行 TASK_158 建立基礎架構
|
|
639
|
-
```
|
|
640
|
-
|
|
641
|
-
### 查詢無結果
|
|
642
|
-
|
|
643
|
-
```bash
|
|
644
|
-
# 檢查 registry.json
|
|
645
|
-
cat .memory/registry.json
|
|
646
|
-
|
|
647
|
-
# 確認記憶已被索引
|
|
648
|
-
node .memory/tools/memory-tools.js list --limit=100
|
|
649
|
-
```
|
|
650
|
-
|
|
651
|
-
### Cortex 整合問題
|
|
652
|
-
|
|
653
|
-
```bash
|
|
654
|
-
# 檢查 Cortex 狀態
|
|
655
|
-
python kenaz-cortex/src/cortex/api/status.py
|
|
656
|
-
|
|
657
|
-
# 重新索引記憶
|
|
658
|
-
python kenaz-cortex/src/cortex/retrieval/memory_layer.py --reindex
|
|
659
|
-
```
|
|
660
|
-
|
|
661
|
-
---
|
|
662
|
-
|
|
663
|
-
## 最佳實踐
|
|
664
|
-
|
|
665
|
-
1. **定期記錄決策** - 重要的技術決策應立即記錄
|
|
666
|
-
2. **失敗必記** - 所有失敗經驗都值得記憶(AGT-005)
|
|
667
|
-
3. **避免過度記憶** - 只記錄有價值的信息(importance >= 3)
|
|
668
|
-
4. **定期清理** - 刪除過時或不再相關的記憶
|
|
669
|
-
5. **善用標籤** - 使用一致的標籤系統便於查詢
|
|
670
|
-
6. **記憶點優先** - 任務開始前必須查詢記憶(AGT-001)
|
|
671
|
-
|
|
672
|
-
---
|
|
673
|
-
|
|
674
|
-
## 相關文檔
|
|
675
|
-
|
|
676
|
-
| 文檔 | 路徑 | 說明 |
|
|
677
|
-
|------|------|------|
|
|
678
|
-
| **Cortex 整合指南** | `.memory/CORTEX_GUIDE.md` | Cortex 系統架構與使用方式 |
|
|
679
|
-
| **記憶工具使用指南** | `.memory/tools/README.md` | CRUD 工具詳細使用說明 |
|
|
680
|
-
| **自動記憶機制** | `.memory/tools/MEMORY_AGENT_README.md` | 自動記憶觸發與評估機制 |
|
|
681
|
-
| **安全與優化** | `.memory/SECURITY_TOKEN_OPTIMIZATION.md` | 安全過濾與 Token 優化策略 |
|
|
682
|
-
| **完整規格** | `docs/specs/MEMORY_SYSTEM_SPEC.md` | 記憶系統完整需求規格 |
|
|
683
|
-
| **主記憶說明** | `.kenaz/main-memory/README.md` | 主記憶系統架構與使用 |
|
|
684
|
-
| **規則系統** | `.system/rule/README.md` | 規則優先級與 AGT-001 規則 |
|
|
685
|
-
| **失敗學習系統** | `.system/failure/README.md` | 失敗經驗與 .failure/ 關係 |
|
|
686
|
-
|
|
687
|
-
---
|
|
688
|
-
|
|
689
|
-
## 統計數據(截至 2026-02-19)
|
|
690
|
-
|
|
691
|
-
```yaml
|
|
692
|
-
# 專案記憶統計
|
|
693
|
-
project_memory:
|
|
694
|
-
total_memories: 12
|
|
695
|
-
by_type:
|
|
696
|
-
decision: 3
|
|
697
|
-
failure: 5
|
|
698
|
-
pattern: 2
|
|
699
|
-
insight: 1
|
|
700
|
-
context: 1
|
|
701
|
-
reference: 0
|
|
702
|
-
by_importance:
|
|
703
|
-
5: 2 # 極重要
|
|
704
|
-
4: 4 # 很重要
|
|
705
|
-
3: 4 # 中等
|
|
706
|
-
2: 1 # 較低
|
|
707
|
-
1: 1 # 最低
|
|
708
|
-
total_access_count: 48
|
|
709
|
-
|
|
710
|
-
# 主記憶統計(來自 .kenaz/main-memory/)
|
|
711
|
-
main_memory:
|
|
712
|
-
total_memories: 26
|
|
713
|
-
knowledge: 8 # 通用知識
|
|
714
|
-
kenaz: 18 # 系統專屬知識
|
|
715
|
-
```
|
|
716
|
-
|
|
717
|
-
---
|
|
718
|
-
|
|
719
|
-
*建立日期: 2026-02-19 | 更新: 2026-02-19*
|