ccjk 14.2.1 → 15.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/README.md +58 -341
- package/dist/cli.js +59 -0
- package/dist/cli.js.map +1 -0
- package/dist/commands/detect.js +15 -0
- package/dist/commands/detect.js.map +1 -0
- package/dist/commands/doctor.js +68 -0
- package/dist/commands/doctor.js.map +1 -0
- package/dist/commands/git-install.js +50 -0
- package/dist/commands/git-install.js.map +1 -0
- package/dist/commands/init.js +102 -0
- package/dist/commands/init.js.map +1 -0
- package/dist/commands/mcp.js +66 -0
- package/dist/commands/mcp.js.map +1 -0
- package/dist/commands/menu.js +33 -0
- package/dist/commands/menu.js.map +1 -0
- package/dist/core/detect.js +24 -0
- package/dist/core/detect.js.map +1 -0
- package/dist/core/lint.js +49 -0
- package/dist/core/lint.js.map +1 -0
- package/dist/core/mcp.js +41 -0
- package/dist/core/mcp.js.map +1 -0
- package/dist/core/paths.js +9 -0
- package/dist/core/paths.js.map +1 -0
- package/dist/core/providers.js +53 -0
- package/dist/core/providers.js.map +1 -0
- package/dist/core/settings.js +31 -0
- package/dist/core/settings.js.map +1 -0
- package/dist/core/slash-templates.js +56 -0
- package/dist/core/slash-templates.js.map +1 -0
- package/dist/core/tools.js +27 -0
- package/dist/core/tools.js.map +1 -0
- package/package.json +43 -164
- package/README.HONEST.md +0 -176
- package/README.en.md +0 -67
- package/README.ja.md +0 -67
- package/README.ko.md +0 -67
- package/README.zh-CN.md +0 -86
- package/bin/ccjk.mjs +0 -5
- package/bin/ccjk.ts +0 -222
- package/dist/chunks/agent-teams.mjs +0 -145
- package/dist/chunks/agent.mjs +0 -1439
- package/dist/chunks/agents.mjs +0 -3783
- package/dist/chunks/api-cli.mjs +0 -135
- package/dist/chunks/api-config-selector.mjs +0 -159
- package/dist/chunks/api-providers.mjs +0 -144
- package/dist/chunks/api.mjs +0 -115
- package/dist/chunks/auto-bootstrap.mjs +0 -358
- package/dist/chunks/auto-fixer.mjs +0 -95
- package/dist/chunks/auto-updater.mjs +0 -507
- package/dist/chunks/banner.mjs +0 -173
- package/dist/chunks/bash.mjs +0 -187
- package/dist/chunks/boost.mjs +0 -474
- package/dist/chunks/brain-config.mjs +0 -75
- package/dist/chunks/brain-status.mjs +0 -89
- package/dist/chunks/ccjk-agents.mjs +0 -416
- package/dist/chunks/ccjk-all.mjs +0 -1046
- package/dist/chunks/ccjk-config.mjs +0 -445
- package/dist/chunks/ccjk-hooks.mjs +0 -1074
- package/dist/chunks/ccjk-mcp.mjs +0 -763
- package/dist/chunks/ccjk-setup.mjs +0 -765
- package/dist/chunks/ccjk-skills.mjs +0 -518
- package/dist/chunks/ccr.mjs +0 -109
- package/dist/chunks/ccu.mjs +0 -40
- package/dist/chunks/check-updates.mjs +0 -117
- package/dist/chunks/claude-code-incremental-manager.mjs +0 -761
- package/dist/chunks/claude-config.mjs +0 -606
- package/dist/chunks/claude-config2.mjs +0 -62
- package/dist/chunks/claude-wrapper.mjs +0 -85
- package/dist/chunks/clavue-config.mjs +0 -1390
- package/dist/chunks/cleanup-migration.mjs +0 -20
- package/dist/chunks/cli-hook.mjs +0 -4096
- package/dist/chunks/cloud-sync.mjs +0 -29
- package/dist/chunks/code-type-resolver.mjs +0 -880
- package/dist/chunks/codex-config-switch.mjs +0 -452
- package/dist/chunks/codex-provider-manager.mjs +0 -238
- package/dist/chunks/codex-uninstaller.mjs +0 -404
- package/dist/chunks/codex.mjs +0 -2141
- package/dist/chunks/commands.mjs +0 -108
- package/dist/chunks/commands2.mjs +0 -421
- package/dist/chunks/commit.mjs +0 -140
- package/dist/chunks/completion.mjs +0 -517
- package/dist/chunks/config-consolidator.mjs +0 -172
- package/dist/chunks/config-switch.mjs +0 -334
- package/dist/chunks/config.mjs +0 -558
- package/dist/chunks/config2.mjs +0 -484
- package/dist/chunks/config3.mjs +0 -486
- package/dist/chunks/constants.mjs +0 -323
- package/dist/chunks/context-opt.mjs +0 -444
- package/dist/chunks/context.mjs +0 -974
- package/dist/chunks/dashboard.mjs +0 -481
- package/dist/chunks/doctor.mjs +0 -1301
- package/dist/chunks/eval.mjs +0 -502
- package/dist/chunks/evolution.mjs +0 -322
- package/dist/chunks/features.mjs +0 -715
- package/dist/chunks/fish.mjs +0 -181
- package/dist/chunks/fs-operations.mjs +0 -180
- package/dist/chunks/health-alerts.mjs +0 -830
- package/dist/chunks/help.mjs +0 -341
- package/dist/chunks/hook-installer.mjs +0 -48
- package/dist/chunks/impact.mjs +0 -651
- package/dist/chunks/index.mjs +0 -23
- package/dist/chunks/index10.mjs +0 -19
- package/dist/chunks/index11.mjs +0 -1171
- package/dist/chunks/index12.mjs +0 -218
- package/dist/chunks/index13.mjs +0 -679
- package/dist/chunks/index14.mjs +0 -1009
- package/dist/chunks/index15.mjs +0 -194
- package/dist/chunks/index2.mjs +0 -7637
- package/dist/chunks/index3.mjs +0 -171
- package/dist/chunks/index4.mjs +0 -26
- package/dist/chunks/index5.mjs +0 -19
- package/dist/chunks/index6.mjs +0 -19092
- package/dist/chunks/index7.mjs +0 -616
- package/dist/chunks/index8.mjs +0 -1602
- package/dist/chunks/index9.mjs +0 -5384
- package/dist/chunks/init.mjs +0 -1911
- package/dist/chunks/installer.mjs +0 -757
- package/dist/chunks/installer2.mjs +0 -103
- package/dist/chunks/interview.mjs +0 -2927
- package/dist/chunks/json-config.mjs +0 -60
- package/dist/chunks/linux.mjs +0 -3863
- package/dist/chunks/macos.mjs +0 -69
- package/dist/chunks/main.mjs +0 -635
- package/dist/chunks/manager.mjs +0 -1048
- package/dist/chunks/marketplace.mjs +0 -265
- package/dist/chunks/mcp-cli.mjs +0 -205
- package/dist/chunks/mcp-performance.mjs +0 -187
- package/dist/chunks/mcp.mjs +0 -667
- package/dist/chunks/memory-check.mjs +0 -2973
- package/dist/chunks/memory-paths.mjs +0 -259
- package/dist/chunks/memory-sync.mjs +0 -209
- package/dist/chunks/memory.mjs +0 -354
- package/dist/chunks/metrics-display.mjs +0 -153
- package/dist/chunks/monitor.mjs +0 -1856
- package/dist/chunks/notification.mjs +0 -1864
- package/dist/chunks/onboarding.mjs +0 -386
- package/dist/chunks/package.mjs +0 -3
- package/dist/chunks/paradigm.mjs +0 -74
- package/dist/chunks/permission-manager.mjs +0 -250
- package/dist/chunks/permissions.mjs +0 -265
- package/dist/chunks/persistence-manager.mjs +0 -801
- package/dist/chunks/persistence.mjs +0 -707
- package/dist/chunks/platform.mjs +0 -395
- package/dist/chunks/plugin.mjs +0 -1936
- package/dist/chunks/powershell.mjs +0 -213
- package/dist/chunks/prompts.mjs +0 -244
- package/dist/chunks/providers.mjs +0 -263
- package/dist/chunks/quick-actions.mjs +0 -335
- package/dist/chunks/quick-provider.mjs +0 -755
- package/dist/chunks/quick-setup.mjs +0 -421
- package/dist/chunks/remote.mjs +0 -497
- package/dist/chunks/research.mjs +0 -1904
- package/dist/chunks/rollback.mjs +0 -38
- package/dist/chunks/session-manager.mjs +0 -1371
- package/dist/chunks/session.mjs +0 -878
- package/dist/chunks/sessions.mjs +0 -106
- package/dist/chunks/silent-updater.mjs +0 -396
- package/dist/chunks/simple-config.mjs +0 -122
- package/dist/chunks/skill.mjs +0 -117
- package/dist/chunks/skill2.mjs +0 -9052
- package/dist/chunks/skills-sync.mjs +0 -1343
- package/dist/chunks/skills.mjs +0 -577
- package/dist/chunks/slash-commands.mjs +0 -208
- package/dist/chunks/smart-guide.mjs +0 -247
- package/dist/chunks/snapshot.mjs +0 -58
- package/dist/chunks/startup.mjs +0 -487
- package/dist/chunks/stats.mjs +0 -191
- package/dist/chunks/status.mjs +0 -471
- package/dist/chunks/team.mjs +0 -63
- package/dist/chunks/thinking.mjs +0 -626
- package/dist/chunks/trace.mjs +0 -57
- package/dist/chunks/uninstall.mjs +0 -852
- package/dist/chunks/update.mjs +0 -174
- package/dist/chunks/upgrade-manager.mjs +0 -204
- package/dist/chunks/upgrade.mjs +0 -133
- package/dist/chunks/version-checker.mjs +0 -891
- package/dist/chunks/vim.mjs +0 -903
- package/dist/chunks/windows.mjs +0 -14
- package/dist/chunks/workflows.mjs +0 -633
- package/dist/chunks/wsl.mjs +0 -129
- package/dist/chunks/zero-config.mjs +0 -871
- package/dist/chunks/zsh.mjs +0 -182
- package/dist/cli.d.mts +0 -1
- package/dist/cli.d.ts +0 -1
- package/dist/cli.mjs +0 -2684
- package/dist/i18n/locales/en/agent-teams.json +0 -18
- package/dist/i18n/locales/en/agentBrowser.json +0 -80
- package/dist/i18n/locales/en/agents.json +0 -135
- package/dist/i18n/locales/en/api.json +0 -63
- package/dist/i18n/locales/en/ccjk-agents.json +0 -33
- package/dist/i18n/locales/en/ccjk-all.json +0 -23
- package/dist/i18n/locales/en/ccjk-skills.json +0 -22
- package/dist/i18n/locales/en/ccjk.json +0 -276
- package/dist/i18n/locales/en/ccr.json +0 -65
- package/dist/i18n/locales/en/claude-md.json +0 -73
- package/dist/i18n/locales/en/cli.json +0 -148
- package/dist/i18n/locales/en/cloud-setup.json +0 -31
- package/dist/i18n/locales/en/cloud-sync.json +0 -147
- package/dist/i18n/locales/en/cloud.json +0 -40
- package/dist/i18n/locales/en/cloudPlugins.json +0 -118
- package/dist/i18n/locales/en/codex.json +0 -184
- package/dist/i18n/locales/en/cometix.json +0 -29
- package/dist/i18n/locales/en/common.json +0 -68
- package/dist/i18n/locales/en/config.json +0 -108
- package/dist/i18n/locales/en/configuration.json +0 -234
- package/dist/i18n/locales/en/context.json +0 -85
- package/dist/i18n/locales/en/dashboard.json +0 -78
- package/dist/i18n/locales/en/errors.json +0 -26
- package/dist/i18n/locales/en/evolution.json +0 -54
- package/dist/i18n/locales/en/hooks.json +0 -74
- package/dist/i18n/locales/en/hooksSync.json +0 -133
- package/dist/i18n/locales/en/installation.json +0 -83
- package/dist/i18n/locales/en/interview.json +0 -104
- package/dist/i18n/locales/en/language.json +0 -19
- package/dist/i18n/locales/en/lsp.json +0 -78
- package/dist/i18n/locales/en/marketplace.json +0 -116
- package/dist/i18n/locales/en/mcp.json +0 -180
- package/dist/i18n/locales/en/memory.json +0 -23
- package/dist/i18n/locales/en/menu.json +0 -299
- package/dist/i18n/locales/en/multi-config.json +0 -79
- package/dist/i18n/locales/en/notification.json +0 -307
- package/dist/i18n/locales/en/permissions.json +0 -95
- package/dist/i18n/locales/en/persistence.json +0 -127
- package/dist/i18n/locales/en/plugins.json +0 -146
- package/dist/i18n/locales/en/quick-actions.json +0 -78
- package/dist/i18n/locales/en/registry.json +0 -54
- package/dist/i18n/locales/en/remote.json +0 -93
- package/dist/i18n/locales/en/sandbox.json +0 -44
- package/dist/i18n/locales/en/setup.json +0 -44
- package/dist/i18n/locales/en/shencha.json +0 -14
- package/dist/i18n/locales/en/skills.json +0 -100
- package/dist/i18n/locales/en/skillsSync.json +0 -74
- package/dist/i18n/locales/en/smartGuide.json +0 -49
- package/dist/i18n/locales/en/stats.json +0 -20
- package/dist/i18n/locales/en/subagent.json +0 -69
- package/dist/i18n/locales/en/superpowers.json +0 -117
- package/dist/i18n/locales/en/team.json +0 -7
- package/dist/i18n/locales/en/thinking.json +0 -65
- package/dist/i18n/locales/en/tools.json +0 -42
- package/dist/i18n/locales/en/uninstall.json +0 -56
- package/dist/i18n/locales/en/updater.json +0 -29
- package/dist/i18n/locales/en/vim.json +0 -169
- package/dist/i18n/locales/en/workflow.json +0 -55
- package/dist/i18n/locales/en/workspace.json +0 -108
- package/dist/i18n/locales/zh-CN/agent-teams.json +0 -18
- package/dist/i18n/locales/zh-CN/agentBrowser.json +0 -80
- package/dist/i18n/locales/zh-CN/agents.json +0 -135
- package/dist/i18n/locales/zh-CN/api.json +0 -63
- package/dist/i18n/locales/zh-CN/ccjk-agents.json +0 -33
- package/dist/i18n/locales/zh-CN/ccjk-all.json +0 -23
- package/dist/i18n/locales/zh-CN/ccjk-skills.json +0 -22
- package/dist/i18n/locales/zh-CN/ccjk.json +0 -276
- package/dist/i18n/locales/zh-CN/ccr.json +0 -65
- package/dist/i18n/locales/zh-CN/claude-md.json +0 -73
- package/dist/i18n/locales/zh-CN/cli.json +0 -148
- package/dist/i18n/locales/zh-CN/cloud-setup.json +0 -31
- package/dist/i18n/locales/zh-CN/cloud-sync.json +0 -147
- package/dist/i18n/locales/zh-CN/cloud.json +0 -40
- package/dist/i18n/locales/zh-CN/cloudPlugins.json +0 -118
- package/dist/i18n/locales/zh-CN/codex.json +0 -184
- package/dist/i18n/locales/zh-CN/cometix.json +0 -29
- package/dist/i18n/locales/zh-CN/common.json +0 -68
- package/dist/i18n/locales/zh-CN/config.json +0 -108
- package/dist/i18n/locales/zh-CN/configuration.json +0 -232
- package/dist/i18n/locales/zh-CN/context.json +0 -85
- package/dist/i18n/locales/zh-CN/dashboard.json +0 -78
- package/dist/i18n/locales/zh-CN/errors.json +0 -26
- package/dist/i18n/locales/zh-CN/evolution.json +0 -54
- package/dist/i18n/locales/zh-CN/hooks.json +0 -74
- package/dist/i18n/locales/zh-CN/hooksSync.json +0 -133
- package/dist/i18n/locales/zh-CN/installation.json +0 -83
- package/dist/i18n/locales/zh-CN/interview.json +0 -104
- package/dist/i18n/locales/zh-CN/language.json +0 -19
- package/dist/i18n/locales/zh-CN/lsp.json +0 -78
- package/dist/i18n/locales/zh-CN/marketplace.json +0 -116
- package/dist/i18n/locales/zh-CN/mcp.json +0 -180
- package/dist/i18n/locales/zh-CN/memory.json +0 -23
- package/dist/i18n/locales/zh-CN/menu.json +0 -299
- package/dist/i18n/locales/zh-CN/multi-config.json +0 -79
- package/dist/i18n/locales/zh-CN/notification.json +0 -307
- package/dist/i18n/locales/zh-CN/permissions.json +0 -95
- package/dist/i18n/locales/zh-CN/persistence.json +0 -127
- package/dist/i18n/locales/zh-CN/plugins.json +0 -146
- package/dist/i18n/locales/zh-CN/quick-actions.json +0 -78
- package/dist/i18n/locales/zh-CN/registry.json +0 -54
- package/dist/i18n/locales/zh-CN/remote.json +0 -93
- package/dist/i18n/locales/zh-CN/sandbox.json +0 -44
- package/dist/i18n/locales/zh-CN/setup.json +0 -44
- package/dist/i18n/locales/zh-CN/shencha.json +0 -14
- package/dist/i18n/locales/zh-CN/skills.json +0 -100
- package/dist/i18n/locales/zh-CN/skillsSync.json +0 -74
- package/dist/i18n/locales/zh-CN/smartGuide.json +0 -49
- package/dist/i18n/locales/zh-CN/stats.json +0 -20
- package/dist/i18n/locales/zh-CN/subagent.json +0 -69
- package/dist/i18n/locales/zh-CN/superpowers.json +0 -117
- package/dist/i18n/locales/zh-CN/team.json +0 -7
- package/dist/i18n/locales/zh-CN/thinking.json +0 -65
- package/dist/i18n/locales/zh-CN/tools.json +0 -42
- package/dist/i18n/locales/zh-CN/uninstall.json +0 -56
- package/dist/i18n/locales/zh-CN/updater.json +0 -29
- package/dist/i18n/locales/zh-CN/vim.json +0 -169
- package/dist/i18n/locales/zh-CN/workflow.json +0 -55
- package/dist/i18n/locales/zh-CN/workspace.json +0 -108
- package/dist/index.d.mts +0 -5658
- package/dist/index.d.ts +0 -5658
- package/dist/index.mjs +0 -3732
- package/dist/shared/ccjk.8oaxX4iR.mjs +0 -90
- package/dist/shared/ccjk.B2U7DsPy.mjs +0 -31
- package/dist/shared/ccjk.B2f-cwUP.mjs +0 -468
- package/dist/shared/ccjk.BAGoDD49.mjs +0 -36
- package/dist/shared/ccjk.BBtCGd_g.mjs +0 -899
- package/dist/shared/ccjk.BFQ7yr5S.mjs +0 -16
- package/dist/shared/ccjk.BLsIiTqO.mjs +0 -449
- package/dist/shared/ccjk.BXv8aYs1.mjs +0 -170
- package/dist/shared/ccjk.BnsY5WxD.mjs +0 -171
- package/dist/shared/ccjk.BoApaI4j.mjs +0 -28
- package/dist/shared/ccjk.Bq8TqZG_.mjs +0 -189
- package/dist/shared/ccjk.BtrioX1Z.mjs +0 -25
- package/dist/shared/ccjk.Bx_rmYfN.mjs +0 -69
- package/dist/shared/ccjk.BzPbSEP2.mjs +0 -115
- package/dist/shared/ccjk.C1Be3aJN.mjs +0 -254
- package/dist/shared/ccjk.C1hANZTu.mjs +0 -19
- package/dist/shared/ccjk.C2jHOZVP.mjs +0 -52
- package/dist/shared/ccjk.C94P8gCY.mjs +0 -283
- package/dist/shared/ccjk.CNhnT6uQ.mjs +0 -636
- package/dist/shared/ccjk.COweQ1RR.mjs +0 -5
- package/dist/shared/ccjk.CTr4yCZ1.mjs +0 -225
- package/dist/shared/ccjk.CfKKcvWy.mjs +0 -126
- package/dist/shared/ccjk.Cjgrln_h.mjs +0 -297
- package/dist/shared/ccjk.CoCHVXl3.mjs +0 -3951
- package/dist/shared/ccjk.CwGZSTAK.mjs +0 -319
- package/dist/shared/ccjk.CxpGa6MC.mjs +0 -2724
- package/dist/shared/ccjk.D-magaEx.mjs +0 -763
- package/dist/shared/ccjk.D0g2ABGg.mjs +0 -171
- package/dist/shared/ccjk.D6ycHbak.mjs +0 -270
- package/dist/shared/ccjk.D75wivnp.mjs +0 -142
- package/dist/shared/ccjk.DDL-4C-k.mjs +0 -100
- package/dist/shared/ccjk.DFRPtmK_.mjs +0 -75
- package/dist/shared/ccjk.DMV3x5Sd.mjs +0 -299
- package/dist/shared/ccjk.DZ2LLOa-.mjs +0 -2195
- package/dist/shared/ccjk.DbigonEQ.mjs +0 -698
- package/dist/shared/ccjk.DcMvE7lf.mjs +0 -618
- package/dist/shared/ccjk.DeWpAShp.mjs +0 -1828
- package/dist/shared/ccjk.DhJ1kyDR.mjs +0 -30
- package/dist/shared/ccjk.DlTXS9rP.mjs +0 -224
- package/dist/shared/ccjk.DopKzo3z.mjs +0 -305
- package/dist/shared/ccjk.DsZsc4LR.mjs +0 -1280
- package/dist/shared/ccjk.DuzJZlgj.mjs +0 -418
- package/dist/shared/ccjk.Dxgd2vjc.mjs +0 -444
- package/dist/shared/ccjk.J8YiPsOw.mjs +0 -259
- package/dist/shared/ccjk.KfSWcGlE.mjs +0 -38
- package/dist/shared/ccjk.MwtjAULc.mjs +0 -1447
- package/dist/shared/ccjk.OJKHVSOb.mjs +0 -2005
- package/dist/shared/ccjk.OTnevPNE.mjs +0 -225
- package/dist/shared/ccjk.RyizuzOI.mjs +0 -21
- package/dist/shared/ccjk.T_cX87dY.mjs +0 -15
- package/dist/shared/ccjk.bQ7Dh1g4.mjs +0 -249
- package/dist/shared/ccjk.gDEDGD_t.mjs +0 -38
- package/dist/shared/ccjk.hoqrwWdN.mjs +0 -333
- package/dist/shared/ccjk.i_vn-9C3.mjs +0 -317
- package/dist/shared/ccjk.lG3ccFjm.mjs +0 -885
- package/dist/shared/ccjk.wLJHO0Af.mjs +0 -244
- package/dist/shared/ccjk.y-a_1vK4.mjs +0 -5127
- package/dist/templates/agents/README.md +0 -78
- package/dist/templates/agents/fullstack-developer.json +0 -70
- package/dist/templates/agents/go-expert.json +0 -69
- package/dist/templates/agents/index.json +0 -64
- package/dist/templates/agents/python-expert.json +0 -69
- package/dist/templates/agents/react-specialist.json +0 -69
- package/dist/templates/agents/testing-automation-expert.json +0 -70
- package/dist/templates/agents/typescript-architect.json +0 -69
- package/dist/templates/claude-code/common/settings.json +0 -109
- package/dist/templates/common/error-prevention.md +0 -267
- package/dist/templates/common/karpathy-baseline.md +0 -83
- package/dist/templates/common/output-styles/zh-CN/carmack-mode.md +0 -381
- package/dist/templates/common/output-styles/zh-CN/dhh-mode.md +0 -265
- package/dist/templates/common/output-styles/zh-CN/evan-you-mode.md +0 -539
- package/dist/templates/common/output-styles/zh-CN/jobs-mode.md +0 -369
- package/dist/templates/common/output-styles/zh-CN/linus-mode.md +0 -135
- package/dist/templates/common/output-styles/zh-CN/uncle-bob-mode.md +0 -221
- package/dist/templates/common/workflow/continuousDelivery/en/continuous-delivery.md +0 -628
- package/dist/templates/common/workflow/continuousDelivery/zh-CN/continuous-delivery.md +0 -628
- package/dist/templates/common/workflow/essential/en/agents/ccjk-config-agent.md +0 -187
- package/dist/templates/common/workflow/essential/en/agents/ccjk-mcp-agent.md +0 -191
- package/dist/templates/common/workflow/essential/en/agents/ccjk-skill-agent.md +0 -249
- package/dist/templates/common/workflow/essential/en/agents/ccjk-workflow-agent.md +0 -277
- package/dist/templates/common/workflow/essential/en/agents/get-current-datetime.md +0 -29
- package/dist/templates/common/workflow/essential/en/agents/init-architect.md +0 -115
- package/dist/templates/common/workflow/essential/en/agents/ui-ux-designer.md +0 -91
- package/dist/templates/common/workflow/essential/en/feat.md +0 -92
- package/dist/templates/common/workflow/essential/en/goal.md +0 -147
- package/dist/templates/common/workflow/essential/en/init-project.md +0 -53
- package/dist/templates/common/workflow/essential/zh-CN/agents/get-current-datetime.md +0 -29
- package/dist/templates/common/workflow/essential/zh-CN/agents/init-architect.md +0 -115
- package/dist/templates/common/workflow/essential/zh-CN/agents/ui-ux-designer.md +0 -91
- package/dist/templates/common/workflow/essential/zh-CN/feat.md +0 -315
- package/dist/templates/common/workflow/essential/zh-CN/goal.md +0 -146
- package/dist/templates/common/workflow/essential/zh-CN/init-project.md +0 -53
- package/dist/templates/common/workflow/git/en/git-cleanBranches.md +0 -102
- package/dist/templates/common/workflow/git/en/git-commit.md +0 -205
- package/dist/templates/common/workflow/git/en/git-rollback.md +0 -90
- package/dist/templates/common/workflow/git/en/git-worktree.md +0 -276
- package/dist/templates/common/workflow/git/zh-CN/git-cleanBranches.md +0 -102
- package/dist/templates/common/workflow/git/zh-CN/git-commit.md +0 -205
- package/dist/templates/common/workflow/git/zh-CN/git-rollback.md +0 -90
- package/dist/templates/common/workflow/git/zh-CN/git-worktree.md +0 -276
- package/dist/templates/common/workflow/interview/en/interview.md +0 -67
- package/dist/templates/common/workflow/interview/zh-CN/interview.md +0 -67
- package/dist/templates/common/workflow/linearMethod/en/linear-method.md +0 -651
- package/dist/templates/common/workflow/linearMethod/zh-CN/linear-method.md +0 -752
- package/dist/templates/common/workflow/refactoringMaster/en/refactoring-master.md +0 -516
- package/dist/templates/common/workflow/refactoringMaster/zh-CN/refactoring-master.md +0 -812
- package/dist/templates/common/workflow/sixStep/en/workflow.md +0 -83
- package/dist/templates/common/workflow/sixStep/zh-CN/workflow.md +0 -359
- package/dist/templates/common/workflow/specFirstTDD/en/spec-first-tdd.md +0 -364
- package/dist/templates/common/workflow/specFirstTDD/zh-CN/spec-first-tdd.md +0 -366
- package/dist/templates/hooks/README.md +0 -212
- package/dist/templates/hooks/git-workflow-hooks.md +0 -551
- package/dist/templates/hooks/post-test/coverage.json +0 -21
- package/dist/templates/hooks/post-test/summary.json +0 -21
- package/dist/templates/hooks/post-test-coverage.md +0 -434
- package/dist/templates/hooks/pre-commit/eslint.json +0 -22
- package/dist/templates/hooks/pre-commit/prettier.json +0 -22
- package/dist/templates/hooks/pre-commit-black.md +0 -274
- package/dist/templates/hooks/pre-commit-eslint.md +0 -153
- package/dist/templates/hooks/pre-commit-gofmt.md +0 -284
- package/dist/templates/hooks/pre-commit-prettier.md +0 -212
- package/dist/templates/hooks/pre-commit-type-check.md +0 -377
- package/dist/templates/skills/ccjk-init.md +0 -154
- package/dist/templates/skills/ccjk-mcp-setup.md +0 -205
- package/dist/templates/skills/ccjk-troubleshoot.md +0 -228
- package/dist/templates/skills/django-patterns.md +0 -1016
- package/dist/templates/skills/git-workflow.md +0 -748
- package/dist/templates/skills/go-idioms.md +0 -963
- package/dist/templates/skills/index.json +0 -132
- package/dist/templates/skills/nextjs-optimization.md +0 -694
- package/dist/templates/skills/python-pep8.md +0 -852
- package/dist/templates/skills/react-patterns.md +0 -686
- package/dist/templates/skills/rust-patterns.md +0 -1057
- package/dist/templates/skills/security-best-practices.md +0 -1413
- package/dist/templates/skills/testing-best-practices.md +0 -1315
- package/dist/templates/skills/ts-best-practices.md +0 -354
- package/templates/agents/README.md +0 -78
- package/templates/agents/fullstack-developer.json +0 -70
- package/templates/agents/go-expert.json +0 -69
- package/templates/agents/index.json +0 -64
- package/templates/agents/python-expert.json +0 -69
- package/templates/agents/react-specialist.json +0 -69
- package/templates/agents/testing-automation-expert.json +0 -70
- package/templates/agents/typescript-architect.json +0 -69
- package/templates/claude-code/common/settings.json +0 -109
- package/templates/common/error-prevention.md +0 -267
- package/templates/common/karpathy-baseline.md +0 -83
- package/templates/common/output-styles/zh-CN/carmack-mode.md +0 -381
- package/templates/common/output-styles/zh-CN/dhh-mode.md +0 -265
- package/templates/common/output-styles/zh-CN/evan-you-mode.md +0 -539
- package/templates/common/output-styles/zh-CN/jobs-mode.md +0 -369
- package/templates/common/output-styles/zh-CN/linus-mode.md +0 -135
- package/templates/common/output-styles/zh-CN/uncle-bob-mode.md +0 -221
- package/templates/common/workflow/continuousDelivery/en/continuous-delivery.md +0 -628
- package/templates/common/workflow/continuousDelivery/zh-CN/continuous-delivery.md +0 -628
- package/templates/common/workflow/essential/en/agents/ccjk-config-agent.md +0 -187
- package/templates/common/workflow/essential/en/agents/ccjk-mcp-agent.md +0 -191
- package/templates/common/workflow/essential/en/agents/ccjk-skill-agent.md +0 -249
- package/templates/common/workflow/essential/en/agents/ccjk-workflow-agent.md +0 -277
- package/templates/common/workflow/essential/en/agents/get-current-datetime.md +0 -29
- package/templates/common/workflow/essential/en/agents/init-architect.md +0 -115
- package/templates/common/workflow/essential/en/agents/ui-ux-designer.md +0 -91
- package/templates/common/workflow/essential/en/feat.md +0 -92
- package/templates/common/workflow/essential/en/goal.md +0 -147
- package/templates/common/workflow/essential/en/init-project.md +0 -53
- package/templates/common/workflow/essential/zh-CN/agents/get-current-datetime.md +0 -29
- package/templates/common/workflow/essential/zh-CN/agents/init-architect.md +0 -115
- package/templates/common/workflow/essential/zh-CN/agents/ui-ux-designer.md +0 -91
- package/templates/common/workflow/essential/zh-CN/feat.md +0 -315
- package/templates/common/workflow/essential/zh-CN/goal.md +0 -146
- package/templates/common/workflow/essential/zh-CN/init-project.md +0 -53
- package/templates/common/workflow/git/en/git-cleanBranches.md +0 -102
- package/templates/common/workflow/git/en/git-commit.md +0 -205
- package/templates/common/workflow/git/en/git-rollback.md +0 -90
- package/templates/common/workflow/git/en/git-worktree.md +0 -276
- package/templates/common/workflow/git/zh-CN/git-cleanBranches.md +0 -102
- package/templates/common/workflow/git/zh-CN/git-commit.md +0 -205
- package/templates/common/workflow/git/zh-CN/git-rollback.md +0 -90
- package/templates/common/workflow/git/zh-CN/git-worktree.md +0 -276
- package/templates/common/workflow/interview/en/interview.md +0 -67
- package/templates/common/workflow/interview/zh-CN/interview.md +0 -67
- package/templates/common/workflow/linearMethod/en/linear-method.md +0 -651
- package/templates/common/workflow/linearMethod/zh-CN/linear-method.md +0 -752
- package/templates/common/workflow/refactoringMaster/en/refactoring-master.md +0 -516
- package/templates/common/workflow/refactoringMaster/zh-CN/refactoring-master.md +0 -812
- package/templates/common/workflow/sixStep/en/workflow.md +0 -83
- package/templates/common/workflow/sixStep/zh-CN/workflow.md +0 -359
- package/templates/common/workflow/specFirstTDD/en/spec-first-tdd.md +0 -364
- package/templates/common/workflow/specFirstTDD/zh-CN/spec-first-tdd.md +0 -366
- package/templates/hooks/README.md +0 -212
- package/templates/hooks/git-workflow-hooks.md +0 -551
- package/templates/hooks/post-test/coverage.json +0 -21
- package/templates/hooks/post-test/summary.json +0 -21
- package/templates/hooks/post-test-coverage.md +0 -434
- package/templates/hooks/pre-commit/eslint.json +0 -22
- package/templates/hooks/pre-commit/prettier.json +0 -22
- package/templates/hooks/pre-commit-black.md +0 -274
- package/templates/hooks/pre-commit-eslint.md +0 -153
- package/templates/hooks/pre-commit-gofmt.md +0 -284
- package/templates/hooks/pre-commit-prettier.md +0 -212
- package/templates/hooks/pre-commit-type-check.md +0 -377
- package/templates/skills/basic.hbs +0 -72
- package/templates/skills/ccjk-init.md +0 -154
- package/templates/skills/ccjk-mcp-setup.md +0 -205
- package/templates/skills/ccjk-troubleshoot.md +0 -228
- package/templates/skills/code-refactor.hbs +0 -133
- package/templates/skills/code-review.hbs +0 -141
- package/templates/skills/django-patterns.md +0 -1016
- package/templates/skills/git-workflow.md +0 -748
- package/templates/skills/go-idioms.md +0 -963
- package/templates/skills/index.json +0 -132
- package/templates/skills/nextjs-optimization.md +0 -694
- package/templates/skills/python-pep8.md +0 -852
- package/templates/skills/react-patterns.md +0 -686
- package/templates/skills/rust-patterns.md +0 -1057
- package/templates/skills/security-best-practices.md +0 -1413
- package/templates/skills/testing-best-practices.md +0 -1315
- package/templates/skills/ts-best-practices.md +0 -354
- package/templates/skills/type-fix.hbs +0 -132
|
@@ -1,1447 +0,0 @@
|
|
|
1
|
-
import { existsSync, mkdirSync, rmSync, readFileSync, readdirSync, writeFileSync } from 'node:fs';
|
|
2
|
-
import { tmpdir, homedir } from 'node:os';
|
|
3
|
-
import { x as K } from '../chunks/main.mjs';
|
|
4
|
-
import { CCJK_PLUGINS_DIR, CCJK_SKILLS_DIR, CLAUDE_AGENTS_DIR, CCJK_CONFIG_DIR } from '../chunks/constants.mjs';
|
|
5
|
-
import { w as writeAgentFile, g as getAgentsDir } from './ccjk.CfKKcvWy.mjs';
|
|
6
|
-
import { j as join, d as dirname } from './ccjk.bQ7Dh1g4.mjs';
|
|
7
|
-
import { spawn } from 'node:child_process';
|
|
8
|
-
import { g as getSkillParser } from './ccjk.i_vn-9C3.mjs';
|
|
9
|
-
|
|
10
|
-
const DEFAULT_MIN_CONFIDENCE = 0.6;
|
|
11
|
-
const PATTERN_WEIGHT = 0.4;
|
|
12
|
-
const KEYWORD_WEIGHT = 0.3;
|
|
13
|
-
const CONTEXT_WEIGHT = 0.3;
|
|
14
|
-
class IntentEngine {
|
|
15
|
-
rules = /* @__PURE__ */ new Map();
|
|
16
|
-
contextCache = /* @__PURE__ */ new Map();
|
|
17
|
-
cacheTTL = 5e3;
|
|
18
|
-
// 5 seconds
|
|
19
|
-
constructor() {
|
|
20
|
-
}
|
|
21
|
-
// ==========================================================================
|
|
22
|
-
// Rule Management
|
|
23
|
-
// ==========================================================================
|
|
24
|
-
/**
|
|
25
|
-
* Register an intent rule
|
|
26
|
-
*/
|
|
27
|
-
registerRule(rule) {
|
|
28
|
-
this.rules.set(rule.id, rule);
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* Register multiple intent rules
|
|
32
|
-
*/
|
|
33
|
-
registerRules(rules) {
|
|
34
|
-
for (const rule of rules) {
|
|
35
|
-
this.registerRule(rule);
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* Unregister an intent rule
|
|
40
|
-
*/
|
|
41
|
-
unregisterRule(ruleId) {
|
|
42
|
-
this.rules.delete(ruleId);
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* Unregister all rules for a plugin
|
|
46
|
-
*/
|
|
47
|
-
unregisterPluginRules(pluginId) {
|
|
48
|
-
for (const [id, rule] of this.rules) {
|
|
49
|
-
if (rule.pluginId === pluginId) {
|
|
50
|
-
this.rules.delete(id);
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* Get all registered rules
|
|
56
|
-
*/
|
|
57
|
-
getRules() {
|
|
58
|
-
return Array.from(this.rules.values());
|
|
59
|
-
}
|
|
60
|
-
// ==========================================================================
|
|
61
|
-
// Intent Detection
|
|
62
|
-
// ==========================================================================
|
|
63
|
-
/**
|
|
64
|
-
* Detect intent from user input and context
|
|
65
|
-
*
|
|
66
|
-
* @param userInput - User's input text
|
|
67
|
-
* @param cwd - Current working directory
|
|
68
|
-
* @returns Array of intent matches sorted by confidence
|
|
69
|
-
*/
|
|
70
|
-
async detect(userInput, cwd) {
|
|
71
|
-
const context = await this.buildContext(userInput, cwd);
|
|
72
|
-
const matches = [];
|
|
73
|
-
for (const rule of this.rules.values()) {
|
|
74
|
-
const match = this.matchRule(rule, context);
|
|
75
|
-
if (match && match.confidence >= (rule.minConfidence ?? DEFAULT_MIN_CONFIDENCE)) {
|
|
76
|
-
matches.push(match);
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
matches.sort((a, b) => {
|
|
80
|
-
const confDiff = b.confidence - a.confidence;
|
|
81
|
-
if (Math.abs(confDiff) > 0.1) {
|
|
82
|
-
return confDiff;
|
|
83
|
-
}
|
|
84
|
-
const ruleA = this.rules.get(a.intentId);
|
|
85
|
-
const ruleB = this.rules.get(b.intentId);
|
|
86
|
-
return (ruleB?.priority ?? 0) - (ruleA?.priority ?? 0);
|
|
87
|
-
});
|
|
88
|
-
return matches;
|
|
89
|
-
}
|
|
90
|
-
/**
|
|
91
|
-
* Get the best matching intent
|
|
92
|
-
*/
|
|
93
|
-
async detectBest(userInput, cwd) {
|
|
94
|
-
const matches = await this.detect(userInput, cwd);
|
|
95
|
-
return matches.length > 0 ? matches[0] : null;
|
|
96
|
-
}
|
|
97
|
-
/**
|
|
98
|
-
* Check if any intent should auto-execute
|
|
99
|
-
*/
|
|
100
|
-
async detectAutoExecute(userInput, cwd) {
|
|
101
|
-
const matches = await this.detect(userInput, cwd);
|
|
102
|
-
return matches.find((m) => m.autoExecute && m.confidence >= 0.8) ?? null;
|
|
103
|
-
}
|
|
104
|
-
// ==========================================================================
|
|
105
|
-
// Context Building
|
|
106
|
-
// ==========================================================================
|
|
107
|
-
/**
|
|
108
|
-
* Build detection context from user input and environment
|
|
109
|
-
*/
|
|
110
|
-
async buildContext(userInput, cwd) {
|
|
111
|
-
const [gitStatus, projectType, activeSignals] = await Promise.all([
|
|
112
|
-
this.detectGitStatus(cwd),
|
|
113
|
-
this.detectProjectType(cwd),
|
|
114
|
-
this.detectActiveSignals(cwd)
|
|
115
|
-
]);
|
|
116
|
-
return {
|
|
117
|
-
userInput,
|
|
118
|
-
cwd,
|
|
119
|
-
gitStatus,
|
|
120
|
-
projectType,
|
|
121
|
-
activeSignals
|
|
122
|
-
};
|
|
123
|
-
}
|
|
124
|
-
/**
|
|
125
|
-
* Detect git status
|
|
126
|
-
*/
|
|
127
|
-
async detectGitStatus(cwd) {
|
|
128
|
-
const isRepo = existsSync(join(cwd, ".git"));
|
|
129
|
-
if (!isRepo) {
|
|
130
|
-
return { isRepo: false, hasChanges: false, hasStaged: false };
|
|
131
|
-
}
|
|
132
|
-
try {
|
|
133
|
-
const statusResult = await K("git", ["status", "--porcelain"], { nodeOptions: { cwd } });
|
|
134
|
-
const hasChanges = statusResult.stdout.trim().length > 0;
|
|
135
|
-
const stagedResult = await K("git", ["diff", "--cached", "--name-only"], { nodeOptions: { cwd } });
|
|
136
|
-
const hasStaged = stagedResult.stdout.trim().length > 0;
|
|
137
|
-
const branchResult = await K("git", ["branch", "--show-current"], { nodeOptions: { cwd } });
|
|
138
|
-
const branch = branchResult.stdout.trim();
|
|
139
|
-
const remoteResult = await K("git", ["remote", "get-url", "origin"], { nodeOptions: { cwd } });
|
|
140
|
-
const remote = remoteResult.stdout.trim() || void 0;
|
|
141
|
-
return { isRepo, hasChanges, hasStaged, branch, remote };
|
|
142
|
-
} catch {
|
|
143
|
-
return { isRepo, hasChanges: false, hasStaged: false };
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
/**
|
|
147
|
-
* Detect project type from files
|
|
148
|
-
*/
|
|
149
|
-
async detectProjectType(cwd) {
|
|
150
|
-
if (existsSync(join(cwd, "next.config.js")) || existsSync(join(cwd, "next.config.mjs")) || existsSync(join(cwd, "next.config.ts"))) {
|
|
151
|
-
return "nextjs";
|
|
152
|
-
}
|
|
153
|
-
if (existsSync(join(cwd, "vue.config.js")) || existsSync(join(cwd, "vite.config.ts"))) {
|
|
154
|
-
const pkgPath2 = join(cwd, "package.json");
|
|
155
|
-
if (existsSync(pkgPath2)) {
|
|
156
|
-
try {
|
|
157
|
-
const pkg = await import(pkgPath2);
|
|
158
|
-
if (pkg.dependencies?.vue || pkg.devDependencies?.vue) {
|
|
159
|
-
return "vue";
|
|
160
|
-
}
|
|
161
|
-
} catch {
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
const pkgPath = join(cwd, "package.json");
|
|
166
|
-
if (existsSync(pkgPath)) {
|
|
167
|
-
try {
|
|
168
|
-
const pkg = await import(pkgPath);
|
|
169
|
-
if (pkg.dependencies?.react || pkg.devDependencies?.react) {
|
|
170
|
-
return "react";
|
|
171
|
-
}
|
|
172
|
-
} catch {
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
if (existsSync(join(cwd, "tsconfig.json"))) {
|
|
176
|
-
return "typescript";
|
|
177
|
-
}
|
|
178
|
-
if (existsSync(join(cwd, "package.json"))) {
|
|
179
|
-
return "nodejs";
|
|
180
|
-
}
|
|
181
|
-
if (existsSync(join(cwd, "requirements.txt")) || existsSync(join(cwd, "pyproject.toml"))) {
|
|
182
|
-
return "python";
|
|
183
|
-
}
|
|
184
|
-
if (existsSync(join(cwd, "Cargo.toml"))) {
|
|
185
|
-
return "rust";
|
|
186
|
-
}
|
|
187
|
-
if (existsSync(join(cwd, "go.mod"))) {
|
|
188
|
-
return "go";
|
|
189
|
-
}
|
|
190
|
-
return "unknown";
|
|
191
|
-
}
|
|
192
|
-
/**
|
|
193
|
-
* Detect active context signals
|
|
194
|
-
*/
|
|
195
|
-
async detectActiveSignals(cwd) {
|
|
196
|
-
const signals = [];
|
|
197
|
-
const gitStatus = await this.detectGitStatus(cwd);
|
|
198
|
-
if (gitStatus.isRepo) {
|
|
199
|
-
signals.push("git_is_repo");
|
|
200
|
-
if (gitStatus.hasChanges)
|
|
201
|
-
signals.push("git_has_changes");
|
|
202
|
-
if (gitStatus.hasStaged)
|
|
203
|
-
signals.push("git_has_staged");
|
|
204
|
-
if (gitStatus.remote)
|
|
205
|
-
signals.push("git_has_remote");
|
|
206
|
-
}
|
|
207
|
-
if (existsSync(join(cwd, "package.json")))
|
|
208
|
-
signals.push("has_package_json");
|
|
209
|
-
if (existsSync(join(cwd, "tsconfig.json")))
|
|
210
|
-
signals.push("has_tsconfig");
|
|
211
|
-
if (existsSync(join(cwd, "Dockerfile")) || existsSync(join(cwd, "docker-compose.yml")))
|
|
212
|
-
signals.push("has_dockerfile");
|
|
213
|
-
if (existsSync(join(cwd, "tests")) || existsSync(join(cwd, "__tests__")) || existsSync(join(cwd, "test"))) {
|
|
214
|
-
signals.push("has_tests");
|
|
215
|
-
}
|
|
216
|
-
if (cwd.includes("/src") || existsSync(join(cwd, "src"))) {
|
|
217
|
-
signals.push("in_src_directory");
|
|
218
|
-
}
|
|
219
|
-
return signals;
|
|
220
|
-
}
|
|
221
|
-
// ==========================================================================
|
|
222
|
-
// Rule Matching
|
|
223
|
-
// ==========================================================================
|
|
224
|
-
/**
|
|
225
|
-
* Match a single rule against context
|
|
226
|
-
*/
|
|
227
|
-
matchRule(rule, context) {
|
|
228
|
-
const matchedPatterns = [];
|
|
229
|
-
const matchedSignals = [];
|
|
230
|
-
let patternScore = 0;
|
|
231
|
-
for (const pattern of rule.patterns) {
|
|
232
|
-
try {
|
|
233
|
-
const regex = new RegExp(pattern, "i");
|
|
234
|
-
if (regex.test(context.userInput)) {
|
|
235
|
-
matchedPatterns.push(pattern);
|
|
236
|
-
patternScore += 1 / rule.patterns.length;
|
|
237
|
-
}
|
|
238
|
-
} catch {
|
|
239
|
-
if (context.userInput.toLowerCase().includes(pattern.toLowerCase())) {
|
|
240
|
-
matchedPatterns.push(pattern);
|
|
241
|
-
patternScore += 1 / rule.patterns.length;
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
let keywordScore = 0;
|
|
246
|
-
const inputLower = context.userInput.toLowerCase();
|
|
247
|
-
for (const keyword of rule.keywords) {
|
|
248
|
-
if (inputLower.includes(keyword.toLowerCase())) {
|
|
249
|
-
keywordScore += 1 / rule.keywords.length;
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
let contextScore = 0;
|
|
253
|
-
if (rule.contextSignals.length > 0) {
|
|
254
|
-
for (const signal of rule.contextSignals) {
|
|
255
|
-
if (context.activeSignals.includes(signal)) {
|
|
256
|
-
matchedSignals.push(signal);
|
|
257
|
-
contextScore += 1 / rule.contextSignals.length;
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
} else {
|
|
261
|
-
contextScore = 1;
|
|
262
|
-
}
|
|
263
|
-
let fileBonus = 0;
|
|
264
|
-
if (rule.filePatterns && rule.filePatterns.length > 0) {
|
|
265
|
-
for (const pattern of rule.filePatterns) {
|
|
266
|
-
if (existsSync(join(context.cwd, pattern))) {
|
|
267
|
-
fileBonus += 0.1;
|
|
268
|
-
}
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
const confidence = Math.min(1, patternScore * PATTERN_WEIGHT + keywordScore * KEYWORD_WEIGHT + contextScore * CONTEXT_WEIGHT + fileBonus);
|
|
272
|
-
if (patternScore === 0 && keywordScore === 0) {
|
|
273
|
-
return null;
|
|
274
|
-
}
|
|
275
|
-
return {
|
|
276
|
-
pluginId: rule.pluginId,
|
|
277
|
-
intentId: rule.id,
|
|
278
|
-
confidence,
|
|
279
|
-
matchedPatterns,
|
|
280
|
-
matchedSignals,
|
|
281
|
-
suggestedAction: rule.name,
|
|
282
|
-
autoExecute: rule.autoExecute && confidence >= 0.8
|
|
283
|
-
};
|
|
284
|
-
}
|
|
285
|
-
// ==========================================================================
|
|
286
|
-
// Cache Management
|
|
287
|
-
// ==========================================================================
|
|
288
|
-
/**
|
|
289
|
-
* Clear context cache
|
|
290
|
-
*/
|
|
291
|
-
clearCache() {
|
|
292
|
-
this.contextCache.clear();
|
|
293
|
-
}
|
|
294
|
-
/**
|
|
295
|
-
* Get cached value or compute
|
|
296
|
-
*/
|
|
297
|
-
async getCachedOrCompute(key, compute) {
|
|
298
|
-
const cached = this.contextCache.get(key);
|
|
299
|
-
if (cached && Date.now() - cached.timestamp < this.cacheTTL) {
|
|
300
|
-
return cached.value;
|
|
301
|
-
}
|
|
302
|
-
const value = await compute();
|
|
303
|
-
this.contextCache.set(key, { value, timestamp: Date.now() });
|
|
304
|
-
return value;
|
|
305
|
-
}
|
|
306
|
-
}
|
|
307
|
-
const DEFAULT_INTENT_RULES = [
|
|
308
|
-
// Git Commit Intent
|
|
309
|
-
{
|
|
310
|
-
id: "intent:git-commit",
|
|
311
|
-
name: { "en": "Git Commit", "zh-CN": "Git \u63D0\u4EA4" },
|
|
312
|
-
patterns: [
|
|
313
|
-
"\u63D0\u4EA4.*\u4EE3\u7801",
|
|
314
|
-
"\u63D0\u4EA4.*\u66F4\u6539",
|
|
315
|
-
"\u63D0\u4EA4.*\u4FEE\u6539",
|
|
316
|
-
"commit.*changes",
|
|
317
|
-
"commit.*code",
|
|
318
|
-
"save.*changes",
|
|
319
|
-
"\u4FDD\u5B58.*\u4FEE\u6539"
|
|
320
|
-
],
|
|
321
|
-
keywords: ["commit", "\u63D0\u4EA4", "save", "push", "\u4FDD\u5B58"],
|
|
322
|
-
contextSignals: ["git_is_repo", "git_has_changes"],
|
|
323
|
-
filePatterns: [".git/"],
|
|
324
|
-
priority: 90,
|
|
325
|
-
pluginId: "git-helper",
|
|
326
|
-
skillId: "smart-commit",
|
|
327
|
-
autoExecute: false
|
|
328
|
-
},
|
|
329
|
-
// Code Review Intent
|
|
330
|
-
{
|
|
331
|
-
id: "intent:code-review",
|
|
332
|
-
name: { "en": "Code Review", "zh-CN": "\u4EE3\u7801\u5BA1\u67E5" },
|
|
333
|
-
patterns: [
|
|
334
|
-
"\u5BA1\u67E5.*\u4EE3\u7801",
|
|
335
|
-
"review.*code",
|
|
336
|
-
"\u68C0\u67E5.*\u4EE3\u7801",
|
|
337
|
-
"check.*code",
|
|
338
|
-
"\u4EE3\u7801.*\u95EE\u9898"
|
|
339
|
-
],
|
|
340
|
-
keywords: ["review", "\u5BA1\u67E5", "check", "\u68C0\u67E5", "lint"],
|
|
341
|
-
contextSignals: ["git_has_changes", "in_src_directory"],
|
|
342
|
-
priority: 85,
|
|
343
|
-
pluginId: "code-reviewer",
|
|
344
|
-
autoExecute: false
|
|
345
|
-
},
|
|
346
|
-
// Test Generation Intent
|
|
347
|
-
{
|
|
348
|
-
id: "intent:generate-tests",
|
|
349
|
-
name: { "en": "Generate Tests", "zh-CN": "\u751F\u6210\u6D4B\u8BD5" },
|
|
350
|
-
patterns: [
|
|
351
|
-
"\u5199.*\u6D4B\u8BD5",
|
|
352
|
-
"\u751F\u6210.*\u6D4B\u8BD5",
|
|
353
|
-
"write.*test",
|
|
354
|
-
"generate.*test",
|
|
355
|
-
"create.*test",
|
|
356
|
-
"\u6DFB\u52A0.*\u6D4B\u8BD5"
|
|
357
|
-
],
|
|
358
|
-
keywords: ["test", "\u6D4B\u8BD5", "spec", "jest", "vitest"],
|
|
359
|
-
contextSignals: ["has_package_json", "has_tests"],
|
|
360
|
-
priority: 80,
|
|
361
|
-
pluginId: "test-generator",
|
|
362
|
-
autoExecute: false
|
|
363
|
-
},
|
|
364
|
-
// Documentation Intent
|
|
365
|
-
{
|
|
366
|
-
id: "intent:generate-docs",
|
|
367
|
-
name: { "en": "Generate Documentation", "zh-CN": "\u751F\u6210\u6587\u6863" },
|
|
368
|
-
patterns: [
|
|
369
|
-
"\u5199.*\u6587\u6863",
|
|
370
|
-
"\u751F\u6210.*\u6587\u6863",
|
|
371
|
-
"write.*doc",
|
|
372
|
-
"generate.*doc",
|
|
373
|
-
"\u6DFB\u52A0.*\u6CE8\u91CA",
|
|
374
|
-
"add.*comment"
|
|
375
|
-
],
|
|
376
|
-
keywords: ["doc", "\u6587\u6863", "readme", "comment", "\u6CE8\u91CA"],
|
|
377
|
-
contextSignals: ["in_src_directory"],
|
|
378
|
-
priority: 75,
|
|
379
|
-
pluginId: "doc-generator",
|
|
380
|
-
autoExecute: false
|
|
381
|
-
},
|
|
382
|
-
// Deploy Intent
|
|
383
|
-
{
|
|
384
|
-
id: "intent:deploy",
|
|
385
|
-
name: { "en": "Deploy", "zh-CN": "\u90E8\u7F72" },
|
|
386
|
-
patterns: [
|
|
387
|
-
"\u90E8\u7F72.*\u9879\u76EE",
|
|
388
|
-
"\u90E8\u7F72.*\u5E94\u7528",
|
|
389
|
-
"deploy.*project",
|
|
390
|
-
"deploy.*app",
|
|
391
|
-
"\u53D1\u5E03.*\u7EBF\u4E0A"
|
|
392
|
-
],
|
|
393
|
-
keywords: ["deploy", "\u90E8\u7F72", "publish", "\u53D1\u5E03", "release"],
|
|
394
|
-
contextSignals: ["has_package_json", "git_has_remote"],
|
|
395
|
-
priority: 70,
|
|
396
|
-
pluginId: "vercel-deploy",
|
|
397
|
-
autoExecute: false
|
|
398
|
-
},
|
|
399
|
-
// Docker Intent
|
|
400
|
-
{
|
|
401
|
-
id: "intent:docker",
|
|
402
|
-
name: { "en": "Docker Operations", "zh-CN": "Docker \u64CD\u4F5C" },
|
|
403
|
-
patterns: [
|
|
404
|
-
"\u521B\u5EFA.*dockerfile",
|
|
405
|
-
"\u751F\u6210.*docker",
|
|
406
|
-
"create.*dockerfile",
|
|
407
|
-
"generate.*docker",
|
|
408
|
-
"\u5BB9\u5668\u5316"
|
|
409
|
-
],
|
|
410
|
-
keywords: ["docker", "container", "\u5BB9\u5668", "dockerfile"],
|
|
411
|
-
contextSignals: ["has_package_json"],
|
|
412
|
-
filePatterns: ["Dockerfile", "docker-compose.yml"],
|
|
413
|
-
priority: 65,
|
|
414
|
-
pluginId: "docker-helper",
|
|
415
|
-
autoExecute: false
|
|
416
|
-
},
|
|
417
|
-
// Refactor Intent
|
|
418
|
-
{
|
|
419
|
-
id: "intent:refactor",
|
|
420
|
-
name: { "en": "Refactor Code", "zh-CN": "\u91CD\u6784\u4EE3\u7801" },
|
|
421
|
-
patterns: [
|
|
422
|
-
"\u91CD\u6784.*\u4EE3\u7801",
|
|
423
|
-
"\u4F18\u5316.*\u4EE3\u7801",
|
|
424
|
-
"refactor.*code",
|
|
425
|
-
"optimize.*code",
|
|
426
|
-
"\u7B80\u5316.*\u4EE3\u7801",
|
|
427
|
-
"simplify.*code"
|
|
428
|
-
],
|
|
429
|
-
keywords: ["refactor", "\u91CD\u6784", "optimize", "\u4F18\u5316", "simplify", "\u7B80\u5316"],
|
|
430
|
-
contextSignals: ["in_src_directory"],
|
|
431
|
-
priority: 60,
|
|
432
|
-
pluginId: "code-simplifier",
|
|
433
|
-
autoExecute: false
|
|
434
|
-
}
|
|
435
|
-
];
|
|
436
|
-
let engineInstance = null;
|
|
437
|
-
function getIntentEngine() {
|
|
438
|
-
if (!engineInstance) {
|
|
439
|
-
engineInstance = new IntentEngine();
|
|
440
|
-
engineInstance.registerRules(DEFAULT_INTENT_RULES);
|
|
441
|
-
}
|
|
442
|
-
return engineInstance;
|
|
443
|
-
}
|
|
444
|
-
|
|
445
|
-
const DEFAULT_TIMEOUT = 3e4;
|
|
446
|
-
const MAX_TIMEOUT = 3e5;
|
|
447
|
-
const MAX_OUTPUT_SIZE = 1024 * 1024;
|
|
448
|
-
const SCRIPT_INTERPRETERS = {
|
|
449
|
-
bash: ["bash", "-e"],
|
|
450
|
-
node: ["node"],
|
|
451
|
-
python: ["python3", "-u"],
|
|
452
|
-
deno: ["deno", "run", "--allow-all"],
|
|
453
|
-
bun: ["bun", "run"]
|
|
454
|
-
};
|
|
455
|
-
const SCRIPT_EXTENSIONS = {
|
|
456
|
-
bash: [".sh", ".bash"],
|
|
457
|
-
node: [".js", ".mjs", ".cjs"],
|
|
458
|
-
python: [".py"],
|
|
459
|
-
deno: [".ts", ".js"],
|
|
460
|
-
bun: [".ts", ".js"]
|
|
461
|
-
};
|
|
462
|
-
class ScriptRunner {
|
|
463
|
-
grantedPermissions = /* @__PURE__ */ new Set();
|
|
464
|
-
runningProcesses = /* @__PURE__ */ new Map();
|
|
465
|
-
constructor() {
|
|
466
|
-
this.grantedPermissions.add("file:read");
|
|
467
|
-
this.grantedPermissions.add("git:read");
|
|
468
|
-
this.grantedPermissions.add("env:read");
|
|
469
|
-
}
|
|
470
|
-
// ==========================================================================
|
|
471
|
-
// Permission Management
|
|
472
|
-
// ==========================================================================
|
|
473
|
-
/**
|
|
474
|
-
* Grant a permission
|
|
475
|
-
*/
|
|
476
|
-
grantPermission(permission) {
|
|
477
|
-
this.grantedPermissions.add(permission);
|
|
478
|
-
}
|
|
479
|
-
/**
|
|
480
|
-
* Grant multiple permissions
|
|
481
|
-
*/
|
|
482
|
-
grantPermissions(permissions) {
|
|
483
|
-
for (const p of permissions) {
|
|
484
|
-
this.grantedPermissions.add(p);
|
|
485
|
-
}
|
|
486
|
-
}
|
|
487
|
-
/**
|
|
488
|
-
* Revoke a permission
|
|
489
|
-
*/
|
|
490
|
-
revokePermission(permission) {
|
|
491
|
-
this.grantedPermissions.delete(permission);
|
|
492
|
-
}
|
|
493
|
-
/**
|
|
494
|
-
* Check if permission is granted
|
|
495
|
-
*/
|
|
496
|
-
hasPermission(permission) {
|
|
497
|
-
return this.grantedPermissions.has(permission);
|
|
498
|
-
}
|
|
499
|
-
/**
|
|
500
|
-
* Check if all required permissions are granted
|
|
501
|
-
*/
|
|
502
|
-
hasAllPermissions(permissions) {
|
|
503
|
-
return permissions.every((p) => this.grantedPermissions.has(p));
|
|
504
|
-
}
|
|
505
|
-
/**
|
|
506
|
-
* Get missing permissions
|
|
507
|
-
*/
|
|
508
|
-
getMissingPermissions(required) {
|
|
509
|
-
return required.filter((p) => !this.grantedPermissions.has(p));
|
|
510
|
-
}
|
|
511
|
-
// ==========================================================================
|
|
512
|
-
// Script Execution
|
|
513
|
-
// ==========================================================================
|
|
514
|
-
/**
|
|
515
|
-
* Execute a script
|
|
516
|
-
*
|
|
517
|
-
* @param script - Script definition
|
|
518
|
-
* @param pluginPath - Path to the plugin directory
|
|
519
|
-
* @param options - Execution options
|
|
520
|
-
* @returns Script execution result
|
|
521
|
-
*/
|
|
522
|
-
async execute(script, pluginPath, options = {}) {
|
|
523
|
-
const startTime = Date.now();
|
|
524
|
-
const missingPermissions = this.getMissingPermissions(script.permissions);
|
|
525
|
-
if (missingPermissions.length > 0) {
|
|
526
|
-
return {
|
|
527
|
-
success: false,
|
|
528
|
-
exitCode: -1,
|
|
529
|
-
stdout: "",
|
|
530
|
-
stderr: `Permission denied. Missing permissions: ${missingPermissions.join(", ")}`,
|
|
531
|
-
duration: 0
|
|
532
|
-
};
|
|
533
|
-
}
|
|
534
|
-
const scriptPath = join(pluginPath, script.path);
|
|
535
|
-
if (!existsSync(scriptPath)) {
|
|
536
|
-
return {
|
|
537
|
-
success: false,
|
|
538
|
-
exitCode: -1,
|
|
539
|
-
stdout: "",
|
|
540
|
-
stderr: `Script not found: ${scriptPath}`,
|
|
541
|
-
duration: 0
|
|
542
|
-
};
|
|
543
|
-
}
|
|
544
|
-
const interpreter = this.getInterpreter(script.type);
|
|
545
|
-
if (!interpreter) {
|
|
546
|
-
return {
|
|
547
|
-
success: false,
|
|
548
|
-
exitCode: -1,
|
|
549
|
-
stdout: "",
|
|
550
|
-
stderr: `Unsupported script type: ${script.type}`,
|
|
551
|
-
duration: 0
|
|
552
|
-
};
|
|
553
|
-
}
|
|
554
|
-
const args = [...interpreter.slice(1), scriptPath, ...options.args ?? script.defaultArgs ?? []];
|
|
555
|
-
const command = interpreter[0];
|
|
556
|
-
const env = this.buildEnvironment(script, options);
|
|
557
|
-
const cwd = options.cwd ?? dirname(scriptPath);
|
|
558
|
-
const timeout = Math.min(options.timeout ?? script.timeout ?? DEFAULT_TIMEOUT, MAX_TIMEOUT);
|
|
559
|
-
try {
|
|
560
|
-
const result = await this.spawn(command, args, {
|
|
561
|
-
cwd,
|
|
562
|
-
env,
|
|
563
|
-
timeout,
|
|
564
|
-
stdin: options.stdin,
|
|
565
|
-
captureOutput: options.captureOutput ?? true,
|
|
566
|
-
background: options.background,
|
|
567
|
-
scriptId: `${script.name}-${Date.now()}`
|
|
568
|
-
});
|
|
569
|
-
return {
|
|
570
|
-
...result,
|
|
571
|
-
duration: Date.now() - startTime
|
|
572
|
-
};
|
|
573
|
-
} catch (error) {
|
|
574
|
-
return {
|
|
575
|
-
success: false,
|
|
576
|
-
exitCode: -1,
|
|
577
|
-
stdout: "",
|
|
578
|
-
stderr: error instanceof Error ? error.message : String(error),
|
|
579
|
-
duration: Date.now() - startTime
|
|
580
|
-
};
|
|
581
|
-
}
|
|
582
|
-
}
|
|
583
|
-
/**
|
|
584
|
-
* Execute a script from raw content
|
|
585
|
-
*/
|
|
586
|
-
async executeRaw(content, type, options = {}) {
|
|
587
|
-
const startTime = Date.now();
|
|
588
|
-
if (!this.hasPermission("shell:execute")) {
|
|
589
|
-
return {
|
|
590
|
-
success: false,
|
|
591
|
-
exitCode: -1,
|
|
592
|
-
stdout: "",
|
|
593
|
-
stderr: "Permission denied. shell:execute permission required for raw script execution.",
|
|
594
|
-
duration: 0
|
|
595
|
-
};
|
|
596
|
-
}
|
|
597
|
-
const interpreter = this.getInterpreter(type);
|
|
598
|
-
if (!interpreter) {
|
|
599
|
-
return {
|
|
600
|
-
success: false,
|
|
601
|
-
exitCode: -1,
|
|
602
|
-
stdout: "",
|
|
603
|
-
stderr: `Unsupported script type: ${type}`,
|
|
604
|
-
duration: 0
|
|
605
|
-
};
|
|
606
|
-
}
|
|
607
|
-
if (type === "bash") {
|
|
608
|
-
const args = ["-c", content, ...options.args ?? []];
|
|
609
|
-
const timeout = Math.min(options.timeout ?? DEFAULT_TIMEOUT, MAX_TIMEOUT);
|
|
610
|
-
try {
|
|
611
|
-
const result = await this.spawn("bash", args, {
|
|
612
|
-
cwd: options.cwd,
|
|
613
|
-
env: {
|
|
614
|
-
...Object.fromEntries(
|
|
615
|
-
Object.entries(process.env).filter(([, v]) => v !== void 0)
|
|
616
|
-
),
|
|
617
|
-
...options.env
|
|
618
|
-
},
|
|
619
|
-
timeout,
|
|
620
|
-
stdin: options.stdin,
|
|
621
|
-
captureOutput: options.captureOutput ?? true
|
|
622
|
-
});
|
|
623
|
-
return {
|
|
624
|
-
...result,
|
|
625
|
-
duration: Date.now() - startTime
|
|
626
|
-
};
|
|
627
|
-
} catch (error) {
|
|
628
|
-
return {
|
|
629
|
-
success: false,
|
|
630
|
-
exitCode: -1,
|
|
631
|
-
stdout: "",
|
|
632
|
-
stderr: error instanceof Error ? error.message : String(error),
|
|
633
|
-
duration: Date.now() - startTime
|
|
634
|
-
};
|
|
635
|
-
}
|
|
636
|
-
}
|
|
637
|
-
const tempPath = join(tmpdir(), `ccjk-script-${Date.now()}${SCRIPT_EXTENSIONS[type][0]}`);
|
|
638
|
-
const { writeFileSync, unlinkSync } = await import('node:fs');
|
|
639
|
-
try {
|
|
640
|
-
writeFileSync(tempPath, content, "utf-8");
|
|
641
|
-
const args = [...interpreter.slice(1), tempPath, ...options.args ?? []];
|
|
642
|
-
const timeout = Math.min(options.timeout ?? DEFAULT_TIMEOUT, MAX_TIMEOUT);
|
|
643
|
-
const result = await this.spawn(interpreter[0], args, {
|
|
644
|
-
cwd: options.cwd,
|
|
645
|
-
env: {
|
|
646
|
-
...Object.fromEntries(
|
|
647
|
-
Object.entries(process.env).filter(([, v]) => v !== void 0)
|
|
648
|
-
),
|
|
649
|
-
...options.env
|
|
650
|
-
},
|
|
651
|
-
timeout,
|
|
652
|
-
stdin: options.stdin,
|
|
653
|
-
captureOutput: options.captureOutput ?? true
|
|
654
|
-
});
|
|
655
|
-
return {
|
|
656
|
-
...result,
|
|
657
|
-
duration: Date.now() - startTime
|
|
658
|
-
};
|
|
659
|
-
} catch (error) {
|
|
660
|
-
return {
|
|
661
|
-
success: false,
|
|
662
|
-
exitCode: -1,
|
|
663
|
-
stdout: "",
|
|
664
|
-
stderr: error instanceof Error ? error.message : String(error),
|
|
665
|
-
duration: Date.now() - startTime
|
|
666
|
-
};
|
|
667
|
-
} finally {
|
|
668
|
-
try {
|
|
669
|
-
unlinkSync(tempPath);
|
|
670
|
-
} catch {
|
|
671
|
-
}
|
|
672
|
-
}
|
|
673
|
-
}
|
|
674
|
-
/**
|
|
675
|
-
* Execute inline bash command
|
|
676
|
-
*/
|
|
677
|
-
async bash(command, options = {}) {
|
|
678
|
-
return this.executeRaw(command, "bash", options);
|
|
679
|
-
}
|
|
680
|
-
// ==========================================================================
|
|
681
|
-
// Process Management
|
|
682
|
-
// ==========================================================================
|
|
683
|
-
/**
|
|
684
|
-
* Kill a running script
|
|
685
|
-
*/
|
|
686
|
-
kill(scriptId) {
|
|
687
|
-
const process2 = this.runningProcesses.get(scriptId);
|
|
688
|
-
if (process2) {
|
|
689
|
-
process2.kill();
|
|
690
|
-
this.runningProcesses.delete(scriptId);
|
|
691
|
-
return true;
|
|
692
|
-
}
|
|
693
|
-
return false;
|
|
694
|
-
}
|
|
695
|
-
/**
|
|
696
|
-
* Kill all running scripts
|
|
697
|
-
*/
|
|
698
|
-
killAll() {
|
|
699
|
-
for (const [id, process2] of Array.from(this.runningProcesses.entries())) {
|
|
700
|
-
process2.kill();
|
|
701
|
-
this.runningProcesses.delete(id);
|
|
702
|
-
}
|
|
703
|
-
}
|
|
704
|
-
/**
|
|
705
|
-
* Get running script IDs
|
|
706
|
-
*/
|
|
707
|
-
getRunningScripts() {
|
|
708
|
-
return Array.from(this.runningProcesses.keys());
|
|
709
|
-
}
|
|
710
|
-
// ==========================================================================
|
|
711
|
-
// Private Helpers
|
|
712
|
-
// ==========================================================================
|
|
713
|
-
/**
|
|
714
|
-
* Get interpreter for script type
|
|
715
|
-
*/
|
|
716
|
-
getInterpreter(type) {
|
|
717
|
-
return SCRIPT_INTERPRETERS[type] ?? null;
|
|
718
|
-
}
|
|
719
|
-
/**
|
|
720
|
-
* Build environment variables
|
|
721
|
-
*/
|
|
722
|
-
buildEnvironment(script, options) {
|
|
723
|
-
const env = {};
|
|
724
|
-
if (this.hasPermission("env:read")) {
|
|
725
|
-
const safeVars = ["PATH", "HOME", "USER", "SHELL", "LANG", "LC_ALL", "TERM", "NODE_ENV"];
|
|
726
|
-
for (const key of safeVars) {
|
|
727
|
-
if (process.env[key]) {
|
|
728
|
-
env[key] = process.env[key];
|
|
729
|
-
}
|
|
730
|
-
}
|
|
731
|
-
}
|
|
732
|
-
if (script.env) {
|
|
733
|
-
Object.assign(env, script.env);
|
|
734
|
-
}
|
|
735
|
-
if (options.env) {
|
|
736
|
-
Object.assign(env, options.env);
|
|
737
|
-
}
|
|
738
|
-
env.CCJK_PLUGIN = "true";
|
|
739
|
-
env.CCJK_VERSION = "2.0";
|
|
740
|
-
return env;
|
|
741
|
-
}
|
|
742
|
-
/**
|
|
743
|
-
* Spawn a process
|
|
744
|
-
*/
|
|
745
|
-
spawn(command, args, options) {
|
|
746
|
-
return new Promise((resolve, reject) => {
|
|
747
|
-
let stdout = "";
|
|
748
|
-
let stderr = "";
|
|
749
|
-
let killed = false;
|
|
750
|
-
const proc = spawn(command, args, {
|
|
751
|
-
cwd: options.cwd,
|
|
752
|
-
env: options.env,
|
|
753
|
-
stdio: options.captureOutput ? ["pipe", "pipe", "pipe"] : "inherit",
|
|
754
|
-
shell: false
|
|
755
|
-
});
|
|
756
|
-
if (options.scriptId) {
|
|
757
|
-
this.runningProcesses.set(options.scriptId, {
|
|
758
|
-
pid: proc.pid,
|
|
759
|
-
kill: () => {
|
|
760
|
-
killed = true;
|
|
761
|
-
proc.kill("SIGTERM");
|
|
762
|
-
}
|
|
763
|
-
});
|
|
764
|
-
}
|
|
765
|
-
let timeoutId;
|
|
766
|
-
if (options.timeout) {
|
|
767
|
-
timeoutId = setTimeout(() => {
|
|
768
|
-
killed = true;
|
|
769
|
-
proc.kill("SIGTERM");
|
|
770
|
-
setTimeout(() => {
|
|
771
|
-
if (!proc.killed) {
|
|
772
|
-
proc.kill("SIGKILL");
|
|
773
|
-
}
|
|
774
|
-
}, 1e3);
|
|
775
|
-
}, options.timeout);
|
|
776
|
-
}
|
|
777
|
-
if (options.stdin && proc.stdin) {
|
|
778
|
-
proc.stdin.write(options.stdin);
|
|
779
|
-
proc.stdin.end();
|
|
780
|
-
}
|
|
781
|
-
if (options.captureOutput) {
|
|
782
|
-
proc.stdout?.on("data", (data) => {
|
|
783
|
-
const chunk = data.toString();
|
|
784
|
-
if (stdout.length + chunk.length <= MAX_OUTPUT_SIZE) {
|
|
785
|
-
stdout += chunk;
|
|
786
|
-
}
|
|
787
|
-
});
|
|
788
|
-
proc.stderr?.on("data", (data) => {
|
|
789
|
-
const chunk = data.toString();
|
|
790
|
-
if (stderr.length + chunk.length <= MAX_OUTPUT_SIZE) {
|
|
791
|
-
stderr += chunk;
|
|
792
|
-
}
|
|
793
|
-
});
|
|
794
|
-
}
|
|
795
|
-
proc.on("close", (code) => {
|
|
796
|
-
if (timeoutId) {
|
|
797
|
-
clearTimeout(timeoutId);
|
|
798
|
-
}
|
|
799
|
-
if (options.scriptId) {
|
|
800
|
-
this.runningProcesses.delete(options.scriptId);
|
|
801
|
-
}
|
|
802
|
-
if (killed && code !== 0) {
|
|
803
|
-
resolve({
|
|
804
|
-
success: false,
|
|
805
|
-
exitCode: code ?? -1,
|
|
806
|
-
stdout,
|
|
807
|
-
stderr: stderr || "Script was killed (timeout or manual)"
|
|
808
|
-
});
|
|
809
|
-
} else {
|
|
810
|
-
resolve({
|
|
811
|
-
success: code === 0,
|
|
812
|
-
exitCode: code ?? 0,
|
|
813
|
-
stdout,
|
|
814
|
-
stderr
|
|
815
|
-
});
|
|
816
|
-
}
|
|
817
|
-
});
|
|
818
|
-
proc.on("error", (error) => {
|
|
819
|
-
if (timeoutId) {
|
|
820
|
-
clearTimeout(timeoutId);
|
|
821
|
-
}
|
|
822
|
-
if (options.scriptId) {
|
|
823
|
-
this.runningProcesses.delete(options.scriptId);
|
|
824
|
-
}
|
|
825
|
-
reject(error);
|
|
826
|
-
});
|
|
827
|
-
if (options.background) {
|
|
828
|
-
resolve({
|
|
829
|
-
success: true,
|
|
830
|
-
exitCode: 0,
|
|
831
|
-
stdout: `Background process started with PID: ${proc.pid}`,
|
|
832
|
-
stderr: ""
|
|
833
|
-
});
|
|
834
|
-
}
|
|
835
|
-
});
|
|
836
|
-
}
|
|
837
|
-
}
|
|
838
|
-
let runnerInstance = null;
|
|
839
|
-
function getScriptRunner() {
|
|
840
|
-
if (!runnerInstance) {
|
|
841
|
-
runnerInstance = new ScriptRunner();
|
|
842
|
-
}
|
|
843
|
-
return runnerInstance;
|
|
844
|
-
}
|
|
845
|
-
|
|
846
|
-
const PLUGINS_DIR = CCJK_PLUGINS_DIR;
|
|
847
|
-
const SKILLS_DIR = CCJK_SKILLS_DIR;
|
|
848
|
-
const AGENTS_DIR = CLAUDE_AGENTS_DIR;
|
|
849
|
-
const CONFIG_FILE = join(CCJK_CONFIG_DIR, "plugins.json");
|
|
850
|
-
class PluginManager {
|
|
851
|
-
plugins = /* @__PURE__ */ new Map();
|
|
852
|
-
agents = /* @__PURE__ */ new Map();
|
|
853
|
-
eventHandlers = /* @__PURE__ */ new Set();
|
|
854
|
-
initialized = false;
|
|
855
|
-
constructor() {
|
|
856
|
-
this.ensureDirectories();
|
|
857
|
-
}
|
|
858
|
-
// ==========================================================================
|
|
859
|
-
// Initialization
|
|
860
|
-
// ==========================================================================
|
|
861
|
-
/**
|
|
862
|
-
* Initialize the plugin manager
|
|
863
|
-
*/
|
|
864
|
-
async initialize() {
|
|
865
|
-
if (this.initialized)
|
|
866
|
-
return;
|
|
867
|
-
await this.loadInstalledPlugins();
|
|
868
|
-
await this.loadInstalledAgents();
|
|
869
|
-
this.registerAllIntents();
|
|
870
|
-
this.initialized = true;
|
|
871
|
-
}
|
|
872
|
-
/**
|
|
873
|
-
* Ensure required directories exist
|
|
874
|
-
*/
|
|
875
|
-
ensureDirectories() {
|
|
876
|
-
for (const dir of [PLUGINS_DIR, SKILLS_DIR, AGENTS_DIR]) {
|
|
877
|
-
if (!existsSync(dir)) {
|
|
878
|
-
mkdirSync(dir, { recursive: true });
|
|
879
|
-
}
|
|
880
|
-
}
|
|
881
|
-
}
|
|
882
|
-
// ==========================================================================
|
|
883
|
-
// Plugin Installation
|
|
884
|
-
// ==========================================================================
|
|
885
|
-
/**
|
|
886
|
-
* Install a plugin from various sources
|
|
887
|
-
*
|
|
888
|
-
* @param source - Plugin source (cloud, github, local, npm)
|
|
889
|
-
* @param options - Installation options
|
|
890
|
-
*/
|
|
891
|
-
async install(source, options = {}) {
|
|
892
|
-
const resolvedSource = typeof source === "string" ? this.resolveSource(source) : source;
|
|
893
|
-
try {
|
|
894
|
-
let result;
|
|
895
|
-
switch (resolvedSource.type) {
|
|
896
|
-
case "cloud":
|
|
897
|
-
result = await this.installFromCloud(resolvedSource.url, options);
|
|
898
|
-
break;
|
|
899
|
-
case "github":
|
|
900
|
-
result = await this.installFromGitHub(resolvedSource.repo, resolvedSource.ref, options);
|
|
901
|
-
break;
|
|
902
|
-
case "local":
|
|
903
|
-
result = await this.installFromLocal(resolvedSource.path, options);
|
|
904
|
-
break;
|
|
905
|
-
case "npm":
|
|
906
|
-
result = await this.installFromNpm(resolvedSource.package, options);
|
|
907
|
-
break;
|
|
908
|
-
default:
|
|
909
|
-
return { success: false, pluginId: "", error: "Unknown source type" };
|
|
910
|
-
}
|
|
911
|
-
if (result.success) {
|
|
912
|
-
this.emit({ type: "plugin:installed", pluginId: result.pluginId, version: result.version });
|
|
913
|
-
}
|
|
914
|
-
return result;
|
|
915
|
-
} catch (error) {
|
|
916
|
-
return {
|
|
917
|
-
success: false,
|
|
918
|
-
pluginId: "",
|
|
919
|
-
error: error instanceof Error ? error.message : String(error)
|
|
920
|
-
};
|
|
921
|
-
}
|
|
922
|
-
}
|
|
923
|
-
/**
|
|
924
|
-
* Install from GitHub (supports Vercel Agent Skills format)
|
|
925
|
-
*/
|
|
926
|
-
async installFromGitHub(repo, ref, options = {}) {
|
|
927
|
-
const parts = repo.split("/");
|
|
928
|
-
if (parts.length < 2) {
|
|
929
|
-
return { success: false, pluginId: "", error: "Invalid GitHub repo format" };
|
|
930
|
-
}
|
|
931
|
-
const owner = parts[0];
|
|
932
|
-
const repoName = parts[1];
|
|
933
|
-
const subPath = parts.slice(2).join("/");
|
|
934
|
-
const targetDir = join(SKILLS_DIR, `${owner}-${repoName}${subPath ? `-${subPath.replace(/\//g, "-")}` : ""}`);
|
|
935
|
-
if (existsSync(targetDir)) {
|
|
936
|
-
if (options.force) {
|
|
937
|
-
rmSync(targetDir, { recursive: true });
|
|
938
|
-
} else {
|
|
939
|
-
return { success: false, pluginId: "", error: "Plugin already installed. Use --force to reinstall." };
|
|
940
|
-
}
|
|
941
|
-
}
|
|
942
|
-
try {
|
|
943
|
-
const cloneUrl = `https://github.com/${owner}/${repoName}.git`;
|
|
944
|
-
await K("git", ["clone", "--depth", "1", ...ref ? ["--branch", ref] : [], cloneUrl, targetDir]);
|
|
945
|
-
if (subPath) {
|
|
946
|
-
const subDir = join(targetDir, subPath);
|
|
947
|
-
if (!existsSync(subDir)) {
|
|
948
|
-
rmSync(targetDir, { recursive: true });
|
|
949
|
-
return { success: false, pluginId: "", error: `Path ${subPath} not found in repo` };
|
|
950
|
-
}
|
|
951
|
-
const tempDir = `${targetDir}-temp`;
|
|
952
|
-
await K("mv", [subDir, tempDir]);
|
|
953
|
-
rmSync(targetDir, { recursive: true });
|
|
954
|
-
await K("mv", [tempDir, targetDir]);
|
|
955
|
-
}
|
|
956
|
-
const plugin = await this.loadPluginFromDirectory(targetDir);
|
|
957
|
-
if (!plugin) {
|
|
958
|
-
rmSync(targetDir, { recursive: true });
|
|
959
|
-
return { success: false, pluginId: "", error: "Invalid plugin format" };
|
|
960
|
-
}
|
|
961
|
-
this.plugins.set(plugin.manifest.id, plugin);
|
|
962
|
-
this.registerPluginIntents(plugin);
|
|
963
|
-
this.saveConfig();
|
|
964
|
-
return {
|
|
965
|
-
success: true,
|
|
966
|
-
pluginId: plugin.manifest.id,
|
|
967
|
-
version: plugin.manifest.version,
|
|
968
|
-
path: targetDir
|
|
969
|
-
};
|
|
970
|
-
} catch (error) {
|
|
971
|
-
if (existsSync(targetDir)) {
|
|
972
|
-
rmSync(targetDir, { recursive: true });
|
|
973
|
-
}
|
|
974
|
-
return {
|
|
975
|
-
success: false,
|
|
976
|
-
pluginId: "",
|
|
977
|
-
error: error instanceof Error ? error.message : String(error)
|
|
978
|
-
};
|
|
979
|
-
}
|
|
980
|
-
}
|
|
981
|
-
/**
|
|
982
|
-
* Install from local directory
|
|
983
|
-
*/
|
|
984
|
-
async installFromLocal(path, options = {}) {
|
|
985
|
-
if (!existsSync(path)) {
|
|
986
|
-
return { success: false, pluginId: "", error: `Path not found: ${path}` };
|
|
987
|
-
}
|
|
988
|
-
const plugin = await this.loadPluginFromDirectory(path);
|
|
989
|
-
if (!plugin) {
|
|
990
|
-
return { success: false, pluginId: "", error: "Invalid plugin format" };
|
|
991
|
-
}
|
|
992
|
-
const targetDir = join(PLUGINS_DIR, plugin.manifest.id);
|
|
993
|
-
if (existsSync(targetDir) && !options.force) {
|
|
994
|
-
return { success: false, pluginId: "", error: "Plugin already installed. Use --force to reinstall." };
|
|
995
|
-
}
|
|
996
|
-
await K("cp", ["-r", path, targetDir]);
|
|
997
|
-
this.plugins.set(plugin.manifest.id, { ...plugin, source: { type: "local", path: targetDir } });
|
|
998
|
-
this.registerPluginIntents(plugin);
|
|
999
|
-
this.saveConfig();
|
|
1000
|
-
return {
|
|
1001
|
-
success: true,
|
|
1002
|
-
pluginId: plugin.manifest.id,
|
|
1003
|
-
version: plugin.manifest.version,
|
|
1004
|
-
path: targetDir
|
|
1005
|
-
};
|
|
1006
|
-
}
|
|
1007
|
-
/**
|
|
1008
|
-
* Install from cloud registry
|
|
1009
|
-
*/
|
|
1010
|
-
async installFromCloud(url, _options = {}) {
|
|
1011
|
-
return { success: false, pluginId: "", error: "Cloud installation not yet implemented in v2" };
|
|
1012
|
-
}
|
|
1013
|
-
/**
|
|
1014
|
-
* Install from NPM
|
|
1015
|
-
*/
|
|
1016
|
-
async installFromNpm(packageName, _options = {}) {
|
|
1017
|
-
const targetDir = join(PLUGINS_DIR, packageName.replace(/\//g, "-"));
|
|
1018
|
-
try {
|
|
1019
|
-
await K("npm", ["pack", packageName, "--pack-destination", targetDir]);
|
|
1020
|
-
return { success: false, pluginId: "", error: "NPM installation not yet fully implemented" };
|
|
1021
|
-
} catch (error) {
|
|
1022
|
-
return {
|
|
1023
|
-
success: false,
|
|
1024
|
-
pluginId: "",
|
|
1025
|
-
error: error instanceof Error ? error.message : String(error)
|
|
1026
|
-
};
|
|
1027
|
-
}
|
|
1028
|
-
}
|
|
1029
|
-
/**
|
|
1030
|
-
* Resolve source string to PluginSource
|
|
1031
|
-
*/
|
|
1032
|
-
resolveSource(source) {
|
|
1033
|
-
if (source.startsWith("github:") || source.match(/^[\w-]+\/[\w-]+/)) {
|
|
1034
|
-
const repo = source.replace("github:", "");
|
|
1035
|
-
return { type: "github", repo };
|
|
1036
|
-
}
|
|
1037
|
-
if (source.startsWith("npm:") || source.startsWith("@")) {
|
|
1038
|
-
const pkg = source.replace("npm:", "");
|
|
1039
|
-
return { type: "npm", package: pkg };
|
|
1040
|
-
}
|
|
1041
|
-
if (source.startsWith("/") || source.startsWith("./") || source.startsWith("~")) {
|
|
1042
|
-
const path = source.startsWith("~") ? source.replace("~", homedir()) : source;
|
|
1043
|
-
return { type: "local", path };
|
|
1044
|
-
}
|
|
1045
|
-
return { type: "cloud", url: source };
|
|
1046
|
-
}
|
|
1047
|
-
// ==========================================================================
|
|
1048
|
-
// Plugin Loading
|
|
1049
|
-
// ==========================================================================
|
|
1050
|
-
/**
|
|
1051
|
-
* Load plugin from directory
|
|
1052
|
-
*/
|
|
1053
|
-
async loadPluginFromDirectory(dirPath) {
|
|
1054
|
-
const parser = getSkillParser();
|
|
1055
|
-
const manifestPath = join(dirPath, "plugin.json");
|
|
1056
|
-
const skillPath = join(dirPath, "SKILL.md");
|
|
1057
|
-
let manifest;
|
|
1058
|
-
if (existsSync(manifestPath)) {
|
|
1059
|
-
manifest = JSON.parse(readFileSync(manifestPath, "utf-8"));
|
|
1060
|
-
} else if (existsSync(skillPath)) {
|
|
1061
|
-
const skill2 = parser.parse(skillPath);
|
|
1062
|
-
manifest = this.generateManifestFromSkill(skill2, dirPath);
|
|
1063
|
-
} else {
|
|
1064
|
-
return null;
|
|
1065
|
-
}
|
|
1066
|
-
const skill = existsSync(skillPath) ? await Promise.resolve(parser.parse(skillPath)) : void 0;
|
|
1067
|
-
const scripts = this.loadScripts(dirPath);
|
|
1068
|
-
const intents = this.loadIntents(dirPath, manifest.id);
|
|
1069
|
-
return {
|
|
1070
|
-
manifest,
|
|
1071
|
-
skill,
|
|
1072
|
-
scripts,
|
|
1073
|
-
intents,
|
|
1074
|
-
source: { type: "local", path: dirPath }
|
|
1075
|
-
};
|
|
1076
|
-
}
|
|
1077
|
-
/**
|
|
1078
|
-
* Generate manifest from SKILL.md
|
|
1079
|
-
*/
|
|
1080
|
-
generateManifestFromSkill(skill, dirPath) {
|
|
1081
|
-
const dirName = dirPath.split("/").pop() || "unknown";
|
|
1082
|
-
return {
|
|
1083
|
-
id: dirName,
|
|
1084
|
-
name: { "en": skill.title, "zh-CN": skill.title },
|
|
1085
|
-
description: { "en": skill.description, "zh-CN": skill.description },
|
|
1086
|
-
version: "1.0.0",
|
|
1087
|
-
author: { name: "Unknown" },
|
|
1088
|
-
category: "other",
|
|
1089
|
-
tags: [],
|
|
1090
|
-
permissions: ["file:read"],
|
|
1091
|
-
formatVersion: "2.0"
|
|
1092
|
-
};
|
|
1093
|
-
}
|
|
1094
|
-
/**
|
|
1095
|
-
* Load scripts from directory
|
|
1096
|
-
*/
|
|
1097
|
-
loadScripts(dirPath) {
|
|
1098
|
-
const scripts = [];
|
|
1099
|
-
const scriptsDir = join(dirPath, "scripts");
|
|
1100
|
-
if (!existsSync(scriptsDir))
|
|
1101
|
-
return scripts;
|
|
1102
|
-
const entries = readdirSync(scriptsDir, { withFileTypes: true });
|
|
1103
|
-
for (const entry of entries) {
|
|
1104
|
-
if (entry.isFile()) {
|
|
1105
|
-
const ext = entry.name.substring(entry.name.lastIndexOf("."));
|
|
1106
|
-
let type = null;
|
|
1107
|
-
if ([".sh", ".bash"].includes(ext))
|
|
1108
|
-
type = "bash";
|
|
1109
|
-
else if ([".js", ".mjs"].includes(ext))
|
|
1110
|
-
type = "node";
|
|
1111
|
-
else if (ext === ".py")
|
|
1112
|
-
type = "python";
|
|
1113
|
-
if (type) {
|
|
1114
|
-
scripts.push({
|
|
1115
|
-
name: entry.name.replace(/\.[^.]+$/, ""),
|
|
1116
|
-
path: `scripts/${entry.name}`,
|
|
1117
|
-
type,
|
|
1118
|
-
permissions: ["shell:execute"]
|
|
1119
|
-
});
|
|
1120
|
-
}
|
|
1121
|
-
}
|
|
1122
|
-
}
|
|
1123
|
-
return scripts;
|
|
1124
|
-
}
|
|
1125
|
-
/**
|
|
1126
|
-
* Load intents from directory
|
|
1127
|
-
*/
|
|
1128
|
-
loadIntents(dirPath, _pluginId) {
|
|
1129
|
-
const intentsPath = join(dirPath, "intents", "intents.yaml");
|
|
1130
|
-
if (!existsSync(intentsPath))
|
|
1131
|
-
return void 0;
|
|
1132
|
-
return void 0;
|
|
1133
|
-
}
|
|
1134
|
-
/**
|
|
1135
|
-
* Load all installed plugins
|
|
1136
|
-
*/
|
|
1137
|
-
async loadInstalledPlugins() {
|
|
1138
|
-
if (existsSync(PLUGINS_DIR)) {
|
|
1139
|
-
const entries = readdirSync(PLUGINS_DIR, { withFileTypes: true });
|
|
1140
|
-
for (const entry of entries) {
|
|
1141
|
-
if (entry.isDirectory()) {
|
|
1142
|
-
const plugin = await this.loadPluginFromDirectory(join(PLUGINS_DIR, entry.name));
|
|
1143
|
-
if (plugin) {
|
|
1144
|
-
this.plugins.set(plugin.manifest.id, plugin);
|
|
1145
|
-
}
|
|
1146
|
-
}
|
|
1147
|
-
}
|
|
1148
|
-
}
|
|
1149
|
-
if (existsSync(SKILLS_DIR)) {
|
|
1150
|
-
const entries = readdirSync(SKILLS_DIR, { withFileTypes: true });
|
|
1151
|
-
for (const entry of entries) {
|
|
1152
|
-
if (entry.isDirectory()) {
|
|
1153
|
-
const plugin = await this.loadPluginFromDirectory(join(SKILLS_DIR, entry.name));
|
|
1154
|
-
if (plugin) {
|
|
1155
|
-
this.plugins.set(plugin.manifest.id, plugin);
|
|
1156
|
-
}
|
|
1157
|
-
}
|
|
1158
|
-
}
|
|
1159
|
-
}
|
|
1160
|
-
}
|
|
1161
|
-
// ==========================================================================
|
|
1162
|
-
// Intent Management
|
|
1163
|
-
// ==========================================================================
|
|
1164
|
-
/**
|
|
1165
|
-
* Register intents from all plugins
|
|
1166
|
-
*/
|
|
1167
|
-
registerAllIntents() {
|
|
1168
|
-
const engine = getIntentEngine();
|
|
1169
|
-
for (const plugin of Array.from(this.plugins.values())) {
|
|
1170
|
-
if (plugin.intents) {
|
|
1171
|
-
engine.registerRules(plugin.intents);
|
|
1172
|
-
}
|
|
1173
|
-
}
|
|
1174
|
-
}
|
|
1175
|
-
/**
|
|
1176
|
-
* Register intents from a single plugin
|
|
1177
|
-
*/
|
|
1178
|
-
registerPluginIntents(plugin) {
|
|
1179
|
-
if (plugin.intents) {
|
|
1180
|
-
const engine = getIntentEngine();
|
|
1181
|
-
engine.registerRules(plugin.intents);
|
|
1182
|
-
}
|
|
1183
|
-
}
|
|
1184
|
-
/**
|
|
1185
|
-
* Detect intent and get matching plugins
|
|
1186
|
-
*/
|
|
1187
|
-
async detectIntent(userInput, cwd) {
|
|
1188
|
-
const engine = getIntentEngine();
|
|
1189
|
-
return engine.detect(userInput, cwd);
|
|
1190
|
-
}
|
|
1191
|
-
/**
|
|
1192
|
-
* Execute based on detected intent
|
|
1193
|
-
*/
|
|
1194
|
-
async executeIntent(match, cwd) {
|
|
1195
|
-
const plugin = this.plugins.get(match.pluginId);
|
|
1196
|
-
if (!plugin) {
|
|
1197
|
-
throw new Error(`Plugin not found: ${match.pluginId}`);
|
|
1198
|
-
}
|
|
1199
|
-
this.emit({ type: "plugin:activated", pluginId: match.pluginId, trigger: "intent" });
|
|
1200
|
-
if (plugin.scripts && plugin.scripts.length > 0) {
|
|
1201
|
-
const mainScript = plugin.scripts.find((s) => s.name === "main") || plugin.scripts[0];
|
|
1202
|
-
const runner = getScriptRunner();
|
|
1203
|
-
const pluginPath = plugin.source.type === "local" ? plugin.source.path : "";
|
|
1204
|
-
const result = await runner.execute(mainScript, pluginPath, { cwd });
|
|
1205
|
-
this.emit({ type: "intent:executed", match, result });
|
|
1206
|
-
return result;
|
|
1207
|
-
}
|
|
1208
|
-
if (plugin.skill) {
|
|
1209
|
-
this.emit({ type: "intent:executed", match, result: plugin.skill });
|
|
1210
|
-
return plugin.skill;
|
|
1211
|
-
}
|
|
1212
|
-
return null;
|
|
1213
|
-
}
|
|
1214
|
-
// ==========================================================================
|
|
1215
|
-
// Agent Management
|
|
1216
|
-
// ==========================================================================
|
|
1217
|
-
/**
|
|
1218
|
-
* Create an agent from skills and MCP servers
|
|
1219
|
-
*
|
|
1220
|
-
* Writes agent to project-local `.claude-code/agents/` in Markdown format
|
|
1221
|
-
* for Claude Code compatibility.
|
|
1222
|
-
*/
|
|
1223
|
-
async createAgent(definition, options) {
|
|
1224
|
-
for (const skillRef of definition.skills) {
|
|
1225
|
-
if (!this.plugins.has(skillRef.pluginId)) {
|
|
1226
|
-
throw new Error(`Skill not found: ${skillRef.pluginId}`);
|
|
1227
|
-
}
|
|
1228
|
-
}
|
|
1229
|
-
await writeAgentFile(definition, {
|
|
1230
|
-
format: "markdown",
|
|
1231
|
-
projectDir: options?.projectDir,
|
|
1232
|
-
global: options?.global || false
|
|
1233
|
-
});
|
|
1234
|
-
this.agents.set(definition.id, definition);
|
|
1235
|
-
this.emit({ type: "agent:created", agentId: definition.id });
|
|
1236
|
-
}
|
|
1237
|
-
/**
|
|
1238
|
-
* Get an agent by ID
|
|
1239
|
-
*/
|
|
1240
|
-
getAgent(agentId) {
|
|
1241
|
-
return this.agents.get(agentId);
|
|
1242
|
-
}
|
|
1243
|
-
/**
|
|
1244
|
-
* List all agents
|
|
1245
|
-
*/
|
|
1246
|
-
listAgents() {
|
|
1247
|
-
return Array.from(this.agents.values());
|
|
1248
|
-
}
|
|
1249
|
-
/**
|
|
1250
|
-
* Load installed agents from both project-local and global directories
|
|
1251
|
-
*
|
|
1252
|
-
* Supports:
|
|
1253
|
-
* - Project-local `.claude-code/agents/*.md` (Claude Code format)
|
|
1254
|
-
* - Global `~/.claude/agents/*.md` (Claude Code compatible)
|
|
1255
|
-
*/
|
|
1256
|
-
async loadInstalledAgents() {
|
|
1257
|
-
const projectAgentsDir = getAgentsDir();
|
|
1258
|
-
if (existsSync(projectAgentsDir)) {
|
|
1259
|
-
const entries = readdirSync(projectAgentsDir, { withFileTypes: true });
|
|
1260
|
-
for (const entry of entries) {
|
|
1261
|
-
if (entry.isFile() && entry.name.endsWith(".md")) {
|
|
1262
|
-
try {
|
|
1263
|
-
const content = readFileSync(join(projectAgentsDir, entry.name), "utf-8");
|
|
1264
|
-
const agent = this.parseMarkdownAgent(content, entry.name);
|
|
1265
|
-
if (agent) {
|
|
1266
|
-
this.agents.set(agent.id, agent);
|
|
1267
|
-
}
|
|
1268
|
-
} catch {
|
|
1269
|
-
}
|
|
1270
|
-
}
|
|
1271
|
-
}
|
|
1272
|
-
}
|
|
1273
|
-
if (existsSync(AGENTS_DIR)) {
|
|
1274
|
-
const entries = readdirSync(AGENTS_DIR, { withFileTypes: true });
|
|
1275
|
-
for (const entry of entries) {
|
|
1276
|
-
if (entry.isFile() && entry.name.endsWith(".json")) {
|
|
1277
|
-
try {
|
|
1278
|
-
const content = readFileSync(join(AGENTS_DIR, entry.name), "utf-8");
|
|
1279
|
-
const agent = JSON.parse(content);
|
|
1280
|
-
if (!this.agents.has(agent.id)) {
|
|
1281
|
-
this.agents.set(agent.id, agent);
|
|
1282
|
-
}
|
|
1283
|
-
} catch {
|
|
1284
|
-
}
|
|
1285
|
-
}
|
|
1286
|
-
}
|
|
1287
|
-
}
|
|
1288
|
-
}
|
|
1289
|
-
/**
|
|
1290
|
-
* Parse a Markdown agent file to AgentDefinition
|
|
1291
|
-
*/
|
|
1292
|
-
parseMarkdownAgent(content, filename) {
|
|
1293
|
-
const frontmatterMatch = content.match(/^---\n([\s\S]*?)\n---/);
|
|
1294
|
-
if (!frontmatterMatch)
|
|
1295
|
-
return null;
|
|
1296
|
-
const frontmatter = frontmatterMatch[1];
|
|
1297
|
-
const lines = frontmatter.split("\n");
|
|
1298
|
-
let id = filename.replace(/\.md$/, "");
|
|
1299
|
-
let name = id;
|
|
1300
|
-
let description = "";
|
|
1301
|
-
const tools = [];
|
|
1302
|
-
for (const line of lines) {
|
|
1303
|
-
const colonIndex = line.indexOf(":");
|
|
1304
|
-
if (colonIndex === -1)
|
|
1305
|
-
continue;
|
|
1306
|
-
const key = line.slice(0, colonIndex).trim();
|
|
1307
|
-
const value = line.slice(colonIndex + 1).trim();
|
|
1308
|
-
if (key === "name") {
|
|
1309
|
-
id = value;
|
|
1310
|
-
name = value;
|
|
1311
|
-
} else if (key === "description") {
|
|
1312
|
-
description = value;
|
|
1313
|
-
} else if (key === "tools") {
|
|
1314
|
-
tools.push(...value.split(",").map((t) => t.trim()).filter(Boolean));
|
|
1315
|
-
}
|
|
1316
|
-
}
|
|
1317
|
-
const bodyMatch = content.match(/^---\n[\s\S]*?\n---\n([\s\S]*)$/);
|
|
1318
|
-
const persona = bodyMatch ? bodyMatch[1].trim() : "";
|
|
1319
|
-
return {
|
|
1320
|
-
id,
|
|
1321
|
-
name: { "en": name, "zh-CN": name },
|
|
1322
|
-
description: { "en": description, "zh-CN": description },
|
|
1323
|
-
persona,
|
|
1324
|
-
instructions: persona,
|
|
1325
|
-
// Use persona as instructions
|
|
1326
|
-
skills: [],
|
|
1327
|
-
mcpServers: [],
|
|
1328
|
-
capabilities: []
|
|
1329
|
-
};
|
|
1330
|
-
}
|
|
1331
|
-
// ==========================================================================
|
|
1332
|
-
// Plugin Management
|
|
1333
|
-
// ==========================================================================
|
|
1334
|
-
/**
|
|
1335
|
-
* Uninstall a plugin
|
|
1336
|
-
*/
|
|
1337
|
-
async uninstall(pluginId) {
|
|
1338
|
-
const plugin = this.plugins.get(pluginId);
|
|
1339
|
-
if (!plugin)
|
|
1340
|
-
return false;
|
|
1341
|
-
if (plugin.source.type === "local") {
|
|
1342
|
-
rmSync(plugin.source.path, { recursive: true });
|
|
1343
|
-
}
|
|
1344
|
-
const engine = getIntentEngine();
|
|
1345
|
-
engine.unregisterPluginRules(pluginId);
|
|
1346
|
-
this.plugins.delete(pluginId);
|
|
1347
|
-
this.saveConfig();
|
|
1348
|
-
this.emit({ type: "plugin:uninstalled", pluginId });
|
|
1349
|
-
return true;
|
|
1350
|
-
}
|
|
1351
|
-
/**
|
|
1352
|
-
* Get a plugin by ID
|
|
1353
|
-
*/
|
|
1354
|
-
getPlugin(pluginId) {
|
|
1355
|
-
return this.plugins.get(pluginId);
|
|
1356
|
-
}
|
|
1357
|
-
/**
|
|
1358
|
-
* List all installed plugins
|
|
1359
|
-
*/
|
|
1360
|
-
listPlugins() {
|
|
1361
|
-
return Array.from(this.plugins.values());
|
|
1362
|
-
}
|
|
1363
|
-
/**
|
|
1364
|
-
* Check for updates
|
|
1365
|
-
*/
|
|
1366
|
-
async checkUpdates() {
|
|
1367
|
-
return [];
|
|
1368
|
-
}
|
|
1369
|
-
// ==========================================================================
|
|
1370
|
-
// Script Execution
|
|
1371
|
-
// ==========================================================================
|
|
1372
|
-
/**
|
|
1373
|
-
* Execute a plugin script
|
|
1374
|
-
*/
|
|
1375
|
-
async executeScript(pluginId, scriptName, options = {}) {
|
|
1376
|
-
const plugin = this.plugins.get(pluginId);
|
|
1377
|
-
if (!plugin) {
|
|
1378
|
-
throw new Error(`Plugin not found: ${pluginId}`);
|
|
1379
|
-
}
|
|
1380
|
-
const script = plugin.scripts?.find((s) => s.name === scriptName);
|
|
1381
|
-
if (!script) {
|
|
1382
|
-
throw new Error(`Script not found: ${scriptName}`);
|
|
1383
|
-
}
|
|
1384
|
-
const runner = getScriptRunner();
|
|
1385
|
-
const pluginPath = plugin.source.type === "local" ? plugin.source.path : "";
|
|
1386
|
-
this.emit({ type: "script:started", pluginId, scriptName });
|
|
1387
|
-
const result = await runner.execute(script, pluginPath, options);
|
|
1388
|
-
this.emit({ type: "script:completed", pluginId, scriptName, result });
|
|
1389
|
-
return result;
|
|
1390
|
-
}
|
|
1391
|
-
/**
|
|
1392
|
-
* Grant permission to script runner
|
|
1393
|
-
*/
|
|
1394
|
-
grantPermission(permission) {
|
|
1395
|
-
const runner = getScriptRunner();
|
|
1396
|
-
runner.grantPermission(permission);
|
|
1397
|
-
}
|
|
1398
|
-
// ==========================================================================
|
|
1399
|
-
// Event System
|
|
1400
|
-
// ==========================================================================
|
|
1401
|
-
/**
|
|
1402
|
-
* Subscribe to plugin events
|
|
1403
|
-
*/
|
|
1404
|
-
on(handler) {
|
|
1405
|
-
this.eventHandlers.add(handler);
|
|
1406
|
-
return () => this.eventHandlers.delete(handler);
|
|
1407
|
-
}
|
|
1408
|
-
/**
|
|
1409
|
-
* Emit an event
|
|
1410
|
-
*/
|
|
1411
|
-
emit(event) {
|
|
1412
|
-
for (const handler of Array.from(this.eventHandlers)) {
|
|
1413
|
-
try {
|
|
1414
|
-
handler(event);
|
|
1415
|
-
} catch (error) {
|
|
1416
|
-
console.error("Event handler error:", error);
|
|
1417
|
-
}
|
|
1418
|
-
}
|
|
1419
|
-
}
|
|
1420
|
-
// ==========================================================================
|
|
1421
|
-
// Configuration
|
|
1422
|
-
// ==========================================================================
|
|
1423
|
-
/**
|
|
1424
|
-
* Save configuration
|
|
1425
|
-
*/
|
|
1426
|
-
saveConfig() {
|
|
1427
|
-
const config = {
|
|
1428
|
-
plugins: Array.from(this.plugins.entries()).map(([id, p]) => ({
|
|
1429
|
-
id,
|
|
1430
|
-
source: p.source,
|
|
1431
|
-
version: p.manifest.version
|
|
1432
|
-
})),
|
|
1433
|
-
agents: Array.from(this.agents.keys())
|
|
1434
|
-
};
|
|
1435
|
-
writeFileSync(CONFIG_FILE, JSON.stringify(config, null, 2));
|
|
1436
|
-
}
|
|
1437
|
-
}
|
|
1438
|
-
let managerInstance = null;
|
|
1439
|
-
async function getPluginManager() {
|
|
1440
|
-
if (!managerInstance) {
|
|
1441
|
-
managerInstance = new PluginManager();
|
|
1442
|
-
await managerInstance.initialize();
|
|
1443
|
-
}
|
|
1444
|
-
return managerInstance;
|
|
1445
|
-
}
|
|
1446
|
-
|
|
1447
|
-
export { getPluginManager as g };
|