kenaz 0.3.3 → 0.3.5
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/.agents/skills/typesafe-ai/LICENSE +21 -21
- package/core/.agents/skills/typesafe-ai/SKILL.md +149 -149
- package/core/.claude/commands/Ansuz.md +14 -2
- package/core/.claude/hooks/__tests__/task-2395-project-registration.test.js +84 -0
- package/core/.claude/hooks/handoff-staleness.js +2 -2
- package/core/.claude/hooks/session-init.ps1 +49 -49
- package/core/.claude/hooks/turn-context.js +50 -2
- package/core/.claude/skills/ui-ux-pro-max/data/charts.csv +26 -26
- package/core/.claude/skills/ui-ux-pro-max/data/colors.csv +97 -97
- package/core/.claude/skills/ui-ux-pro-max/data/icons.csv +101 -101
- package/core/.claude/skills/ui-ux-pro-max/data/landing.csv +31 -31
- package/core/.claude/skills/ui-ux-pro-max/data/products.csv +96 -96
- package/core/.claude/skills/ui-ux-pro-max/data/react-performance.csv +45 -45
- package/core/.claude/skills/ui-ux-pro-max/data/stacks/astro.csv +54 -54
- package/core/.claude/skills/ui-ux-pro-max/data/stacks/flutter.csv +53 -53
- package/core/.claude/skills/ui-ux-pro-max/data/stacks/html-tailwind.csv +56 -56
- package/core/.claude/skills/ui-ux-pro-max/data/stacks/jetpack-compose.csv +53 -53
- package/core/.claude/skills/ui-ux-pro-max/data/stacks/nextjs.csv +53 -53
- package/core/.claude/skills/ui-ux-pro-max/data/stacks/nuxt-ui.csv +51 -51
- package/core/.claude/skills/ui-ux-pro-max/data/stacks/nuxtjs.csv +59 -59
- package/core/.claude/skills/ui-ux-pro-max/data/stacks/react-native.csv +52 -52
- package/core/.claude/skills/ui-ux-pro-max/data/stacks/react.csv +54 -54
- package/core/.claude/skills/ui-ux-pro-max/data/stacks/shadcn.csv +61 -61
- package/core/.claude/skills/ui-ux-pro-max/data/stacks/svelte.csv +54 -54
- package/core/.claude/skills/ui-ux-pro-max/data/stacks/swiftui.csv +51 -51
- package/core/.claude/skills/ui-ux-pro-max/data/stacks/vue.csv +50 -50
- package/core/.claude/skills/ui-ux-pro-max/data/styles.csv +68 -68
- package/core/.claude/skills/ui-ux-pro-max/data/typography.csv +57 -57
- package/core/.claude/skills/ui-ux-pro-max/data/ui-reasoning.csv +101 -101
- package/core/.claude/skills/ui-ux-pro-max/data/ux-guidelines.csv +99 -99
- package/core/.claude/skills/ui-ux-pro-max/data/web-interface.csv +31 -31
- package/core/.claude/skills/ui-ux-pro-max/scripts/core.py +253 -253
- package/core/.claude/skills/ui-ux-pro-max/scripts/design_system.py +1067 -1067
- package/core/.claude/skills/ui-ux-pro-max/scripts/search.py +106 -106
- package/core/.collaboration/core/task-api.js +1 -4
- package/core/.formation/README.md +21 -146
- package/core/.formation/bifrost/codex-doctor.js +37 -2
- package/core/.formation/bifrost/codex-doctor.test.js +18 -0
- package/core/.formation/bifrost/launch.js +1 -1
- package/core/.formation/bifrost/openai/codex-hook-shim.js +6 -0
- package/core/.formation/bifrost/openai/codex-hook-shim.test.js +11 -1
- package/core/.formation/bifrost/setup-codex.js +3 -0
- package/core/.formation/spec/task_operations.parity.test.js +0 -1
- package/core/.formation/tests/hello.txt +2 -2
- package/core/.formation/tools/dashboard-models-chain.test.js +0 -6
- package/core/.formation/tools/dispatch-detail/cross-project-worktree.md +1 -9
- package/core/.formation/tools/dispatch-detail/worktree-subagent-mode.md +2 -2
- package/core/.formation/tools/dispatch.js +28 -549
- package/core/.formation/tools/mcp-allowlist.test.js +0 -1
- package/core/.formation/tools/post-complete/task2345.test.js +0 -5
- package/core/.formation/tools/pre-dispatch-snapshot.test.js +0 -100
- package/core/.formation/tools/prompt.js +29 -1623
- package/core/.formation/tools/prompt.test.js +26 -594
- package/core/.kenaz/knowledge/ladybug_2c51da1e_shadow_file_frame_group.patch +163 -163
- package/core/.kenaz/knowledge/ladybug_30cf85690e_shadow_page_read_during_checkpoint.patch +393 -393
- package/core/.kenaz/knowledge/ladybug_7a17858d3a_node_group_delete_lock.patch +102 -102
- package/core/.kenaz/knowledge/ladybug_926a0ba1_column_checkpoint.patch +412 -412
- package/core/.kenaz/knowledge/ladybug_a346c4c4b6_pk_index_header_pages.patch +144 -144
- package/core/.kenaz/knowledge/ladybug_ba5f38815b_csr_node_group.patch +86 -86
- package/core/.kenaz/muninn_episode_write.ps1 +17 -17
- package/core/.kenaz/specialist/field_report_watermark.json +1 -1
- package/core/.kenaz/specialist/memory_guard_fired.json +1 -1
- package/core/.kenaz/specialist/memory_guard_trigger_cache.json +1 -1
- package/core/.kenaz/specialist/t1777_probe.txt +1 -1
- package/core/.matrix/index.matrix +5 -5
- package/core/.specialist/tools/__tests__/freya-cli-contract.test.js +0 -1
- package/core/KENAZ_CORE_VERSION +1 -1
- package/core/dev/ANSUZ_STARTUP_INJECTION_REVIEW.md +355 -355
- package/core/dev/JEV_INTEGRATION_PLAN.md +189 -189
- package/core/dev/design/matrix_format_EXAMPLE_memory.matrix +13 -13
- package/core/dev/design/matrix_format_EXAMPLE_project_status.matrix +9 -9
- package/core/dev/design/matrix_format_EXAMPLE_tasks.matrix +14 -14
- package/core/dev/design/matrix_v2_EXAMPLE.matrix +67 -67
- package/core/dev/jev-eval/ACTIVE_CORRECTION.md +52 -52
- package/core/dev/jev-eval/CONTEXT_REVIEW.md +31 -31
- package/core/dev/jev-eval/EVALUATION_STATUS.md +39 -39
- package/core/dev/jev-eval/HISTORICAL_CORPUS.md +33 -33
- package/core/dev/jev-eval/README.md +99 -99
- package/core/dev/jev-eval/THALAMUS_RANKING.md +58 -58
- package/core/dev/jev-eval/reports/annotation-pilot-2026-09-20.json +32 -32
- package/core/dev/jev-eval/reports/context-review-2026-09-20.json +48 -48
- package/core/dev/jev-eval/reports/history-corpus-2026-09-20.json +52 -52
- package/core/dev/pipeline/SELF_ENHANCEMENT_STATUS.json.bak +47 -47
- package/core/dev/pipeline/tasks/.gitkeep +1 -1
- package/core/dev/pipeline/test_results/TASK_TEST_PARALLEL_002_result.txt +27 -27
- package/core/dev/scripts/init_git.sh +0 -0
- package/core/dev/scripts/init_project.sh +0 -0
- package/core/dev/scripts/legacy/dev_agent_scheduler.ps1.bak +536 -536
- package/core/dev/scripts/legacy/multi_agent_scheduler.ps1.bak +1978 -1978
- package/core/dev/scripts/matrix/src/cli/commands/list-tags.ts.wip +140 -140
- package/core/dev/scripts/matrix/src/cli/commands/manage-tags.ts.wip +173 -173
- package/core/dev/scripts/matrix/src/cli/commands/stats.ts.wip +168 -168
- package/core/dev/scripts/matrix/src/cli/commands/tokens.ts.wip +126 -126
- package/core/dev/scripts/multi_agent_scheduler.sh +0 -0
- package/core/dev/scripts/run_once.sh +0 -0
- package/core/dev/scripts/setup_mcp.sh +0 -0
- package/core/dev/scripts/setup_rag.sh +0 -0
- package/core/dev/scripts/start_dev_agent.sh +0 -0
- package/core/dev/scripts/start_multi_agent.sh +0 -0
- package/core/dev/scripts/sync_task_queue.sh +0 -0
- package/core/plugins/kenaz/commands/Amelia.md +1 -1
- package/core/plugins/kenaz/commands/Ansuz.md +15 -3
- package/core/plugins/kenaz/scripts/kenaz-mode.js +11 -1
- package/core/plugins/kenaz/scripts/sync.js +6 -2
- package/core/plugins/kenaz/scripts/ygg.js +13 -1
- package/core/plugins/kenaz/skills/product_manager/SKILL.md +12 -12
- package/core/plugins/kenaz/skills/ui-ux-pro-max/data/charts.csv +26 -26
- package/core/plugins/kenaz/skills/ui-ux-pro-max/data/colors.csv +97 -97
- package/core/plugins/kenaz/skills/ui-ux-pro-max/data/icons.csv +101 -101
- package/core/plugins/kenaz/skills/ui-ux-pro-max/data/landing.csv +31 -31
- package/core/plugins/kenaz/skills/ui-ux-pro-max/data/products.csv +96 -96
- package/core/plugins/kenaz/skills/ui-ux-pro-max/data/react-performance.csv +45 -45
- package/core/plugins/kenaz/skills/ui-ux-pro-max/data/stacks/astro.csv +54 -54
- package/core/plugins/kenaz/skills/ui-ux-pro-max/data/stacks/flutter.csv +53 -53
- package/core/plugins/kenaz/skills/ui-ux-pro-max/data/stacks/html-tailwind.csv +56 -56
- package/core/plugins/kenaz/skills/ui-ux-pro-max/data/stacks/jetpack-compose.csv +53 -53
- package/core/plugins/kenaz/skills/ui-ux-pro-max/data/stacks/nextjs.csv +53 -53
- package/core/plugins/kenaz/skills/ui-ux-pro-max/data/stacks/nuxt-ui.csv +51 -51
- package/core/plugins/kenaz/skills/ui-ux-pro-max/data/stacks/nuxtjs.csv +59 -59
- package/core/plugins/kenaz/skills/ui-ux-pro-max/data/stacks/react-native.csv +52 -52
- package/core/plugins/kenaz/skills/ui-ux-pro-max/data/stacks/react.csv +54 -54
- package/core/plugins/kenaz/skills/ui-ux-pro-max/data/stacks/shadcn.csv +61 -61
- package/core/plugins/kenaz/skills/ui-ux-pro-max/data/stacks/svelte.csv +54 -54
- package/core/plugins/kenaz/skills/ui-ux-pro-max/data/stacks/swiftui.csv +51 -51
- package/core/plugins/kenaz/skills/ui-ux-pro-max/data/stacks/vue.csv +50 -50
- package/core/plugins/kenaz/skills/ui-ux-pro-max/data/styles.csv +68 -68
- package/core/plugins/kenaz/skills/ui-ux-pro-max/data/typography.csv +57 -57
- package/core/plugins/kenaz/skills/ui-ux-pro-max/data/ui-reasoning.csv +101 -101
- package/core/plugins/kenaz/skills/ui-ux-pro-max/data/ux-guidelines.csv +99 -99
- package/core/plugins/kenaz/skills/ui-ux-pro-max/data/web-interface.csv +31 -31
- package/core/plugins/kenaz/skills/ui-ux-pro-max/scripts/core.py +253 -253
- package/core/plugins/kenaz/skills/ui-ux-pro-max/scripts/design_system.py +1067 -1067
- package/core/plugins/kenaz/skills/ui-ux-pro-max/scripts/search.py +106 -106
- package/lib/cli.js +11 -4
- package/package.json +11 -7
- package/vendor/install-kenaz-cli.js +18 -7
- package/core/.formation/tools/broadcast.js +0 -103
- package/core/.formation/tools/dispatch-dryrun.test.js +0 -54
- package/core/.formation/tools/dispatch-notifier.js +0 -84
- package/core/.formation/tools/formations.js +0 -1203
- package/core/.formation/tools/headless-branch-recovery.test.js +0 -64
- package/core/.formation/tools/headless-dryrun.test.js +0 -79
- package/core/.formation/tools/headless-v2.js +0 -659
- package/core/.formation/tools/headless.js +0 -1071
- package/core/.formation/tools/legacy-scheduler.js +0 -1994
- package/core/.formation/tools/logger.js +0 -273
- package/core/.formation/tools/memory-loader.js +0 -422
- package/core/.formation/tools/process-state.js +0 -33
- package/core/.formation/tools/remote-conflict.js +0 -98
- package/core/.formation/tools/runner.js +0 -1332
- package/core/.formation/tools/task-utils.js +0 -344
- package/core/.formation/tools/task2028-headless-worktree.test.js +0 -112
- package/core/.formation/tools/tests/headless-mcp-args-plumbing.test.js +0 -123
- package/core/.formation/tools/worktree-leak.test.js +0 -162
- package/core/k-cli/dist/alaya/run.js +0 -91
- package/core/k-cli/dist/core/output.js +0 -24
- package/core/k-cli/dist/core/process.js +0 -38
- package/core/k-cli/dist/core/project.js +0 -80
- package/core/k-cli/dist/core/spawn.js +0 -268
- package/core/k-cli/dist/core/types.js +0 -2
- package/core/k-cli/dist/dashboard/update.js +0 -53
- package/core/k-cli/dist/dashboard/version.js +0 -20
- package/core/k-cli/dist/dispatch/run.js +0 -241
- package/core/k-cli/dist/dispatch/status.js +0 -103
- package/core/k-cli/dist/index.js +0 -283
- package/core/k-cli/dist/project/initialize.js +0 -301
- package/core/k-cli/dist/project/install.js +0 -89
- package/core/k-cli/dist/project/status.js +0 -138
- package/core/k-cli/dist/specialist/list.js +0 -100
- package/core/k-cli/dist/specialist/run.js +0 -93
- package/core/k-cli/dist/task/create.js +0 -194
- package/core/k-cli/dist/task/delete.js +0 -98
- package/core/k-cli/dist/task/get.js +0 -55
- package/core/k-cli/dist/task/list.js +0 -58
- package/core/k-cli/dist/task/submit.js +0 -156
- package/core/k-cli/dist/ygg/run.js +0 -51
- package/core/k-cli/node_modules/.bin/yaml +0 -16
- package/core/k-cli/node_modules/.bin/yaml.cmd +0 -17
- package/core/k-cli/node_modules/.bin/yaml.ps1 +0 -28
- package/core/k-cli/node_modules/.package-lock.json +0 -23
- package/core/k-cli/node_modules/yaml/LICENSE +0 -13
- package/core/k-cli/node_modules/yaml/README.md +0 -172
- package/core/k-cli/node_modules/yaml/bin.mjs +0 -11
- package/core/k-cli/node_modules/yaml/browser/dist/compose/compose-collection.js +0 -88
- package/core/k-cli/node_modules/yaml/browser/dist/compose/compose-doc.js +0 -43
- package/core/k-cli/node_modules/yaml/browser/dist/compose/compose-node.js +0 -109
- package/core/k-cli/node_modules/yaml/browser/dist/compose/compose-scalar.js +0 -86
- package/core/k-cli/node_modules/yaml/browser/dist/compose/composer.js +0 -217
- package/core/k-cli/node_modules/yaml/browser/dist/compose/resolve-block-map.js +0 -115
- package/core/k-cli/node_modules/yaml/browser/dist/compose/resolve-block-scalar.js +0 -198
- package/core/k-cli/node_modules/yaml/browser/dist/compose/resolve-block-seq.js +0 -49
- package/core/k-cli/node_modules/yaml/browser/dist/compose/resolve-end.js +0 -37
- package/core/k-cli/node_modules/yaml/browser/dist/compose/resolve-flow-collection.js +0 -207
- package/core/k-cli/node_modules/yaml/browser/dist/compose/resolve-flow-scalar.js +0 -223
- package/core/k-cli/node_modules/yaml/browser/dist/compose/resolve-props.js +0 -146
- package/core/k-cli/node_modules/yaml/browser/dist/compose/util-contains-newline.js +0 -34
- package/core/k-cli/node_modules/yaml/browser/dist/compose/util-empty-scalar-position.js +0 -26
- package/core/k-cli/node_modules/yaml/browser/dist/compose/util-flow-indent-check.js +0 -15
- package/core/k-cli/node_modules/yaml/browser/dist/compose/util-map-includes.js +0 -13
- package/core/k-cli/node_modules/yaml/browser/dist/doc/Document.js +0 -335
- package/core/k-cli/node_modules/yaml/browser/dist/doc/anchors.js +0 -71
- package/core/k-cli/node_modules/yaml/browser/dist/doc/applyReviver.js +0 -55
- package/core/k-cli/node_modules/yaml/browser/dist/doc/createNode.js +0 -88
- package/core/k-cli/node_modules/yaml/browser/dist/doc/directives.js +0 -176
- package/core/k-cli/node_modules/yaml/browser/dist/errors.js +0 -57
- package/core/k-cli/node_modules/yaml/browser/dist/index.js +0 -17
- package/core/k-cli/node_modules/yaml/browser/dist/log.js +0 -11
- package/core/k-cli/node_modules/yaml/browser/dist/nodes/Alias.js +0 -114
- package/core/k-cli/node_modules/yaml/browser/dist/nodes/Collection.js +0 -147
- package/core/k-cli/node_modules/yaml/browser/dist/nodes/Node.js +0 -38
- package/core/k-cli/node_modules/yaml/browser/dist/nodes/Pair.js +0 -36
- package/core/k-cli/node_modules/yaml/browser/dist/nodes/Scalar.js +0 -24
- package/core/k-cli/node_modules/yaml/browser/dist/nodes/YAMLMap.js +0 -144
- package/core/k-cli/node_modules/yaml/browser/dist/nodes/YAMLSeq.js +0 -113
- package/core/k-cli/node_modules/yaml/browser/dist/nodes/addPairToJSMap.js +0 -63
- package/core/k-cli/node_modules/yaml/browser/dist/nodes/identity.js +0 -36
- package/core/k-cli/node_modules/yaml/browser/dist/nodes/toJS.js +0 -37
- package/core/k-cli/node_modules/yaml/browser/dist/parse/cst-scalar.js +0 -214
- package/core/k-cli/node_modules/yaml/browser/dist/parse/cst-stringify.js +0 -61
- package/core/k-cli/node_modules/yaml/browser/dist/parse/cst-visit.js +0 -97
- package/core/k-cli/node_modules/yaml/browser/dist/parse/cst.js +0 -98
- package/core/k-cli/node_modules/yaml/browser/dist/parse/lexer.js +0 -717
- package/core/k-cli/node_modules/yaml/browser/dist/parse/line-counter.js +0 -39
- package/core/k-cli/node_modules/yaml/browser/dist/parse/parser.js +0 -967
- package/core/k-cli/node_modules/yaml/browser/dist/public-api.js +0 -102
- package/core/k-cli/node_modules/yaml/browser/dist/schema/Schema.js +0 -37
- package/core/k-cli/node_modules/yaml/browser/dist/schema/common/map.js +0 -17
- package/core/k-cli/node_modules/yaml/browser/dist/schema/common/null.js +0 -15
- package/core/k-cli/node_modules/yaml/browser/dist/schema/common/seq.js +0 -17
- package/core/k-cli/node_modules/yaml/browser/dist/schema/common/string.js +0 -14
- package/core/k-cli/node_modules/yaml/browser/dist/schema/core/bool.js +0 -19
- package/core/k-cli/node_modules/yaml/browser/dist/schema/core/float.js +0 -43
- package/core/k-cli/node_modules/yaml/browser/dist/schema/core/int.js +0 -38
- package/core/k-cli/node_modules/yaml/browser/dist/schema/core/schema.js +0 -23
- package/core/k-cli/node_modules/yaml/browser/dist/schema/json/schema.js +0 -62
- package/core/k-cli/node_modules/yaml/browser/dist/schema/tags.js +0 -96
- package/core/k-cli/node_modules/yaml/browser/dist/schema/yaml-1.1/binary.js +0 -58
- package/core/k-cli/node_modules/yaml/browser/dist/schema/yaml-1.1/bool.js +0 -26
- package/core/k-cli/node_modules/yaml/browser/dist/schema/yaml-1.1/float.js +0 -46
- package/core/k-cli/node_modules/yaml/browser/dist/schema/yaml-1.1/int.js +0 -71
- package/core/k-cli/node_modules/yaml/browser/dist/schema/yaml-1.1/merge.js +0 -64
- package/core/k-cli/node_modules/yaml/browser/dist/schema/yaml-1.1/omap.js +0 -74
- package/core/k-cli/node_modules/yaml/browser/dist/schema/yaml-1.1/pairs.js +0 -78
- package/core/k-cli/node_modules/yaml/browser/dist/schema/yaml-1.1/schema.js +0 -39
- package/core/k-cli/node_modules/yaml/browser/dist/schema/yaml-1.1/set.js +0 -93
- package/core/k-cli/node_modules/yaml/browser/dist/schema/yaml-1.1/timestamp.js +0 -101
- package/core/k-cli/node_modules/yaml/browser/dist/stringify/foldFlowLines.js +0 -146
- package/core/k-cli/node_modules/yaml/browser/dist/stringify/stringify.js +0 -129
- package/core/k-cli/node_modules/yaml/browser/dist/stringify/stringifyCollection.js +0 -153
- package/core/k-cli/node_modules/yaml/browser/dist/stringify/stringifyComment.js +0 -20
- package/core/k-cli/node_modules/yaml/browser/dist/stringify/stringifyDocument.js +0 -85
- package/core/k-cli/node_modules/yaml/browser/dist/stringify/stringifyNumber.js +0 -24
- package/core/k-cli/node_modules/yaml/browser/dist/stringify/stringifyPair.js +0 -150
- package/core/k-cli/node_modules/yaml/browser/dist/stringify/stringifyString.js +0 -336
- package/core/k-cli/node_modules/yaml/browser/dist/util.js +0 -11
- package/core/k-cli/node_modules/yaml/browser/dist/visit.js +0 -233
- package/core/k-cli/node_modules/yaml/browser/index.js +0 -5
- package/core/k-cli/node_modules/yaml/browser/package.json +0 -3
- package/core/k-cli/node_modules/yaml/dist/cli.d.ts +0 -8
- package/core/k-cli/node_modules/yaml/dist/cli.mjs +0 -201
- package/core/k-cli/node_modules/yaml/dist/compose/compose-collection.d.ts +0 -11
- package/core/k-cli/node_modules/yaml/dist/compose/compose-collection.js +0 -90
- package/core/k-cli/node_modules/yaml/dist/compose/compose-doc.d.ts +0 -7
- package/core/k-cli/node_modules/yaml/dist/compose/compose-doc.js +0 -45
- package/core/k-cli/node_modules/yaml/dist/compose/compose-node.d.ts +0 -29
- package/core/k-cli/node_modules/yaml/dist/compose/compose-node.js +0 -112
- package/core/k-cli/node_modules/yaml/dist/compose/compose-scalar.d.ts +0 -5
- package/core/k-cli/node_modules/yaml/dist/compose/compose-scalar.js +0 -88
- package/core/k-cli/node_modules/yaml/dist/compose/composer.d.ts +0 -63
- package/core/k-cli/node_modules/yaml/dist/compose/composer.js +0 -222
- package/core/k-cli/node_modules/yaml/dist/compose/resolve-block-map.d.ts +0 -6
- package/core/k-cli/node_modules/yaml/dist/compose/resolve-block-map.js +0 -117
- package/core/k-cli/node_modules/yaml/dist/compose/resolve-block-scalar.d.ts +0 -11
- package/core/k-cli/node_modules/yaml/dist/compose/resolve-block-scalar.js +0 -200
- package/core/k-cli/node_modules/yaml/dist/compose/resolve-block-seq.d.ts +0 -6
- package/core/k-cli/node_modules/yaml/dist/compose/resolve-block-seq.js +0 -51
- package/core/k-cli/node_modules/yaml/dist/compose/resolve-end.d.ts +0 -6
- package/core/k-cli/node_modules/yaml/dist/compose/resolve-end.js +0 -39
- package/core/k-cli/node_modules/yaml/dist/compose/resolve-flow-collection.d.ts +0 -7
- package/core/k-cli/node_modules/yaml/dist/compose/resolve-flow-collection.js +0 -209
- package/core/k-cli/node_modules/yaml/dist/compose/resolve-flow-scalar.d.ts +0 -10
- package/core/k-cli/node_modules/yaml/dist/compose/resolve-flow-scalar.js +0 -225
- package/core/k-cli/node_modules/yaml/dist/compose/resolve-props.d.ts +0 -23
- package/core/k-cli/node_modules/yaml/dist/compose/resolve-props.js +0 -148
- package/core/k-cli/node_modules/yaml/dist/compose/util-contains-newline.d.ts +0 -2
- package/core/k-cli/node_modules/yaml/dist/compose/util-contains-newline.js +0 -36
- package/core/k-cli/node_modules/yaml/dist/compose/util-empty-scalar-position.d.ts +0 -2
- package/core/k-cli/node_modules/yaml/dist/compose/util-empty-scalar-position.js +0 -28
- package/core/k-cli/node_modules/yaml/dist/compose/util-flow-indent-check.d.ts +0 -3
- package/core/k-cli/node_modules/yaml/dist/compose/util-flow-indent-check.js +0 -17
- package/core/k-cli/node_modules/yaml/dist/compose/util-map-includes.d.ts +0 -4
- package/core/k-cli/node_modules/yaml/dist/compose/util-map-includes.js +0 -15
- package/core/k-cli/node_modules/yaml/dist/doc/Document.d.ts +0 -141
- package/core/k-cli/node_modules/yaml/dist/doc/Document.js +0 -337
- package/core/k-cli/node_modules/yaml/dist/doc/anchors.d.ts +0 -24
- package/core/k-cli/node_modules/yaml/dist/doc/anchors.js +0 -76
- package/core/k-cli/node_modules/yaml/dist/doc/applyReviver.d.ts +0 -9
- package/core/k-cli/node_modules/yaml/dist/doc/applyReviver.js +0 -57
- package/core/k-cli/node_modules/yaml/dist/doc/createNode.d.ts +0 -17
- package/core/k-cli/node_modules/yaml/dist/doc/createNode.js +0 -90
- package/core/k-cli/node_modules/yaml/dist/doc/directives.d.ts +0 -49
- package/core/k-cli/node_modules/yaml/dist/doc/directives.js +0 -178
- package/core/k-cli/node_modules/yaml/dist/errors.d.ts +0 -21
- package/core/k-cli/node_modules/yaml/dist/errors.js +0 -62
- package/core/k-cli/node_modules/yaml/dist/index.d.ts +0 -25
- package/core/k-cli/node_modules/yaml/dist/index.js +0 -50
- package/core/k-cli/node_modules/yaml/dist/log.d.ts +0 -3
- package/core/k-cli/node_modules/yaml/dist/log.js +0 -19
- package/core/k-cli/node_modules/yaml/dist/nodes/Alias.d.ts +0 -29
- package/core/k-cli/node_modules/yaml/dist/nodes/Alias.js +0 -116
- package/core/k-cli/node_modules/yaml/dist/nodes/Collection.d.ts +0 -73
- package/core/k-cli/node_modules/yaml/dist/nodes/Collection.js +0 -151
- package/core/k-cli/node_modules/yaml/dist/nodes/Node.d.ts +0 -53
- package/core/k-cli/node_modules/yaml/dist/nodes/Node.js +0 -40
- package/core/k-cli/node_modules/yaml/dist/nodes/Pair.d.ts +0 -22
- package/core/k-cli/node_modules/yaml/dist/nodes/Pair.js +0 -39
- package/core/k-cli/node_modules/yaml/dist/nodes/Scalar.d.ts +0 -43
- package/core/k-cli/node_modules/yaml/dist/nodes/Scalar.js +0 -27
- package/core/k-cli/node_modules/yaml/dist/nodes/YAMLMap.d.ts +0 -53
- package/core/k-cli/node_modules/yaml/dist/nodes/YAMLMap.js +0 -147
- package/core/k-cli/node_modules/yaml/dist/nodes/YAMLSeq.d.ts +0 -60
- package/core/k-cli/node_modules/yaml/dist/nodes/YAMLSeq.js +0 -115
- package/core/k-cli/node_modules/yaml/dist/nodes/addPairToJSMap.d.ts +0 -4
- package/core/k-cli/node_modules/yaml/dist/nodes/addPairToJSMap.js +0 -65
- package/core/k-cli/node_modules/yaml/dist/nodes/identity.d.ts +0 -23
- package/core/k-cli/node_modules/yaml/dist/nodes/identity.js +0 -53
- package/core/k-cli/node_modules/yaml/dist/nodes/toJS.d.ts +0 -29
- package/core/k-cli/node_modules/yaml/dist/nodes/toJS.js +0 -39
- package/core/k-cli/node_modules/yaml/dist/options.d.ts +0 -350
- package/core/k-cli/node_modules/yaml/dist/parse/cst-scalar.d.ts +0 -64
- package/core/k-cli/node_modules/yaml/dist/parse/cst-scalar.js +0 -218
- package/core/k-cli/node_modules/yaml/dist/parse/cst-stringify.d.ts +0 -8
- package/core/k-cli/node_modules/yaml/dist/parse/cst-stringify.js +0 -63
- package/core/k-cli/node_modules/yaml/dist/parse/cst-visit.d.ts +0 -39
- package/core/k-cli/node_modules/yaml/dist/parse/cst-visit.js +0 -99
- package/core/k-cli/node_modules/yaml/dist/parse/cst.d.ts +0 -109
- package/core/k-cli/node_modules/yaml/dist/parse/cst.js +0 -112
- package/core/k-cli/node_modules/yaml/dist/parse/lexer.d.ts +0 -87
- package/core/k-cli/node_modules/yaml/dist/parse/lexer.js +0 -719
- package/core/k-cli/node_modules/yaml/dist/parse/line-counter.d.ts +0 -22
- package/core/k-cli/node_modules/yaml/dist/parse/line-counter.js +0 -41
- package/core/k-cli/node_modules/yaml/dist/parse/parser.d.ts +0 -84
- package/core/k-cli/node_modules/yaml/dist/parse/parser.js +0 -972
- package/core/k-cli/node_modules/yaml/dist/public-api.d.ts +0 -44
- package/core/k-cli/node_modules/yaml/dist/public-api.js +0 -107
- package/core/k-cli/node_modules/yaml/dist/schema/Schema.d.ts +0 -17
- package/core/k-cli/node_modules/yaml/dist/schema/Schema.js +0 -39
- package/core/k-cli/node_modules/yaml/dist/schema/common/map.d.ts +0 -2
- package/core/k-cli/node_modules/yaml/dist/schema/common/map.js +0 -19
- package/core/k-cli/node_modules/yaml/dist/schema/common/null.d.ts +0 -4
- package/core/k-cli/node_modules/yaml/dist/schema/common/null.js +0 -17
- package/core/k-cli/node_modules/yaml/dist/schema/common/seq.d.ts +0 -2
- package/core/k-cli/node_modules/yaml/dist/schema/common/seq.js +0 -19
- package/core/k-cli/node_modules/yaml/dist/schema/common/string.d.ts +0 -2
- package/core/k-cli/node_modules/yaml/dist/schema/common/string.js +0 -16
- package/core/k-cli/node_modules/yaml/dist/schema/core/bool.d.ts +0 -4
- package/core/k-cli/node_modules/yaml/dist/schema/core/bool.js +0 -21
- package/core/k-cli/node_modules/yaml/dist/schema/core/float.d.ts +0 -4
- package/core/k-cli/node_modules/yaml/dist/schema/core/float.js +0 -47
- package/core/k-cli/node_modules/yaml/dist/schema/core/int.d.ts +0 -4
- package/core/k-cli/node_modules/yaml/dist/schema/core/int.js +0 -42
- package/core/k-cli/node_modules/yaml/dist/schema/core/schema.d.ts +0 -1
- package/core/k-cli/node_modules/yaml/dist/schema/core/schema.js +0 -25
- package/core/k-cli/node_modules/yaml/dist/schema/json/schema.d.ts +0 -2
- package/core/k-cli/node_modules/yaml/dist/schema/json/schema.js +0 -64
- package/core/k-cli/node_modules/yaml/dist/schema/json-schema.d.ts +0 -69
- package/core/k-cli/node_modules/yaml/dist/schema/tags.d.ts +0 -48
- package/core/k-cli/node_modules/yaml/dist/schema/tags.js +0 -99
- package/core/k-cli/node_modules/yaml/dist/schema/types.d.ts +0 -92
- package/core/k-cli/node_modules/yaml/dist/schema/yaml-1.1/binary.d.ts +0 -2
- package/core/k-cli/node_modules/yaml/dist/schema/yaml-1.1/binary.js +0 -70
- package/core/k-cli/node_modules/yaml/dist/schema/yaml-1.1/bool.d.ts +0 -7
- package/core/k-cli/node_modules/yaml/dist/schema/yaml-1.1/bool.js +0 -29
- package/core/k-cli/node_modules/yaml/dist/schema/yaml-1.1/float.d.ts +0 -4
- package/core/k-cli/node_modules/yaml/dist/schema/yaml-1.1/float.js +0 -50
- package/core/k-cli/node_modules/yaml/dist/schema/yaml-1.1/int.d.ts +0 -5
- package/core/k-cli/node_modules/yaml/dist/schema/yaml-1.1/int.js +0 -76
- package/core/k-cli/node_modules/yaml/dist/schema/yaml-1.1/merge.d.ts +0 -9
- package/core/k-cli/node_modules/yaml/dist/schema/yaml-1.1/merge.js +0 -68
- package/core/k-cli/node_modules/yaml/dist/schema/yaml-1.1/omap.d.ts +0 -22
- package/core/k-cli/node_modules/yaml/dist/schema/yaml-1.1/omap.js +0 -77
- package/core/k-cli/node_modules/yaml/dist/schema/yaml-1.1/pairs.d.ts +0 -10
- package/core/k-cli/node_modules/yaml/dist/schema/yaml-1.1/pairs.js +0 -82
- package/core/k-cli/node_modules/yaml/dist/schema/yaml-1.1/schema.d.ts +0 -1
- package/core/k-cli/node_modules/yaml/dist/schema/yaml-1.1/schema.js +0 -41
- package/core/k-cli/node_modules/yaml/dist/schema/yaml-1.1/set.d.ts +0 -28
- package/core/k-cli/node_modules/yaml/dist/schema/yaml-1.1/set.js +0 -96
- package/core/k-cli/node_modules/yaml/dist/schema/yaml-1.1/timestamp.d.ts +0 -6
- package/core/k-cli/node_modules/yaml/dist/schema/yaml-1.1/timestamp.js +0 -105
- package/core/k-cli/node_modules/yaml/dist/stringify/foldFlowLines.d.ts +0 -34
- package/core/k-cli/node_modules/yaml/dist/stringify/foldFlowLines.js +0 -151
- package/core/k-cli/node_modules/yaml/dist/stringify/stringify.d.ts +0 -21
- package/core/k-cli/node_modules/yaml/dist/stringify/stringify.js +0 -132
- package/core/k-cli/node_modules/yaml/dist/stringify/stringifyCollection.d.ts +0 -17
- package/core/k-cli/node_modules/yaml/dist/stringify/stringifyCollection.js +0 -155
- package/core/k-cli/node_modules/yaml/dist/stringify/stringifyComment.d.ts +0 -10
- package/core/k-cli/node_modules/yaml/dist/stringify/stringifyComment.js +0 -24
- package/core/k-cli/node_modules/yaml/dist/stringify/stringifyDocument.d.ts +0 -4
- package/core/k-cli/node_modules/yaml/dist/stringify/stringifyDocument.js +0 -87
- package/core/k-cli/node_modules/yaml/dist/stringify/stringifyNumber.d.ts +0 -2
- package/core/k-cli/node_modules/yaml/dist/stringify/stringifyNumber.js +0 -26
- package/core/k-cli/node_modules/yaml/dist/stringify/stringifyPair.d.ts +0 -3
- package/core/k-cli/node_modules/yaml/dist/stringify/stringifyPair.js +0 -152
- package/core/k-cli/node_modules/yaml/dist/stringify/stringifyString.d.ts +0 -9
- package/core/k-cli/node_modules/yaml/dist/stringify/stringifyString.js +0 -338
- package/core/k-cli/node_modules/yaml/dist/test-events.d.ts +0 -4
- package/core/k-cli/node_modules/yaml/dist/test-events.js +0 -134
- package/core/k-cli/node_modules/yaml/dist/util.d.ts +0 -16
- package/core/k-cli/node_modules/yaml/dist/util.js +0 -28
- package/core/k-cli/node_modules/yaml/dist/visit.d.ts +0 -102
- package/core/k-cli/node_modules/yaml/dist/visit.js +0 -236
- package/core/k-cli/node_modules/yaml/package.json +0 -97
- package/core/k-cli/node_modules/yaml/util.js +0 -2
|
@@ -1,273 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Formation Logger
|
|
3
|
-
* Claude subagent 輸出的 stream-json 格式化
|
|
4
|
-
*
|
|
5
|
-
* 支援的 entry types:
|
|
6
|
-
* - system: init, hook 事件
|
|
7
|
-
* - assistant: agent 的文字輸出和工具呼叫
|
|
8
|
-
* - user: tool_use_result、teammate 訊息
|
|
9
|
-
* - result: session 結束摘要
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
const fs = require('fs');
|
|
13
|
-
const path = require('path');
|
|
14
|
-
const { LOG_DIR, getLogDir } = require('./utils');
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Local wall-clock HH:MM:SS for per-line log prefixes.
|
|
18
|
-
*
|
|
19
|
-
* LOCAL (not UTC) on purpose — TASK_1845: file mtime displays in local time,
|
|
20
|
-
* so the last log line's timestamp must be directly comparable with the file's
|
|
21
|
-
* mtime without timezone arithmetic. The previous UTC prefix
|
|
22
|
-
* (`toISOString().slice(11,19)`) was misread as "agent stalled for 8 hours"
|
|
23
|
-
* in a UTC+8 environment when the file had been written 13 seconds earlier.
|
|
24
|
-
*
|
|
25
|
-
* The `[HH:MM:SS]` shape is unchanged (downstream parsers depend on it). Cross-timezone readers can
|
|
26
|
-
* anchor via the header, which carries both the ISO-8601 `Started:` line and
|
|
27
|
-
* an explicit `Timezone: UTC±HH:MM` line.
|
|
28
|
-
*/
|
|
29
|
-
function localHHMMSS() {
|
|
30
|
-
const d = new Date();
|
|
31
|
-
const p = (n) => String(n).padStart(2, '0');
|
|
32
|
-
return `${p(d.getHours())}:${p(d.getMinutes())}:${p(d.getSeconds())}`;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
/** UTC offset of this machine as `UTC±HH:MM` (e.g. `UTC+08:00`). */
|
|
36
|
-
function localUtcOffset() {
|
|
37
|
-
const offMin = -new Date().getTimezoneOffset();
|
|
38
|
-
const sign = offMin >= 0 ? '+' : '-';
|
|
39
|
-
const abs = Math.abs(offMin);
|
|
40
|
-
const p = (n) => String(n).padStart(2, '0');
|
|
41
|
-
return `UTC${sign}${p(Math.floor(abs / 60))}:${p(abs % 60)}`;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* 建立 log writer
|
|
46
|
-
* @param {object} opts
|
|
47
|
-
* @param {string} opts.formation
|
|
48
|
-
* @param {string} opts.skill
|
|
49
|
-
* @param {string} opts.sessionId
|
|
50
|
-
* @param {string} [opts.outputPath] - 自訂輸出路徑
|
|
51
|
-
* @param {string} [opts.memberId] - Squad 成員 ID(可選)
|
|
52
|
-
* @param {string} [opts.projectPath] - 專案路徑(多專案支援)
|
|
53
|
-
* @returns {{ stream: WriteStream, path: string, writeHeader: Function, writeFooter: Function }}
|
|
54
|
-
*/
|
|
55
|
-
function createLogWriter(opts) {
|
|
56
|
-
const { formation, skill, sessionId, outputPath, memberId, projectPath } = opts;
|
|
57
|
-
|
|
58
|
-
// logs 按 formation 分目錄:logs/unit/, logs/squad/, ...
|
|
59
|
-
// 多專案:根據 projectPath 決定 log 根目錄
|
|
60
|
-
const logRoot = projectPath ? getLogDir(projectPath) : LOG_DIR;
|
|
61
|
-
const formationLogDir = path.join(logRoot, formation || 'misc');
|
|
62
|
-
if (!fs.existsSync(formationLogDir)) {
|
|
63
|
-
fs.mkdirSync(formationLogDir, { recursive: true });
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
const suffix = memberId ? `_${memberId}` : '';
|
|
67
|
-
const logPath = outputPath || path.join(formationLogDir, `${skill}${suffix}_${sessionId}.log`);
|
|
68
|
-
const stream = fs.createWriteStream(logPath, { flags: 'w' });
|
|
69
|
-
|
|
70
|
-
return {
|
|
71
|
-
stream,
|
|
72
|
-
path: logPath,
|
|
73
|
-
|
|
74
|
-
writeHeader() {
|
|
75
|
-
stream.write(`Formation: ${formation} | Skill: ${skill}${memberId ? ` | Member: ${memberId}` : ''}\n`);
|
|
76
|
-
stream.write(`Session: ${sessionId}\n`);
|
|
77
|
-
stream.write(`Started: ${new Date().toISOString()}\n`);
|
|
78
|
-
stream.write(`Timezone: ${localUtcOffset()} (per-line [HH:MM:SS] timestamps are local time, directly comparable to file mtime)\n`);
|
|
79
|
-
stream.write(`${'='.repeat(60)}\n\n`);
|
|
80
|
-
},
|
|
81
|
-
|
|
82
|
-
writeFooter(exitCode) {
|
|
83
|
-
stream.write(`\n${'='.repeat(60)}\n`);
|
|
84
|
-
stream.write(`Finished: ${new Date().toISOString()}\n`);
|
|
85
|
-
stream.write(`Exit Code: ${exitCode}\n`);
|
|
86
|
-
stream.end();
|
|
87
|
-
}
|
|
88
|
-
};
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
/**
|
|
92
|
-
* 格式化 stream-json 的一條 entry
|
|
93
|
-
* @param {object} entry - JSON parsed entry from claude --output-format stream-json
|
|
94
|
-
* @returns {string|null}
|
|
95
|
-
*/
|
|
96
|
-
function formatEntry(entry) {
|
|
97
|
-
const ts = localHHMMSS();
|
|
98
|
-
const { type } = entry;
|
|
99
|
-
|
|
100
|
-
// ── system events ──
|
|
101
|
-
if (type === 'system') {
|
|
102
|
-
return formatSystem(ts, entry);
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
// ── assistant(agent 的輸出和工具呼叫)──
|
|
106
|
-
if (type === 'assistant' && entry.message?.content) {
|
|
107
|
-
const parts = [];
|
|
108
|
-
for (const block of entry.message.content) {
|
|
109
|
-
if (block.type === 'text' && block.text?.trim()) {
|
|
110
|
-
const clean = block.text
|
|
111
|
-
.replace(/^#{1,6}\s+/gm, '')
|
|
112
|
-
.replace(/\*\*([^*]+)\*\*/g, '$1')
|
|
113
|
-
.trim();
|
|
114
|
-
const lines = clean.split('\n').filter(l => l.trim());
|
|
115
|
-
for (const l of lines) {
|
|
116
|
-
parts.push(`[${ts}][Agent] ${l.trim()}`);
|
|
117
|
-
}
|
|
118
|
-
} else if (block.type === 'tool_use') {
|
|
119
|
-
parts.push(formatToolUse(ts, block));
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
return parts.length ? parts.join('\n') : null;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
// ── user(tool results、teammate 訊息)──
|
|
126
|
-
if (type === 'user') {
|
|
127
|
-
return formatUser(ts, entry);
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
// ── result(session 結束)──
|
|
131
|
-
if (type === 'result') {
|
|
132
|
-
return formatResult(ts, entry);
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
return null;
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
// ─────────────────────────────────────────
|
|
139
|
-
// system events
|
|
140
|
-
// ─────────────────────────────────────────
|
|
141
|
-
|
|
142
|
-
function formatSystem(ts, entry) {
|
|
143
|
-
const { subtype } = entry;
|
|
144
|
-
if (subtype === 'init') {
|
|
145
|
-
return `[${ts}][SYSTEM][INIT] model=${entry.model || ''} cwd=${entry.cwd || ''}`;
|
|
146
|
-
}
|
|
147
|
-
if (subtype === 'hook_started') {
|
|
148
|
-
return `[${ts}][SYSTEM][HOOK] ${entry.hook_name || ''} started`;
|
|
149
|
-
}
|
|
150
|
-
if (subtype === 'hook_response') {
|
|
151
|
-
const status = entry.outcome === 'error' ? 'FAILED' : 'OK';
|
|
152
|
-
return `[${ts}][SYSTEM][HOOK] ${entry.hook_name || ''} ${status}`;
|
|
153
|
-
}
|
|
154
|
-
return null;
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
// ─────────────────────────────────────────
|
|
158
|
-
// tool_use formatting(差異 4 修正)
|
|
159
|
-
// ─────────────────────────────────────────
|
|
160
|
-
|
|
161
|
-
function formatToolUse(ts, block) {
|
|
162
|
-
const tool = block.name;
|
|
163
|
-
const input = block.input || {};
|
|
164
|
-
|
|
165
|
-
const toolFormatters = {
|
|
166
|
-
Bash: () => input.description || input.command?.slice(0, 60) || '',
|
|
167
|
-
Read: () => input.file_path || '',
|
|
168
|
-
Write: () => input.file_path || '',
|
|
169
|
-
Edit: () => input.file_path || '',
|
|
170
|
-
Glob: () => input.pattern || '',
|
|
171
|
-
Grep: () => input.pattern || '',
|
|
172
|
-
|
|
173
|
-
// Agent Teams 工具(與 Sunny format-output.js 對齊)
|
|
174
|
-
TeamCreate: () => `team="${input.team_name || ''}"`,
|
|
175
|
-
TeamDelete: () => '',
|
|
176
|
-
Task: () => {
|
|
177
|
-
const name = input.name || input.description?.slice(0, 30) || '';
|
|
178
|
-
const agentType = input.subagent_type || '';
|
|
179
|
-
return name ? `spawn="${name}" type=${agentType}` : agentType;
|
|
180
|
-
},
|
|
181
|
-
SendMessage: () => {
|
|
182
|
-
const recipient = input.recipient || '';
|
|
183
|
-
const msgType = input.type || 'message';
|
|
184
|
-
return `to=${recipient} type=${msgType}`;
|
|
185
|
-
},
|
|
186
|
-
TodoWrite: () => '',
|
|
187
|
-
};
|
|
188
|
-
|
|
189
|
-
const detail = (toolFormatters[tool] || (() => ''))();
|
|
190
|
-
const line = `[${ts}][Agent][${tool}] ${detail}`;
|
|
191
|
-
|
|
192
|
-
// SendMessage:附加完整訊息內容(與 Sunny 一致)
|
|
193
|
-
if (tool === 'SendMessage' && input.content) {
|
|
194
|
-
const msgLines = input.content.split('\n');
|
|
195
|
-
const formatted = msgLines.map(ml => ` | ${ml}`).join('\n');
|
|
196
|
-
return `${line}\n${formatted}`;
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
return line;
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
// ─────────────────────────────────────────
|
|
203
|
-
// user events(差異 3 修正)
|
|
204
|
-
// ─────────────────────────────────────────
|
|
205
|
-
|
|
206
|
-
function formatUser(ts, entry) {
|
|
207
|
-
const parts = [];
|
|
208
|
-
|
|
209
|
-
// tool_use_result(teammate spawn 確認等)
|
|
210
|
-
if (entry.tool_use_result) {
|
|
211
|
-
const result = entry.tool_use_result;
|
|
212
|
-
if (result.status === 'teammate_spawned') {
|
|
213
|
-
parts.push(`[${ts}][SYSTEM][Spawned] Teammate "${result.name || ''}" model=${result.model || ''}`);
|
|
214
|
-
} else if (result.team_name && result.success !== undefined) {
|
|
215
|
-
const status = result.success ? 'OK' : 'FAILED';
|
|
216
|
-
parts.push(`[${ts}][SYSTEM][TeamOp] ${status}: ${result.team_name}`);
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
// 收到的訊息(來自 teammates 的 SendMessage)
|
|
221
|
-
if (entry.message?.content) {
|
|
222
|
-
for (const block of entry.message.content) {
|
|
223
|
-
if (block.type === 'text' && block.text) {
|
|
224
|
-
const text = block.text;
|
|
225
|
-
|
|
226
|
-
// 嘗試提取 teammate 名稱
|
|
227
|
-
let teammateName = 'Unknown';
|
|
228
|
-
const nameMatch = text.match(/(?:from|From)\s+["']?(\w+[-\w]*)["']?/i);
|
|
229
|
-
if (nameMatch) {
|
|
230
|
-
teammateName = nameMatch[1];
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
// 判斷是否是 teammate 訊息
|
|
234
|
-
if (text.includes('Message from') || text.includes('teammate') || text.includes('Teammate')) {
|
|
235
|
-
parts.push(`[${ts}][Teammate:${teammateName}]`);
|
|
236
|
-
const msgLines = text.split('\n').filter(l => l.trim());
|
|
237
|
-
for (const ml of msgLines) {
|
|
238
|
-
parts.push(` | ${ml}`);
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
return parts.length > 0 ? parts.join('\n') : null;
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
// ─────────────────────────────────────────
|
|
249
|
-
// result(session 結束摘要,加入 token 統計)
|
|
250
|
-
// ─────────────────────────────────────────
|
|
251
|
-
|
|
252
|
-
function formatResult(ts, entry) {
|
|
253
|
-
const lines = [];
|
|
254
|
-
lines.push(`[${ts}][RESULT] ${(entry.subtype || '').toUpperCase()}`);
|
|
255
|
-
lines.push(` Duration: ${((entry.duration_ms || 0) / 1000).toFixed(1)}s`);
|
|
256
|
-
lines.push(` Cost: $${(entry.total_cost_usd || 0).toFixed(4)}`);
|
|
257
|
-
|
|
258
|
-
// Token 統計(與 Sunny 對齊)
|
|
259
|
-
if (entry.num_turns) {
|
|
260
|
-
lines.push(` Turns: ${entry.num_turns}`);
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
if (entry.result) {
|
|
264
|
-
const clean = entry.result.replace(/\*\*([^*]+)\*\*/g, '$1').trim();
|
|
265
|
-
const resultLines = clean.split('\n').filter(l => l.trim()).slice(0, 10);
|
|
266
|
-
for (const rl of resultLines) {
|
|
267
|
-
lines.push(` ${rl}`);
|
|
268
|
-
}
|
|
269
|
-
}
|
|
270
|
-
return lines.join('\n');
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
module.exports = { createLogWriter, formatEntry };
|
|
@@ -1,422 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Memory Loader for Formation Prompt Builder
|
|
3
|
-
* 從三個記憶系統載入相關經驗,注入到 agent prompt 中
|
|
4
|
-
*
|
|
5
|
-
* 系統:
|
|
6
|
-
* 1. .failure/ — 失敗經驗(YAML,按 category 分目錄)
|
|
7
|
-
* 2. .memory/ — 專案記憶(JSON,含 registry.json 索引)
|
|
8
|
-
* 3. .kenaz/main-memory/ — 主記憶(Markdown,唯讀知識庫)
|
|
9
|
-
*
|
|
10
|
-
* 設計原則:
|
|
11
|
-
* - 輕量:不跑 Node 子進程,直接讀檔
|
|
12
|
-
* - 容錯:任何系統不可用時 graceful degradation
|
|
13
|
-
* - Token 友善:按任務相關度裁剪,控制總 token 預算
|
|
14
|
-
*/
|
|
15
|
-
|
|
16
|
-
const fs = require('fs');
|
|
17
|
-
const path = require('path');
|
|
18
|
-
|
|
19
|
-
const ROOT = path.resolve(__dirname, '..', '..');
|
|
20
|
-
|
|
21
|
-
// ─────────────────────────────────────────
|
|
22
|
-
// 配置
|
|
23
|
-
// ─────────────────────────────────────────
|
|
24
|
-
|
|
25
|
-
const DEFAULT_CONFIG = {
|
|
26
|
-
// Token 預算(字元數,粗略 1 token ≈ 4 chars)
|
|
27
|
-
MAX_CHARS: 3000,
|
|
28
|
-
|
|
29
|
-
// 各系統最大條目數
|
|
30
|
-
MAX_FAILURES: 3,
|
|
31
|
-
MAX_MEMORIES: 5,
|
|
32
|
-
MAX_MAIN_MEMORY: 3,
|
|
33
|
-
|
|
34
|
-
// .failure/ 路徑
|
|
35
|
-
FAILURE_DIR: path.join(ROOT, '.failure'),
|
|
36
|
-
|
|
37
|
-
// .memory/ 路徑
|
|
38
|
-
MEMORY_DIR: path.join(ROOT, '.memory'),
|
|
39
|
-
MEMORY_REGISTRY: path.join(ROOT, '.memory', 'registry.json'),
|
|
40
|
-
|
|
41
|
-
// .kenaz/main-memory/ 路徑
|
|
42
|
-
MAIN_MEMORY_DIR: path.join(ROOT, '.kenaz', 'main-memory'),
|
|
43
|
-
MAIN_MEMORY_REGISTRY: path.join(ROOT, '.kenaz', 'main-memory', 'registry.json'),
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
// Keep a mutable reference so callers that imported CONFIG still work
|
|
47
|
-
const CONFIG = { ...DEFAULT_CONFIG };
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* Build config paths from a given core root directory.
|
|
51
|
-
* When corePath differs from ROOT, re-points .failure/, .memory/, .kenaz/main-memory/
|
|
52
|
-
* to the core project so sub-projects can load system-level memories.
|
|
53
|
-
*/
|
|
54
|
-
function resolveConfig(corePath) {
|
|
55
|
-
if (!corePath || path.resolve(corePath) === path.resolve(ROOT)) {
|
|
56
|
-
return DEFAULT_CONFIG;
|
|
57
|
-
}
|
|
58
|
-
return {
|
|
59
|
-
...DEFAULT_CONFIG,
|
|
60
|
-
FAILURE_DIR: path.join(corePath, '.failure'),
|
|
61
|
-
MEMORY_DIR: path.join(corePath, '.memory'),
|
|
62
|
-
MEMORY_REGISTRY: path.join(corePath, '.memory', 'registry.json'),
|
|
63
|
-
MAIN_MEMORY_DIR: path.join(corePath, '.kenaz', 'main-memory'),
|
|
64
|
-
MAIN_MEMORY_REGISTRY: path.join(corePath, '.kenaz', 'main-memory', 'registry.json'),
|
|
65
|
-
};
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
// ─────────────────────────────────────────
|
|
69
|
-
// 主入口
|
|
70
|
-
// ─────────────────────────────────────────
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* 載入與任務相關的記憶 context
|
|
74
|
-
* @param {object} opts
|
|
75
|
-
* @param {string} [opts.taskTitle] - 任務標題
|
|
76
|
-
* @param {string} [opts.role] - 角色(frontend/backend/developer/...)
|
|
77
|
-
* @param {string[]} [opts.scopePaths] - scope 路徑
|
|
78
|
-
* @param {string[]} [opts.tags] - 任務標籤
|
|
79
|
-
* @param {string} [opts.priority] - P0/P1/P2/P3
|
|
80
|
-
* @param {boolean} [opts.skipFailures] - TASK_1998 R2 (+ follow-up
|
|
81
|
-
* 2026-09-22): skip Known Failures (rigor:low prompt diet only — rigor:medium
|
|
82
|
-
* restores this section).
|
|
83
|
-
* @param {boolean} [opts.skipMemory] - TASK_1998 R2: skip Project Memory
|
|
84
|
-
* (rigor low/medium prompt diet). Knowledge Base (main-memory) always loads
|
|
85
|
-
* regardless of either flag — it isn't part of the ritual collapse.
|
|
86
|
-
* @returns {string} 組裝好的記憶 context 區塊(可直接 append 到 prompt)
|
|
87
|
-
*/
|
|
88
|
-
function loadMemoryContext(opts = {}) {
|
|
89
|
-
// Resolve config from corePath (supports sub-projects pointing to core)
|
|
90
|
-
const cfg = resolveConfig(opts.corePath);
|
|
91
|
-
const sections = [];
|
|
92
|
-
|
|
93
|
-
// TASK_1998 R2 (+ follow-up 2026-09-22): Known Failures and Project Memory
|
|
94
|
-
// are two of the six ritual sections collapsed into prompt.js's "## Working
|
|
95
|
-
// contract" for rigor low/medium — but Known Failures is now restored for
|
|
96
|
-
// rigor:medium (only rigor:low drops it); Project Memory stays dropped for
|
|
97
|
-
// both. Knowledge Base (step 3, main-memory) is unaffected by either flag.
|
|
98
|
-
if (!opts.skipFailures) {
|
|
99
|
-
// 1. .failure/ — 失敗經驗(最高優先)
|
|
100
|
-
try {
|
|
101
|
-
const failures = loadFailures(opts, cfg);
|
|
102
|
-
if (failures.length > 0) {
|
|
103
|
-
sections.push(formatFailures(failures));
|
|
104
|
-
}
|
|
105
|
-
} catch { /* graceful degradation */ }
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
if (!opts.skipMemory) {
|
|
109
|
-
// 2. .memory/ — 專案記憶
|
|
110
|
-
try {
|
|
111
|
-
const memories = loadProjectMemories(opts, cfg);
|
|
112
|
-
if (memories.length > 0) {
|
|
113
|
-
sections.push(formatMemories(memories));
|
|
114
|
-
}
|
|
115
|
-
} catch { /* graceful degradation */ }
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
// 3. .kenaz/main-memory/ — 主記憶
|
|
119
|
-
try {
|
|
120
|
-
const mainMem = loadMainMemory(opts, cfg);
|
|
121
|
-
if (mainMem.length > 0) {
|
|
122
|
-
sections.push(formatMainMemory(mainMem));
|
|
123
|
-
}
|
|
124
|
-
} catch { /* graceful degradation */ }
|
|
125
|
-
|
|
126
|
-
if (sections.length === 0) return '';
|
|
127
|
-
|
|
128
|
-
// 組裝 + 裁剪
|
|
129
|
-
let result = sections.join('\n');
|
|
130
|
-
if (result.length > cfg.MAX_CHARS) {
|
|
131
|
-
result = result.slice(0, cfg.MAX_CHARS) + '\n...(記憶已裁剪)';
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
return result;
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
// ─────────────────────────────────────────
|
|
138
|
-
// .failure/ 載入
|
|
139
|
-
// ─────────────────────────────────────────
|
|
140
|
-
|
|
141
|
-
// TASK_2371: entries from Heimdall REVERT/guardian health events and entries about
|
|
142
|
-
// removed systems are stale noise in dispatch prompts. Phase 9 / cognitive checkpoint
|
|
143
|
-
// entries describe the phase ritual archived in TASK_2372.
|
|
144
|
-
const STALE_FAILURE_RE = /Heimdall|guardian health|Kuzu|\bNorn\b|thalamus|\breflex\b|Formation squad|\bREVERT\b|Phase 9|[Cc]ognitive checkpoint/;
|
|
145
|
-
|
|
146
|
-
function loadFailures(opts, cfg = DEFAULT_CONFIG) {
|
|
147
|
-
const indexPath = path.join(cfg.FAILURE_DIR, 'INDEX.yaml');
|
|
148
|
-
if (!fs.existsSync(indexPath)) return [];
|
|
149
|
-
|
|
150
|
-
// 掃描所有子目錄的 FAIL-*.yaml 和 FAIL-*.md
|
|
151
|
-
const results = [];
|
|
152
|
-
const categories = ['agent-execution', 'code-quality', 'architecture', 'pipeline', 'data-integrity'];
|
|
153
|
-
|
|
154
|
-
for (const cat of categories) {
|
|
155
|
-
const catDir = path.join(cfg.FAILURE_DIR, cat);
|
|
156
|
-
if (!fs.existsSync(catDir)) continue;
|
|
157
|
-
|
|
158
|
-
const files = fs.readdirSync(catDir).filter(f => f.startsWith('FAIL-'));
|
|
159
|
-
for (const file of files) {
|
|
160
|
-
const filePath = path.join(catDir, file);
|
|
161
|
-
try {
|
|
162
|
-
const content = fs.readFileSync(filePath, 'utf-8');
|
|
163
|
-
if (STALE_FAILURE_RE.test(content)) continue;
|
|
164
|
-
const entry = parseFailureEntry(content, file, cat);
|
|
165
|
-
if (entry) {
|
|
166
|
-
entry.seq = Number((file.match(/(\d+)/) || [])[1] || 0);
|
|
167
|
-
entry.relevance = scoreRelevance(entry, opts);
|
|
168
|
-
results.push(entry);
|
|
169
|
-
}
|
|
170
|
-
} catch { /* skip unreadable files */ }
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
// Sort by relevance, then filter by task tags/category if provided, cap at MAX_FAILURES
|
|
175
|
-
results.sort((a, b) => b.relevance - a.relevance);
|
|
176
|
-
let filtered = results;
|
|
177
|
-
if (opts.tags && opts.tags.length > 0) {
|
|
178
|
-
const tagSet = new Set(opts.tags.map(t => t.toLowerCase()));
|
|
179
|
-
const tagMatches = results.filter(e => tagSet.has(e.category.replace(/-/g, '_')) || e.keywords.some(k => tagSet.has(k)));
|
|
180
|
-
if (tagMatches.length > 0) filtered = tagMatches;
|
|
181
|
-
}
|
|
182
|
-
// TASK_2371: newest first = highest FAIL number (mtime is checkout time in worktrees; relevance only decides which entries survive the tag filter)
|
|
183
|
-
return filtered.sort((a, b) => b.seq - a.seq).slice(0, cfg.MAX_FAILURES);
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
/**
|
|
187
|
-
* 解析 .failure/ 條目(支援 YAML 和 Markdown 格式)
|
|
188
|
-
*/
|
|
189
|
-
function parseFailureEntry(content, filename, category) {
|
|
190
|
-
// 提取標題
|
|
191
|
-
let title = filename;
|
|
192
|
-
const titleMatch = content.match(/^#\s+\[?(FAIL-\d+)\]?\s*(.*)/m)
|
|
193
|
-
|| content.match(/title:\s*["']?(.+?)["']?\s*$/m);
|
|
194
|
-
if (titleMatch) {
|
|
195
|
-
// Markdown header: use [0] stripped; YAML title: use capture group [1]
|
|
196
|
-
title = titleMatch[0].trim().startsWith('#')
|
|
197
|
-
? titleMatch[0].replace(/^#\s+/, '').trim()
|
|
198
|
-
: (titleMatch[1] || titleMatch[0]).replace(/['"]?/g, '').trim();
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
// 提取 severity
|
|
202
|
-
let severity = 'medium';
|
|
203
|
-
const sevMatch = content.match(/severity:\s*["']?(\w+)["']?/i);
|
|
204
|
-
if (sevMatch) severity = sevMatch[1].toLowerCase();
|
|
205
|
-
|
|
206
|
-
// 提取摘要(取前 3 行非空非標題內容)
|
|
207
|
-
const lines = content.split('\n');
|
|
208
|
-
const summaryLines = [];
|
|
209
|
-
let started = false;
|
|
210
|
-
for (const line of lines) {
|
|
211
|
-
const trimmed = line.trim();
|
|
212
|
-
if (!trimmed || trimmed.startsWith('#') || trimmed.startsWith('_meta') || trimmed.startsWith('---') || /^\w+\s*:/.test(trimmed)) {
|
|
213
|
-
if (started) continue;
|
|
214
|
-
continue;
|
|
215
|
-
}
|
|
216
|
-
started = true;
|
|
217
|
-
summaryLines.push(trimmed);
|
|
218
|
-
if (summaryLines.length >= 3) break;
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
return {
|
|
222
|
-
id: filename.replace(/\.(yaml|md)$/, ''),
|
|
223
|
-
title,
|
|
224
|
-
severity,
|
|
225
|
-
category,
|
|
226
|
-
summary: summaryLines.join(' ').slice(0, 200),
|
|
227
|
-
keywords: extractKeywords(content),
|
|
228
|
-
};
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
// ─────────────────────────────────────────
|
|
232
|
-
// .memory/ 載入
|
|
233
|
-
// ─────────────────────────────────────────
|
|
234
|
-
|
|
235
|
-
function loadProjectMemories(opts, cfg = DEFAULT_CONFIG) {
|
|
236
|
-
if (!fs.existsSync(cfg.MEMORY_REGISTRY)) return [];
|
|
237
|
-
|
|
238
|
-
let registry;
|
|
239
|
-
try {
|
|
240
|
-
registry = JSON.parse(fs.readFileSync(cfg.MEMORY_REGISTRY, 'utf-8'));
|
|
241
|
-
} catch { return []; }
|
|
242
|
-
|
|
243
|
-
const memories = registry.memories || [];
|
|
244
|
-
if (memories.length === 0) return [];
|
|
245
|
-
|
|
246
|
-
// 評分 + 排序
|
|
247
|
-
const scored = memories.map(m => ({
|
|
248
|
-
...m,
|
|
249
|
-
relevance: scoreMemoryRelevance(m, opts),
|
|
250
|
-
}));
|
|
251
|
-
|
|
252
|
-
scored.sort((a, b) => {
|
|
253
|
-
// 先按相關度,再按 importance
|
|
254
|
-
const relDiff = b.relevance - a.relevance;
|
|
255
|
-
if (relDiff !== 0) return relDiff;
|
|
256
|
-
return (b.importance || 0) - (a.importance || 0);
|
|
257
|
-
});
|
|
258
|
-
|
|
259
|
-
// 取前 N 個,importance >= 3 的
|
|
260
|
-
return scored
|
|
261
|
-
.filter(m => (m.importance || 0) >= 3)
|
|
262
|
-
.slice(0, CONFIG.MAX_MEMORIES);
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
// ─────────────────────────────────────────
|
|
266
|
-
// .kenaz/main-memory/ 載入
|
|
267
|
-
// ─────────────────────────────────────────
|
|
268
|
-
|
|
269
|
-
function loadMainMemory(opts, cfg = DEFAULT_CONFIG) {
|
|
270
|
-
if (!fs.existsSync(cfg.MAIN_MEMORY_REGISTRY)) return [];
|
|
271
|
-
|
|
272
|
-
let registry;
|
|
273
|
-
try {
|
|
274
|
-
registry = JSON.parse(fs.readFileSync(cfg.MAIN_MEMORY_REGISTRY, 'utf-8'));
|
|
275
|
-
} catch { return []; }
|
|
276
|
-
|
|
277
|
-
const entries = registry.entries || registry.memories || [];
|
|
278
|
-
if (entries.length === 0) return [];
|
|
279
|
-
|
|
280
|
-
// 按相關度排序
|
|
281
|
-
const scored = entries.map(e => ({
|
|
282
|
-
...e,
|
|
283
|
-
relevance: scoreMainMemoryRelevance(e, opts),
|
|
284
|
-
}));
|
|
285
|
-
|
|
286
|
-
scored.sort((a, b) => b.relevance - a.relevance);
|
|
287
|
-
return scored.slice(0, CONFIG.MAX_MAIN_MEMORY);
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
// ─────────────────────────────────────────
|
|
291
|
-
// 相關度評分
|
|
292
|
-
// ─────────────────────────────────────────
|
|
293
|
-
|
|
294
|
-
/**
|
|
295
|
-
* .failure/ 條目相關度評分
|
|
296
|
-
*/
|
|
297
|
-
function scoreRelevance(entry, opts) {
|
|
298
|
-
let score = 0;
|
|
299
|
-
|
|
300
|
-
// severity 加分
|
|
301
|
-
if (entry.severity === 'critical') score += 3;
|
|
302
|
-
else if (entry.severity === 'high') score += 2;
|
|
303
|
-
else if (entry.severity === 'medium') score += 1;
|
|
304
|
-
|
|
305
|
-
// 關鍵字匹配
|
|
306
|
-
if (opts.role && entry.keywords.includes(opts.role)) score += 2;
|
|
307
|
-
if (opts.taskTitle) {
|
|
308
|
-
const titleLower = opts.taskTitle.toLowerCase();
|
|
309
|
-
for (const kw of entry.keywords) {
|
|
310
|
-
if (titleLower.includes(kw)) score += 1;
|
|
311
|
-
}
|
|
312
|
-
}
|
|
313
|
-
if (opts.tags) {
|
|
314
|
-
for (const tag of opts.tags) {
|
|
315
|
-
if (entry.keywords.includes(tag.toLowerCase())) score += 1;
|
|
316
|
-
}
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
// agent-execution 類別對所有 agent 都相關
|
|
320
|
-
if (entry.category === 'agent-execution') score += 1;
|
|
321
|
-
|
|
322
|
-
return score;
|
|
323
|
-
}
|
|
324
|
-
|
|
325
|
-
/**
|
|
326
|
-
* .memory/ 條目相關度評分
|
|
327
|
-
*/
|
|
328
|
-
function scoreMemoryRelevance(entry, opts) {
|
|
329
|
-
let score = (entry.importance || 0) * 0.5;
|
|
330
|
-
|
|
331
|
-
// failure 類型加分(避免重蹈覆轍)
|
|
332
|
-
if (entry.type === 'failure') score += 2;
|
|
333
|
-
if (entry.type === 'decision') score += 1;
|
|
334
|
-
|
|
335
|
-
// 標題關鍵字匹配
|
|
336
|
-
if (opts.taskTitle && entry.title) {
|
|
337
|
-
const titleWords = opts.taskTitle.toLowerCase().split(/\s+/);
|
|
338
|
-
const entryTitle = entry.title.toLowerCase();
|
|
339
|
-
for (const w of titleWords) {
|
|
340
|
-
if (w.length > 2 && entryTitle.includes(w)) score += 1;
|
|
341
|
-
}
|
|
342
|
-
}
|
|
343
|
-
|
|
344
|
-
return score;
|
|
345
|
-
}
|
|
346
|
-
|
|
347
|
-
/**
|
|
348
|
-
* .kenaz/main-memory/ 條目相關度評分
|
|
349
|
-
*/
|
|
350
|
-
function scoreMainMemoryRelevance(entry, opts) {
|
|
351
|
-
let score = 1;
|
|
352
|
-
|
|
353
|
-
const entryStr = JSON.stringify(entry).toLowerCase();
|
|
354
|
-
|
|
355
|
-
if (opts.role && entryStr.includes(opts.role.toLowerCase())) score += 2;
|
|
356
|
-
if (opts.taskTitle) {
|
|
357
|
-
const words = opts.taskTitle.toLowerCase().split(/\s+/);
|
|
358
|
-
for (const w of words) {
|
|
359
|
-
if (w.length > 2 && entryStr.includes(w)) score += 1;
|
|
360
|
-
}
|
|
361
|
-
}
|
|
362
|
-
|
|
363
|
-
return score;
|
|
364
|
-
}
|
|
365
|
-
|
|
366
|
-
// ─────────────────────────────────────────
|
|
367
|
-
// 格式化輸出
|
|
368
|
-
// ─────────────────────────────────────────
|
|
369
|
-
|
|
370
|
-
function formatFailures(failures) {
|
|
371
|
-
const lines = ['## Known Failures (避免重蹈覆轍)', ''];
|
|
372
|
-
for (const f of failures) {
|
|
373
|
-
const sev = f.severity === 'critical' ? '🔴' : f.severity === 'high' ? '🟠' : '🟡';
|
|
374
|
-
// Extract first sentence as lesson (ends at . or end of summary)
|
|
375
|
-
const lessonMatch = f.summary && f.summary.match(/^[^.!?]+[.!?]/);
|
|
376
|
-
const lesson = lessonMatch ? lessonMatch[0].trim() : f.summary;
|
|
377
|
-
const lessonPart = lesson ? ' — ' + lesson : '';
|
|
378
|
-
lines.push(`- ${sev} **${f.title}**${lessonPart}`);
|
|
379
|
-
}
|
|
380
|
-
lines.push('');
|
|
381
|
-
return lines.join('\n');
|
|
382
|
-
}
|
|
383
|
-
|
|
384
|
-
function formatMemories(memories) {
|
|
385
|
-
const lines = ['## Project Memory (歷史經驗)', ''];
|
|
386
|
-
for (const m of memories) {
|
|
387
|
-
const typeIcon = m.type === 'failure' ? '⚠️' : m.type === 'decision' ? '📌' : m.type === 'pattern' ? '✅' : 'ℹ️';
|
|
388
|
-
lines.push(`- ${typeIcon} [${m.type}] **${m.title}** (importance: ${m.importance || '?'})`);
|
|
389
|
-
}
|
|
390
|
-
lines.push('');
|
|
391
|
-
return lines.join('\n');
|
|
392
|
-
}
|
|
393
|
-
|
|
394
|
-
function formatMainMemory(entries) {
|
|
395
|
-
const lines = ['## Knowledge Base (通用知識)', ''];
|
|
396
|
-
for (const e of entries) {
|
|
397
|
-
const title = e.title || e.id || 'Unknown';
|
|
398
|
-
lines.push(`- 📖 ${title}`);
|
|
399
|
-
if (e.summary) lines.push(` ${e.summary}`);
|
|
400
|
-
}
|
|
401
|
-
lines.push('');
|
|
402
|
-
return lines.join('\n');
|
|
403
|
-
}
|
|
404
|
-
|
|
405
|
-
// ─────────────────────────────────────────
|
|
406
|
-
// 工具函數
|
|
407
|
-
// ─────────────────────────────────────────
|
|
408
|
-
|
|
409
|
-
/**
|
|
410
|
-
* 從文字中提取關鍵字(小寫化)
|
|
411
|
-
*/
|
|
412
|
-
function extractKeywords(text) {
|
|
413
|
-
const words = text.toLowerCase()
|
|
414
|
-
.replace(/[^a-z0-9\u4e00-\u9fff\s_-]/g, ' ')
|
|
415
|
-
.split(/\s+/)
|
|
416
|
-
.filter(w => w.length > 2);
|
|
417
|
-
|
|
418
|
-
// 去重
|
|
419
|
-
return [...new Set(words)];
|
|
420
|
-
}
|
|
421
|
-
|
|
422
|
-
module.exports = { loadMemoryContext, loadFailures, CONFIG };
|