@yiyi_zhang/laoshi 0.0.0-stage → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +35 -0
- package/LICENSE +21 -0
- package/README.md +60 -2
- package/SCOPE.md +13 -0
- package/adapters/dsh/adapter.ts +75 -0
- package/adapters/dsh/dsh-runtime.ts +242 -0
- package/adapters/dsh/install.mjs +97 -0
- package/adapters/dsh/intranet/install.mjs +15 -0
- package/adapters/dsh/intranet/make-sample.mjs +52 -0
- package/adapters/dsh/plugin/channel.d.mts +2 -0
- package/adapters/dsh/plugin/channel.mjs +31 -0
- package/adapters/dsh/plugin/index.d.mts +3 -0
- package/adapters/dsh/plugin/index.mjs +292 -0
- package/adapters/dsh/plugin/package.json +18 -0
- package/adapters/paseo/adapter.ts +96 -0
- package/adapters/paseo/daemon-check.ts +80 -0
- package/adapters/paseo/daemon-version.ts +64 -0
- package/adapters/paseo/doctor.ts +161 -0
- package/adapters/paseo/install.mjs +30 -0
- package/adapters/paseo/paseo-json.ts +73 -0
- package/adapters/paseo/paseo-profiles.ts +127 -0
- package/adapters/paseo/paseo-runtime.ts +507 -0
- package/adapters/paseo/settings.ts +22 -0
- package/adapters/paseo/skill/setup.md +26 -0
- package/adapters/paseo/skill/templates/copy-local-files.mjs +32 -0
- package/adapters/paseo/skill/templates/with-port.mjs +36 -0
- package/adapters/paseo/smoke-test.ts +203 -0
- package/bin/bootstrap.mjs +170 -0
- package/bin/install.mjs +245 -0
- package/bin/locate.mjs +22 -0
- package/bin/req-docs.d.mts +5 -0
- package/bin/req-docs.mjs +167 -0
- package/bin/req-doctor.mjs +21 -0
- package/bin/req.mjs +236 -0
- package/bin/start-pipeline +21 -0
- package/bin/start-pipeline.mjs +22 -0
- package/config.example.json +134 -0
- package/contracts/README.md +21 -0
- package/contracts/agent-runtime.md +83 -0
- package/contracts/cli-json.md +76 -0
- package/contracts/feature-files.md +148 -0
- package/contracts/notifier-event.md +90 -0
- package/contracts/result-file.md +21 -0
- package/contracts/spec.md +37 -0
- package/contracts/state.md +69 -0
- package/contracts/usage-record.md +72 -0
- package/contracts/verify.md +41 -0
- package/docs/adr/0001-new-repo-core-and-adapters.md +20 -0
- package/docs/adr/0002-two-orchestration-modes.md +20 -0
- package/docs/adr/0003-generate-once-then-lock.md +20 -0
- package/docs/adr/0004-external-contracts-stay-stable.md +19 -0
- package/docs/adr/0005-skill-names.md +26 -0
- package/docs/adr/0006-deterministic-engine-platform-capabilities.md +42 -0
- package/docs/adr/0007-one-install-many-repos.md +63 -0
- package/docs/adr/0008-capability-sources-and-platform-plugin.md +81 -0
- package/docs/adr/README.md +14 -0
- package/docs/design/adapter-guide.md +90 -0
- package/docs/design/architecture.md +104 -0
- package/docs/design/builtin-capabilities.md +72 -0
- package/docs/design/compat-migration.md +65 -0
- package/docs/design/dsh-adapter.md +145 -0
- package/docs/design/in-chat-orchestration.md +67 -0
- package/docs/design/init-bootstrap.md +83 -0
- package/docs/design/internal-platform-adapter.md +76 -0
- package/docs/design/platform-discovery.md +117 -0
- package/docs/design/platform-vocabulary.md +44 -0
- package/docs/design/state-v2.md +71 -0
- package/docs/guide//344/275/277/347/224/250/350/200/205/346/214/207/345/215/227.md +130 -0
- package/docs/guide//345/256/211/350/243/205/344/270/216/345/215/207/347/272/247.md +211 -0
- package/docs/guide//347/273/264/346/212/244/350/200/205/346/214/207/345/215/227.md +86 -0
- package/docs/guide//351/241/271/347/233/256/345/256/232/345/210/266/344/270/216/350/277/220/350/241/214/350/247/204/345/210/231.md +595 -0
- package/docs/intranet/install-verify.md +278 -0
- package/engine/prompts/00-shared-context.md +107 -0
- package/engine/prompts/02-spec-review.md +46 -0
- package/engine/prompts/03-design.md +77 -0
- package/engine/prompts/03a-design-proposal.md +30 -0
- package/engine/prompts/04-design-review.md +73 -0
- package/engine/prompts/04b-design-revise.md +56 -0
- package/engine/prompts/05-implement.md +72 -0
- package/engine/prompts/06-code-review.md +81 -0
- package/engine/prompts/07-review-fix.md +41 -0
- package/engine/prompts/07b-handoff.md +45 -0
- package/engine/prompts/08-service-start.md +59 -0
- package/engine/prompts/09-verify.md +90 -0
- package/engine/prompts/10-defect-fix.md +41 -0
- package/engine/prompts/10b-reverify.md +43 -0
- package/engine/prompts/11-report.md +112 -0
- package/engine/prompts/browser-verify.md +14 -0
- package/engine/prompts/incremental.md +24 -0
- package/engine/prompts/joint.md +55 -0
- package/engine/prompts/managed-services.md +9 -0
- package/engine/prompts/panel-member.md +38 -0
- package/engine/prompts/related-repos.md +7 -0
- package/engine/prompts/review-axis-spec.md +10 -0
- package/engine/prompts/review-axis-standards.md +11 -0
- package/engine/prompts/types/assessment.md +41 -0
- package/engine/prompts/types/defect.md +55 -0
- package/engine/prompts/types/refactor.md +39 -0
- package/engine/prompts/ui-check.md +15 -0
- package/engine/prompts/verify-deployed.md +14 -0
- package/engine/skill-fragments/setup-builtin.md +24 -0
- package/engine/src/activity.ts +131 -0
- package/engine/src/api.ts +655 -0
- package/engine/src/builtin/index.ts +30 -0
- package/engine/src/builtin/project-services.ts +66 -0
- package/engine/src/builtin/service-runner.mjs +35 -0
- package/engine/src/builtin/services.ts +264 -0
- package/engine/src/builtin/setup-runner.mjs +26 -0
- package/engine/src/builtin/workspace.ts +139 -0
- package/engine/src/card-cmd.ts +505 -0
- package/engine/src/card.ts +541 -0
- package/engine/src/checklist-cmd.ts +37 -0
- package/engine/src/checklist.ts +254 -0
- package/engine/src/cli-args.ts +228 -0
- package/engine/src/code-review.ts +421 -0
- package/engine/src/codeowners.ts +87 -0
- package/engine/src/config-view.ts +310 -0
- package/engine/src/config.ts +862 -0
- package/engine/src/configure.ts +343 -0
- package/engine/src/control.ts +257 -0
- package/engine/src/danger-guard.ts +180 -0
- package/engine/src/digest.ts +141 -0
- package/engine/src/doctor.ts +410 -0
- package/engine/src/estimate.ts +95 -0
- package/engine/src/eval.ts +325 -0
- package/engine/src/factory.ts +545 -0
- package/engine/src/features.ts +311 -0
- package/engine/src/gate.ts +157 -0
- package/engine/src/git.ts +30 -0
- package/engine/src/identity.ts +72 -0
- package/engine/src/index-cmd.ts +34 -0
- package/engine/src/integration-cmd.ts +161 -0
- package/engine/src/integrations.ts +485 -0
- package/engine/src/joint.ts +173 -0
- package/engine/src/launch.ts +443 -0
- package/engine/src/lessons.ts +74 -0
- package/engine/src/locations.ts +83 -0
- package/engine/src/main.ts +390 -0
- package/engine/src/messages.ts +472 -0
- package/engine/src/notifiers.ts +114 -0
- package/engine/src/notify-test.ts +108 -0
- package/engine/src/outcomes.ts +145 -0
- package/engine/src/paths.ts +10 -0
- package/engine/src/pipeline.ts +2517 -0
- package/engine/src/platform.ts +121 -0
- package/engine/src/playbooks.ts +46 -0
- package/engine/src/preflight.ts +352 -0
- package/engine/src/prompts.ts +76 -0
- package/engine/src/queue.ts +61 -0
- package/engine/src/records.ts +403 -0
- package/engine/src/reply.ts +81 -0
- package/engine/src/review-assets/app.css +339 -0
- package/engine/src/review-assets/app.html +107 -0
- package/engine/src/review-assets/app.js +958 -0
- package/engine/src/review-assets/check.css +12 -0
- package/engine/src/review-assets/check.html +61 -0
- package/engine/src/review-assets/check.js +341 -0
- package/engine/src/review-assets/code.css +16 -0
- package/engine/src/review-assets/code.html +58 -0
- package/engine/src/review-assets/code.js +497 -0
- package/engine/src/review-assets/rk-icons.js +98 -0
- package/engine/src/review-assets/rk-tokens.css +252 -0
- package/engine/src/review-assets/rk.css +254 -0
- package/engine/src/review.ts +771 -0
- package/engine/src/runtime-loader.ts +110 -0
- package/engine/src/runtime.ts +186 -0
- package/engine/src/scan-guard.ts +132 -0
- package/engine/src/schedule-time.ts +51 -0
- package/engine/src/secret-scan.ts +177 -0
- package/engine/src/semver.ts +31 -0
- package/engine/src/skills-render.ts +104 -0
- package/engine/src/spec-review.ts +99 -0
- package/engine/src/state.ts +506 -0
- package/engine/src/stats.ts +810 -0
- package/engine/src/steps.ts +269 -0
- package/engine/src/try.ts +135 -0
- package/engine/src/ui-check-page.js +208 -0
- package/engine/src/ui-check.ts +366 -0
- package/engine/src/usage.ts +67 -0
- package/engine/src/watchdog.ts +139 -0
- package/engine/src/words.ts +95 -0
- package/engine/src/worktree.ts +227 -0
- package/notifiers/im-template.mjs +86 -0
- package/package.json +78 -4
- package/principles/INDEX.md +11 -0
- package/site-dist/404.html +27 -0
- package/site-dist/assets/app.Df99UgrJ.js +1 -0
- package/site-dist/assets/changelog.md.Df8vFhjK.js +1 -0
- package/site-dist/assets/changelog.md.Df8vFhjK.lean.js +1 -0
- package/site-dist/assets/chunks/@localSearchIndexroot.n-0kN-N0.js +1 -0
- package/site-dist/assets/chunks/VPLocalSearchBox.IEhP6Gw5.js +9 -0
- package/site-dist/assets/chunks/framework.BetZR81g.js +20 -0
- package/site-dist/assets/chunks/theme.DHubfO7g.js +2 -0
- package/site-dist/assets/guide_dsh.md.0X-eYB87.js +5 -0
- package/site-dist/assets/guide_dsh.md.0X-eYB87.lean.js +5 -0
- package/site-dist/assets/guide_getting-started.md.BZTWiHhH.js +1 -0
- package/site-dist/assets/guide_getting-started.md.BZTWiHhH.lean.js +1 -0
- package/site-dist/assets/guide_how-it-works.md.CkvlSgxO.js +25 -0
- package/site-dist/assets/guide_how-it-works.md.CkvlSgxO.lean.js +1 -0
- package/site-dist/assets/guide_index.md.D67QX_Vi.js +1 -0
- package/site-dist/assets/guide_index.md.D67QX_Vi.lean.js +1 -0
- package/site-dist/assets/guide_install.md.D7NiiOPu.js +19 -0
- package/site-dist/assets/guide_install.md.D7NiiOPu.lean.js +19 -0
- package/site-dist/assets/guide_intranet.md.Bz0sAHK0.js +9 -0
- package/site-dist/assets/guide_intranet.md.Bz0sAHK0.lean.js +9 -0
- package/site-dist/assets/guide_maintainer.md.C-Vt-DdK.js +1 -0
- package/site-dist/assets/guide_maintainer.md.C-Vt-DdK.lean.js +1 -0
- package/site-dist/assets/guide_phases.md.Cw0A9Vb1.js +1 -0
- package/site-dist/assets/guide_phases.md.Cw0A9Vb1.lean.js +1 -0
- package/site-dist/assets/guide_project.md.BIcaDhdS.js +77 -0
- package/site-dist/assets/guide_project.md.BIcaDhdS.lean.js +77 -0
- package/site-dist/assets/guide_user.md.B66TQvIA.js +1 -0
- package/site-dist/assets/guide_user.md.B66TQvIA.lean.js +1 -0
- package/site-dist/assets/index.md.CrBM3tiI.js +1 -0
- package/site-dist/assets/index.md.CrBM3tiI.lean.js +1 -0
- package/site-dist/assets/inter-italic-cyrillic-ext.r48I6akx.woff2 +0 -0
- package/site-dist/assets/inter-italic-cyrillic.By2_1cv3.woff2 +0 -0
- package/site-dist/assets/inter-italic-greek-ext.1u6EdAuj.woff2 +0 -0
- package/site-dist/assets/inter-italic-greek.DJ8dCoTZ.woff2 +0 -0
- package/site-dist/assets/inter-italic-latin-ext.CN1xVJS-.woff2 +0 -0
- package/site-dist/assets/inter-italic-latin.C2AdPX0b.woff2 +0 -0
- package/site-dist/assets/inter-italic-vietnamese.BSbpV94h.woff2 +0 -0
- package/site-dist/assets/inter-roman-cyrillic-ext.BBPuwvHQ.woff2 +0 -0
- package/site-dist/assets/inter-roman-cyrillic.C5lxZ8CY.woff2 +0 -0
- package/site-dist/assets/inter-roman-greek-ext.CqjqNYQ-.woff2 +0 -0
- package/site-dist/assets/inter-roman-greek.BBVDIX6e.woff2 +0 -0
- package/site-dist/assets/inter-roman-latin-ext.4ZJIpNVo.woff2 +0 -0
- package/site-dist/assets/inter-roman-latin.Di8DUHzh.woff2 +0 -0
- package/site-dist/assets/inter-roman-vietnamese.BjW4sHH5.woff2 +0 -0
- package/site-dist/assets/reference_adr_0001-new-repo-core-and-adapters.md.CjNHHmrf.js +1 -0
- package/site-dist/assets/reference_adr_0001-new-repo-core-and-adapters.md.CjNHHmrf.lean.js +1 -0
- package/site-dist/assets/reference_adr_0002-two-orchestration-modes.md.CHD05agO.js +1 -0
- package/site-dist/assets/reference_adr_0002-two-orchestration-modes.md.CHD05agO.lean.js +1 -0
- package/site-dist/assets/reference_adr_0003-generate-once-then-lock.md.BaRiZfXT.js +1 -0
- package/site-dist/assets/reference_adr_0003-generate-once-then-lock.md.BaRiZfXT.lean.js +1 -0
- package/site-dist/assets/reference_adr_0004-external-contracts-stay-stable.md.DUJ7CTV1.js +1 -0
- package/site-dist/assets/reference_adr_0004-external-contracts-stay-stable.md.DUJ7CTV1.lean.js +1 -0
- package/site-dist/assets/reference_adr_0005-skill-names.md.DuBVd1tl.js +1 -0
- package/site-dist/assets/reference_adr_0005-skill-names.md.DuBVd1tl.lean.js +1 -0
- package/site-dist/assets/reference_adr_0006-deterministic-engine-platform-capabilities.md.Dcrnx1-L.js +1 -0
- package/site-dist/assets/reference_adr_0006-deterministic-engine-platform-capabilities.md.Dcrnx1-L.lean.js +1 -0
- package/site-dist/assets/reference_adr_0007-one-install-many-repos.md.C78cd4_P.js +1 -0
- package/site-dist/assets/reference_adr_0007-one-install-many-repos.md.C78cd4_P.lean.js +1 -0
- package/site-dist/assets/reference_adr_0008-capability-sources-and-platform-plugin.md.B4vBkIDS.js +1 -0
- package/site-dist/assets/reference_adr_0008-capability-sources-and-platform-plugin.md.B4vBkIDS.lean.js +1 -0
- package/site-dist/assets/reference_adr_index.md.Dx8sPsjs.js +1 -0
- package/site-dist/assets/reference_adr_index.md.Dx8sPsjs.lean.js +1 -0
- package/site-dist/assets/reference_commands.md.BFJRjNju.js +1 -0
- package/site-dist/assets/reference_commands.md.BFJRjNju.lean.js +1 -0
- package/site-dist/assets/reference_config.md.Dt_TJ2y9.js +6 -0
- package/site-dist/assets/reference_config.md.Dt_TJ2y9.lean.js +1 -0
- package/site-dist/assets/reference_contracts_agent-runtime.md.Bu8q-uGl.js +1 -0
- package/site-dist/assets/reference_contracts_agent-runtime.md.Bu8q-uGl.lean.js +1 -0
- package/site-dist/assets/reference_contracts_cli-json.md.Bonk0m6-.js +1 -0
- package/site-dist/assets/reference_contracts_cli-json.md.Bonk0m6-.lean.js +1 -0
- package/site-dist/assets/reference_contracts_feature-files.md.9n332kF_.js +26 -0
- package/site-dist/assets/reference_contracts_feature-files.md.9n332kF_.lean.js +26 -0
- package/site-dist/assets/reference_contracts_index.md.dqNwNs6U.js +1 -0
- package/site-dist/assets/reference_contracts_index.md.dqNwNs6U.lean.js +1 -0
- package/site-dist/assets/reference_contracts_notifier-event.md.D6we9wWS.js +24 -0
- package/site-dist/assets/reference_contracts_notifier-event.md.D6we9wWS.lean.js +24 -0
- package/site-dist/assets/reference_contracts_result-file.md.BmCaSlEu.js +1 -0
- package/site-dist/assets/reference_contracts_result-file.md.BmCaSlEu.lean.js +1 -0
- package/site-dist/assets/reference_contracts_spec.md.CDQYgJz7.js +8 -0
- package/site-dist/assets/reference_contracts_spec.md.CDQYgJz7.lean.js +8 -0
- package/site-dist/assets/reference_contracts_state.md.DVHC4opX.js +1 -0
- package/site-dist/assets/reference_contracts_state.md.DVHC4opX.lean.js +1 -0
- package/site-dist/assets/reference_contracts_usage-record.md.CQI2chqh.js +10 -0
- package/site-dist/assets/reference_contracts_usage-record.md.CQI2chqh.lean.js +10 -0
- package/site-dist/assets/reference_contracts_verify.md.CkJy8LXk.js +29 -0
- package/site-dist/assets/reference_contracts_verify.md.CkJy8LXk.lean.js +29 -0
- package/site-dist/assets/reference_design_adapter-guide.md.BSziZJSM.js +16 -0
- package/site-dist/assets/reference_design_adapter-guide.md.BSziZJSM.lean.js +16 -0
- package/site-dist/assets/reference_design_architecture.md.Bfoc-F2B.js +23 -0
- package/site-dist/assets/reference_design_architecture.md.Bfoc-F2B.lean.js +23 -0
- package/site-dist/assets/reference_design_builtin-capabilities.md.CZYtjo_v.js +7 -0
- package/site-dist/assets/reference_design_builtin-capabilities.md.CZYtjo_v.lean.js +7 -0
- package/site-dist/assets/reference_design_platform-vocabulary.md.xWGv5QO8.js +3 -0
- package/site-dist/assets/reference_design_platform-vocabulary.md.xWGv5QO8.lean.js +3 -0
- package/site-dist/assets/reference_scope.md.aUo6vISB.js +1 -0
- package/site-dist/assets/reference_scope.md.aUo6vISB.lean.js +1 -0
- package/site-dist/assets/style.BX2ZxxqY.css +1 -0
- package/site-dist/changelog.html +30 -0
- package/site-dist/favicon.svg +10 -0
- package/site-dist/guide/dsh.html +34 -0
- package/site-dist/guide/getting-started.html +30 -0
- package/site-dist/guide/how-it-works.html +54 -0
- package/site-dist/guide/index.html +30 -0
- package/site-dist/guide/install.html +48 -0
- package/site-dist/guide/intranet.html +38 -0
- package/site-dist/guide/maintainer.html +30 -0
- package/site-dist/guide/phases.html +30 -0
- package/site-dist/guide/project.html +106 -0
- package/site-dist/guide/user.html +30 -0
- package/site-dist/hashmap.json +1 -0
- package/site-dist/index.html +30 -0
- package/site-dist/logo-light.svg +6 -0
- package/site-dist/logo.svg +6 -0
- package/site-dist/reference/adr/0001-new-repo-core-and-adapters.html +30 -0
- package/site-dist/reference/adr/0002-two-orchestration-modes.html +30 -0
- package/site-dist/reference/adr/0003-generate-once-then-lock.html +30 -0
- package/site-dist/reference/adr/0004-external-contracts-stay-stable.html +30 -0
- package/site-dist/reference/adr/0005-skill-names.html +30 -0
- package/site-dist/reference/adr/0006-deterministic-engine-platform-capabilities.html +30 -0
- package/site-dist/reference/adr/0007-one-install-many-repos.html +30 -0
- package/site-dist/reference/adr/0008-capability-sources-and-platform-plugin.html +30 -0
- package/site-dist/reference/adr/index.html +30 -0
- package/site-dist/reference/commands.html +30 -0
- package/site-dist/reference/config.html +35 -0
- package/site-dist/reference/contracts/agent-runtime.html +30 -0
- package/site-dist/reference/contracts/cli-json.html +30 -0
- package/site-dist/reference/contracts/feature-files.html +55 -0
- package/site-dist/reference/contracts/index.html +30 -0
- package/site-dist/reference/contracts/notifier-event.html +53 -0
- package/site-dist/reference/contracts/result-file.html +30 -0
- package/site-dist/reference/contracts/spec.html +37 -0
- package/site-dist/reference/contracts/state.html +30 -0
- package/site-dist/reference/contracts/usage-record.html +39 -0
- package/site-dist/reference/contracts/verify.html +58 -0
- package/site-dist/reference/design/adapter-guide.html +45 -0
- package/site-dist/reference/design/architecture.html +52 -0
- package/site-dist/reference/design/builtin-capabilities.html +36 -0
- package/site-dist/reference/design/platform-vocabulary.html +32 -0
- package/site-dist/reference/scope.html +30 -0
- package/site-dist/vp-icons.css +1 -0
- package/skills/acceptance-criteria/SKILL.md +61 -0
- package/skills/laoshi/SKILL.md +108 -0
- package/skills/laoshi/playbooks/accept.md +65 -0
- package/skills/laoshi/playbooks/change.md +51 -0
- package/skills/laoshi/playbooks/incident.md +55 -0
- package/skills/laoshi/playbooks/new.md +96 -0
- package/skills/laoshi/playbooks/small.md +48 -0
- package/skills/laoshi/playbooks/status.md +41 -0
- package/skills/laoshi/playbooks/takeover.md +51 -0
- package/skills/laoshi/playbooks/unattended.md +101 -0
- package/skills/laoshi/playbooks/verify.md +57 -0
- package/skills/laoshi-doctor/SKILL.md +36 -0
- package/skills/laoshi-retro/SKILL.md +81 -0
- package/skills/laoshi-setup/SKILL.md +107 -0
- package/skills/laoshi-setup/templates/copy-local-files.mjs +32 -0
- package/skills/principle-delete-before-add/SKILL.md +33 -0
- package/skills/principle-dont-block-on-humans/SKILL.md +35 -0
- package/skills/principle-fix-root-cause/SKILL.md +33 -0
- package/skills/principle-prove-it-works/SKILL.md +33 -0
- package/skills/principle-report-honestly/SKILL.md +33 -0
- package/skills/principle-speak-to-reader/SKILL.md +33 -0
- package/skills/principle-this-requirement-only/SKILL.md +33 -0
- package/skills/requirement-interview/SKILL.md +97 -0
- package/skills/result-report/SKILL.md +34 -0
- package/skills/spec-writing/SKILL.md +58 -0
- package/skills/spec-writing/spec-template.md +109 -0
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
// Checks the parts of the pipeline that depend on your real Paseo setup (the Paseo adapter's
|
|
2
|
+
// smoke test; moved from engine/src in laoshi M2a).
|
|
3
|
+
//
|
|
4
|
+
// npm run smoke -- check daemon, providers, models, modes; one tiny agent per role
|
|
5
|
+
// npm run smoke -- notify --origin-agent <id> message + subagent into an existing chat
|
|
6
|
+
// npm run smoke -- detach-start start a background heartbeat (run from a Paseo chat)
|
|
7
|
+
// npm run smoke -- detach-check is that heartbeat still alive?
|
|
8
|
+
//
|
|
9
|
+
// See docs/guide/安装与升级.md, "冒烟测试", for when to run each one.
|
|
10
|
+
|
|
11
|
+
import { spawn } from "node:child_process";
|
|
12
|
+
import fs from "node:fs";
|
|
13
|
+
import os from "node:os";
|
|
14
|
+
import path from "node:path";
|
|
15
|
+
import { parseArgs } from "node:util";
|
|
16
|
+
import { type AgentProfile, loadConfig, type PipelineConfig } from "../../engine/src/config.js";
|
|
17
|
+
import { checkProfile as checkProfileWith, type Client, connect, type Report, resolveWithDaemon } from "./daemon-check.js";
|
|
18
|
+
import { defaultConfigPath } from "../../engine/src/locations.js";
|
|
19
|
+
|
|
20
|
+
const HEARTBEAT = path.join(os.tmpdir(), "requirement-pipeline-heartbeat.json");
|
|
21
|
+
|
|
22
|
+
function line(ok: boolean, text: string): void {
|
|
23
|
+
console.log(`${ok ? "✓" : "✗"} ${text}`);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const report: Report = (level, text, fix) => {
|
|
27
|
+
line(level !== "fail", text);
|
|
28
|
+
if (fix) console.log(` ${fix}`);
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
async function tinyAgent(client: Client, role: string, profile: AgentProfile): Promise<boolean> {
|
|
32
|
+
const dir = fs.mkdtempSync(path.join(os.tmpdir(), `requirement-pipeline-smoke-${role}-`));
|
|
33
|
+
const agent = await client.agents.create({
|
|
34
|
+
config: {
|
|
35
|
+
provider: profile.provider ?? "",
|
|
36
|
+
...(profile.modeId ? { modeId: profile.modeId } : {}),
|
|
37
|
+
...(profile.thinkingOptionId ? { thinkingOptionId: profile.thinkingOptionId } : {}),
|
|
38
|
+
...(profile.featureValues ? { featureValues: profile.featureValues } : {}),
|
|
39
|
+
},
|
|
40
|
+
cwd: dir,
|
|
41
|
+
title: `[冒烟测试] ${role}`,
|
|
42
|
+
labels: { "requirement-pipeline": "smoke-test" },
|
|
43
|
+
prompt: `在当前目录创建文件 smoke.txt,内容只有一行:ok-${role}。然后用 node 执行 \`node -e "require('fs').writeFileSync('shell.txt','ran')"\`。完成后直接结束,不要做其他事。`,
|
|
44
|
+
});
|
|
45
|
+
console.log(` 已创建 agent ${agent.id},等待它完成(最多 5 分钟)……`);
|
|
46
|
+
try {
|
|
47
|
+
const result = await agent.waitForFinish(5 * 60_000);
|
|
48
|
+
if (result.status === "permission") {
|
|
49
|
+
line(false, `${role}:agent 停下来等待权限批准。请把 agents.${role}.modeId 改成免确认的模式。`);
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
52
|
+
if (result.status !== "idle") {
|
|
53
|
+
line(false, `${role}:agent 结束状态为 ${result.status}:${result.error ?? ""}`);
|
|
54
|
+
return false;
|
|
55
|
+
}
|
|
56
|
+
const wrote = fs.existsSync(path.join(dir, "smoke.txt"));
|
|
57
|
+
const ran = fs.existsSync(path.join(dir, "shell.txt"));
|
|
58
|
+
line(wrote && ran, `${role}:agent 能写文件${wrote ? "" : "(失败)"}、能执行命令${ran ? "" : "(失败)"}`);
|
|
59
|
+
return wrote && ran;
|
|
60
|
+
} finally {
|
|
61
|
+
await agent.archive().catch(() => undefined);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
async function check(config: PipelineConfig): Promise<number> {
|
|
66
|
+
let client: Client;
|
|
67
|
+
try {
|
|
68
|
+
client = await connect(config);
|
|
69
|
+
line(true, `已连接 daemon:${config.daemonUrl}`);
|
|
70
|
+
} catch (error) {
|
|
71
|
+
line(false, `无法连接 daemon ${config.daemonUrl}:${(error as Error).message}`);
|
|
72
|
+
return 1;
|
|
73
|
+
}
|
|
74
|
+
try {
|
|
75
|
+
const snapshot = await client.providers.waitForReady({ timeoutMs: 60_000 });
|
|
76
|
+
console.log(" daemon 上可用的 provider:");
|
|
77
|
+
for (const entry of snapshot.entries) {
|
|
78
|
+
console.log(` - ${entry.provider}(${entry.status})`);
|
|
79
|
+
}
|
|
80
|
+
try {
|
|
81
|
+
config = await resolveWithDaemon(client, config);
|
|
82
|
+
} catch (error) {
|
|
83
|
+
line(false, (error as Error).message);
|
|
84
|
+
return 1;
|
|
85
|
+
}
|
|
86
|
+
let ok = true;
|
|
87
|
+
for (const role of ["builder", "reviewer"] as const) {
|
|
88
|
+
ok = (await checkProfileWith(client, role, config.agents[role], report)) && ok;
|
|
89
|
+
}
|
|
90
|
+
if (!ok) {
|
|
91
|
+
console.log("\n请先修正 ~/.req-kit/config.json 中的 provider/model 和 modeId,再重新运行。");
|
|
92
|
+
return 1;
|
|
93
|
+
}
|
|
94
|
+
for (const role of ["builder", "reviewer"] as const) {
|
|
95
|
+
ok = (await tinyAgent(client, role, config.agents[role])) && ok;
|
|
96
|
+
}
|
|
97
|
+
console.log(ok ? "\n全部通过。" : "\n有检查没有通过,见上面的 ✗。");
|
|
98
|
+
return ok ? 0 : 1;
|
|
99
|
+
} finally {
|
|
100
|
+
await client.close();
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
async function notify(config: PipelineConfig, origin: string): Promise<number> {
|
|
105
|
+
const client = await connect(config);
|
|
106
|
+
try {
|
|
107
|
+
await client.agents.ref(origin).send(
|
|
108
|
+
"【需求开发流水线通知】这是一条冒烟测试消息,不是用户发的。请回复用户:\"流水线的通知通道工作正常。\"",
|
|
109
|
+
{ activeTurnBehavior: "steer" },
|
|
110
|
+
);
|
|
111
|
+
line(true, `已向 agent ${origin} 发送测试通知。请到该对话中确认 agent 转告了"通知通道工作正常"。`);
|
|
112
|
+
|
|
113
|
+
config = await resolveWithDaemon(client, config);
|
|
114
|
+
const child = await client.agents.create({
|
|
115
|
+
config: {
|
|
116
|
+
provider: config.agents.builder.provider ?? "",
|
|
117
|
+
...(config.agents.builder.modeId ? { modeId: config.agents.builder.modeId } : {}),
|
|
118
|
+
},
|
|
119
|
+
cwd: process.cwd(),
|
|
120
|
+
parent: origin,
|
|
121
|
+
title: "[冒烟测试] 子 agent",
|
|
122
|
+
labels: { "requirement-pipeline": "smoke-test" },
|
|
123
|
+
prompt: "只回复\"ok\",然后结束。不要读写任何文件。",
|
|
124
|
+
});
|
|
125
|
+
const result = await child.waitForFinish(3 * 60_000);
|
|
126
|
+
line(result.status === "idle", `已在该对话下创建子 agent ${child.id}(结束状态 ${result.status})。请确认它出现在对话的子 agent 列表中。`);
|
|
127
|
+
await child.archive().catch(() => undefined);
|
|
128
|
+
return result.status === "idle" ? 0 : 1;
|
|
129
|
+
} catch (error) {
|
|
130
|
+
line(false, (error as Error).message);
|
|
131
|
+
return 1;
|
|
132
|
+
} finally {
|
|
133
|
+
await client.close();
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
function detachStart(): number {
|
|
138
|
+
const script = `
|
|
139
|
+
const fs = require("fs");
|
|
140
|
+
const end = Date.now() + 10 * 60_000;
|
|
141
|
+
const beat = () => fs.writeFileSync(${JSON.stringify(HEARTBEAT)}, JSON.stringify({ pid: process.pid, at: Date.now(), startedAt }));
|
|
142
|
+
const startedAt = Date.now();
|
|
143
|
+
beat();
|
|
144
|
+
const timer = setInterval(() => { if (Date.now() > end) { clearInterval(timer); return; } beat(); }, 2000);
|
|
145
|
+
`;
|
|
146
|
+
// Same detach mechanism as launch.ts.
|
|
147
|
+
const child = spawn(process.execPath, ["-e", script], { detached: true, windowsHide: true, stdio: "ignore" });
|
|
148
|
+
child.unref();
|
|
149
|
+
console.log(`已启动后台心跳进程 ${child.pid}(持续 10 分钟),心跳文件:${HEARTBEAT}`);
|
|
150
|
+
console.log("请结束这一轮对话,等待至少 1 分钟后,再让 agent 运行 detach-check。");
|
|
151
|
+
return 0;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
function detachCheck(): number {
|
|
155
|
+
if (!fs.existsSync(HEARTBEAT)) {
|
|
156
|
+
line(false, "找不到心跳文件,请先运行 detach-start");
|
|
157
|
+
return 1;
|
|
158
|
+
}
|
|
159
|
+
const beat = JSON.parse(fs.readFileSync(HEARTBEAT, "utf8")) as { pid: number; at: number; startedAt: number };
|
|
160
|
+
const age = Math.round((Date.now() - beat.at) / 1000);
|
|
161
|
+
const ranFor = Math.round((beat.at - beat.startedAt) / 1000);
|
|
162
|
+
const alive = age < 10;
|
|
163
|
+
line(
|
|
164
|
+
alive,
|
|
165
|
+
alive
|
|
166
|
+
? `后台进程 ${beat.pid} 仍在运行(已运行 ${ranFor} 秒)。聊天 agent 启动的后台流水线可以在它的回合结束后继续运行。`
|
|
167
|
+
: `后台进程 ${beat.pid} 在启动后约 ${ranFor} 秒停止(最后一次心跳在 ${age} 秒前)。` +
|
|
168
|
+
"聊天 agent 的回合结束时,它启动的后台进程被终止了;需要改用插件方式启动流水线。",
|
|
169
|
+
);
|
|
170
|
+
return alive ? 0 : 1;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
async function main(): Promise<number> {
|
|
174
|
+
const { values, positionals } = parseArgs({
|
|
175
|
+
args: process.argv.slice(2),
|
|
176
|
+
options: { "origin-agent": { type: "string" }, config: { type: "string" } },
|
|
177
|
+
allowPositionals: true,
|
|
178
|
+
});
|
|
179
|
+
const command = positionals[0];
|
|
180
|
+
if (command === "detach-start") return detachStart();
|
|
181
|
+
if (command === "detach-check") return detachCheck();
|
|
182
|
+
|
|
183
|
+
const config = loadConfig(values.config ? path.resolve(values.config) : defaultConfigPath()).config;
|
|
184
|
+
if (command === "check") return check(config);
|
|
185
|
+
if (command === "notify") {
|
|
186
|
+
const origin = values["origin-agent"] ?? process.env.PASEO_AGENT_ID;
|
|
187
|
+
if (!origin) {
|
|
188
|
+
console.error("需要 --origin-agent <agent ID>,或在 Paseo 的聊天中运行(自动读取 PASEO_AGENT_ID)");
|
|
189
|
+
return 2;
|
|
190
|
+
}
|
|
191
|
+
return notify(config, origin);
|
|
192
|
+
}
|
|
193
|
+
console.error("用法:npm run smoke -- check | notify --origin-agent <id> | detach-start | detach-check");
|
|
194
|
+
return 2;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
main().then(
|
|
198
|
+
(code) => process.exit(code),
|
|
199
|
+
(error: Error) => {
|
|
200
|
+
console.error(error.message);
|
|
201
|
+
process.exit(1);
|
|
202
|
+
},
|
|
203
|
+
);
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// The one-step install from npm, as paseo-req-kit does it: a machine that can reach an npm registry
|
|
3
|
+
// (the public one or a company mirror) needs nothing else.
|
|
4
|
+
//
|
|
5
|
+
// npx -y @yiyi_zhang/laoshi@latest install --platform dsh
|
|
6
|
+
// npx -y --registry=https://npm.example.internal/ @yiyi_zhang/laoshi@latest install --platform dsh
|
|
7
|
+
// laoshi upgrade [--registry <url>] (the same with @yiyi_zhang/laoshi@latest)
|
|
8
|
+
//
|
|
9
|
+
// Steps: check Node.js, npm and git; use (and save) the npm registry; npm install -g this version
|
|
10
|
+
// (into <install root>/npm when the global directory is not writable); then run the installed
|
|
11
|
+
// copy's `laoshi install` (bin/install.mjs) with the remaining options. npx's copy is temporary,
|
|
12
|
+
// so nothing may point at it. Running it again upgrades in place. On Windows npm runs through
|
|
13
|
+
// cmd.exe, never PowerShell.
|
|
14
|
+
//
|
|
15
|
+
// Tests: LAOSHI_NPM is a script standing in for npm.
|
|
16
|
+
import { spawnSync } from "node:child_process";
|
|
17
|
+
import fs from "node:fs";
|
|
18
|
+
import os from "node:os";
|
|
19
|
+
import path from "node:path";
|
|
20
|
+
import { fileURLToPath } from "node:url";
|
|
21
|
+
|
|
22
|
+
const KIT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..");
|
|
23
|
+
const PKG = JSON.parse(fs.readFileSync(path.join(KIT, "package.json"), "utf8"));
|
|
24
|
+
const WINDOWS = process.platform === "win32";
|
|
25
|
+
const DEFAULT_REGISTRY = "https://registry.npmjs.org/";
|
|
26
|
+
|
|
27
|
+
class Abort extends Error {}
|
|
28
|
+
const die = (text) => {
|
|
29
|
+
throw new Abort(text);
|
|
30
|
+
};
|
|
31
|
+
const say = (text) => console.log(text);
|
|
32
|
+
const ok = (text) => console.log(`✓ ${text}`);
|
|
33
|
+
const warn = (text) => console.log(`⚠ ${text}`);
|
|
34
|
+
const step = (title) => console.log(`\n## ${title}\n`);
|
|
35
|
+
|
|
36
|
+
/** Bootstrap options; everything else goes to `laoshi install`. */
|
|
37
|
+
export function parseArgs(argv) {
|
|
38
|
+
const opts = { registry: null, saveRegistry: true, spec: null, help: false, rest: [] };
|
|
39
|
+
for (let i = 0; i < argv.length; i++) {
|
|
40
|
+
const a = argv[i];
|
|
41
|
+
const value = (name) => {
|
|
42
|
+
if (i + 1 >= argv.length || argv[i + 1].startsWith("--")) die(`${name} 后面要写值,例如 ${name} https://npm.example.internal/`);
|
|
43
|
+
return argv[++i];
|
|
44
|
+
};
|
|
45
|
+
if (a === "--registry") opts.registry = value("--registry");
|
|
46
|
+
else if (a.startsWith("--registry=")) opts.registry = a.slice("--registry=".length);
|
|
47
|
+
else if (a === "--spec") opts.spec = value("--spec");
|
|
48
|
+
else if (a.startsWith("--spec=")) opts.spec = a.slice("--spec=".length);
|
|
49
|
+
else if (a === "--no-save-registry") opts.saveRegistry = false;
|
|
50
|
+
else if (a === "-h" || a === "--help") opts.help = true;
|
|
51
|
+
else opts.rest.push(a);
|
|
52
|
+
}
|
|
53
|
+
if (opts.registry !== null && !/^https?:\/\/\S+$/.test(opts.registry)) die(`--registry 要写完整的地址,例如 https://npm.example.internal/(现在是 ${opts.registry || "空"})`);
|
|
54
|
+
return opts;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export const sameRegistry = (a, b) => String(a ?? "").trim().replace(/\/+$/, "").toLowerCase() === String(b ?? "").trim().replace(/\/+$/, "").toLowerCase();
|
|
58
|
+
|
|
59
|
+
/** The environment for npm: without the settings npx adds for itself; the registry set explicitly. */
|
|
60
|
+
function childEnv(registry) {
|
|
61
|
+
const env = { ...process.env };
|
|
62
|
+
for (const key of Object.keys(env)) {
|
|
63
|
+
const k = key.toLowerCase();
|
|
64
|
+
if (["npm_config_package", "npm_config_yes", "npm_config_call", "npm_config_local_prefix", "npm_command", "npm_package_json", "npm_config_registry"].includes(k) || k.startsWith("npm_lifecycle_")) delete env[key];
|
|
65
|
+
}
|
|
66
|
+
if (registry) env.npm_config_registry = registry;
|
|
67
|
+
return env;
|
|
68
|
+
}
|
|
69
|
+
let ENV = childEnv(null);
|
|
70
|
+
|
|
71
|
+
const quoteForCmd = (args) => args.map((a) => (/[\s&()^|<>"]/.test(a) ? `"${a.replace(/"/g, '""')}"` : a));
|
|
72
|
+
|
|
73
|
+
/** Runs a command; on Windows the npm.cmd shim needs cmd.exe (the shell node uses there). */
|
|
74
|
+
function run(command, args, { inherit = false, env = ENV, timeout = 900_000 } = {}) {
|
|
75
|
+
const shell = WINDOWS && !/\.exe$/i.test(command);
|
|
76
|
+
const r = spawnSync(command, shell ? quoteForCmd(args) : args, { encoding: "utf8", windowsHide: true, shell, env, timeout, stdio: inherit ? "inherit" : ["ignore", "pipe", "pipe"] });
|
|
77
|
+
return { status: r.error ? null : r.status, stdout: r.stdout ?? "", stderr: r.stderr ?? "" };
|
|
78
|
+
}
|
|
79
|
+
function npm(args, options = {}) {
|
|
80
|
+
const fake = process.env.LAOSHI_NPM?.trim();
|
|
81
|
+
if (fake) return run(process.execPath, [fake, ...args], options);
|
|
82
|
+
return run(WINDOWS ? "npm.cmd" : "npm", args, options);
|
|
83
|
+
}
|
|
84
|
+
const writable = (dir) => {
|
|
85
|
+
try {
|
|
86
|
+
fs.accessSync(dir, fs.constants.W_OK);
|
|
87
|
+
return true;
|
|
88
|
+
} catch {
|
|
89
|
+
return false;
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
const HELP = `用法:npx -y [--registry=<npm 源>] @yiyi_zhang/laoshi@latest install --platform <平台> [安装选项]
|
|
94
|
+
|
|
95
|
+
--registry <地址> 这次安装用的 npm 源(公司内网的镜像),默认保存为本机的 npm 源
|
|
96
|
+
--no-save-registry 只这次用,不保存
|
|
97
|
+
--spec <包> 安装哪个版本,默认是正在运行的这个(如 @yiyi_zhang/laoshi@0.1.1)
|
|
98
|
+
其余选项交给 laoshi install(--platform、--home、--target、--force、平台的选项,见 laoshi install --help)。`;
|
|
99
|
+
|
|
100
|
+
export async function main(argv) {
|
|
101
|
+
const opts = parseArgs(argv);
|
|
102
|
+
if (opts.help) {
|
|
103
|
+
say(HELP);
|
|
104
|
+
return 0;
|
|
105
|
+
}
|
|
106
|
+
const spec = opts.spec ?? `${PKG.name}@${PKG.version}`;
|
|
107
|
+
say(`安装 laoshi(${spec})`);
|
|
108
|
+
|
|
109
|
+
step("检查环境");
|
|
110
|
+
const [major, minor] = process.versions.node.split(".").map(Number);
|
|
111
|
+
if (major < 22 || (major === 22 && minor < 19)) die(`需要 Node.js 22.19 或更新版本,当前是 ${process.version}`);
|
|
112
|
+
ok(`Node.js ${process.version}`);
|
|
113
|
+
const npmVersion = npm(["--version"], { timeout: 60_000 });
|
|
114
|
+
if (npmVersion.status !== 0) die("没有找到 npm(通常随 Node.js 一起安装)");
|
|
115
|
+
ok(`npm ${npmVersion.stdout.trim() || "?"}`);
|
|
116
|
+
|
|
117
|
+
step("npm 源");
|
|
118
|
+
// `npx --registry=…` passes it on as npm_config_registry; --registry says it explicitly.
|
|
119
|
+
const wanted = opts.registry ?? process.env.npm_config_registry?.trim() ?? process.env.NPM_CONFIG_REGISTRY?.trim() ?? null;
|
|
120
|
+
const savedResult = npm(["config", "get", "registry"], { env: childEnv(null), timeout: 60_000 });
|
|
121
|
+
const saved = savedResult.status === 0 ? savedResult.stdout.trim() || DEFAULT_REGISTRY : DEFAULT_REGISTRY;
|
|
122
|
+
let registry = saved;
|
|
123
|
+
if (wanted && !sameRegistry(wanted, saved)) {
|
|
124
|
+
registry = wanted;
|
|
125
|
+
if (opts.saveRegistry && npm(["config", "set", "registry", wanted], { env: childEnv(null), timeout: 60_000 }).status === 0) ok(`已把本机的 npm 源设为 ${wanted}(原来是 ${saved})。以后 laoshi upgrade 也从这里取`);
|
|
126
|
+
else ok(`这次安装使用 ${wanted}(本机的 npm 源仍是 ${saved})`);
|
|
127
|
+
} else ok(`npm 源:${saved}`);
|
|
128
|
+
ENV = childEnv(registry);
|
|
129
|
+
if (sameRegistry(registry, DEFAULT_REGISTRY)) say(" 公司内网请改用镜像:npx -y --registry=<镜像地址> @yiyi_zhang/laoshi@latest install");
|
|
130
|
+
|
|
131
|
+
step(`安装 ${spec}`);
|
|
132
|
+
const found = npm(["view", spec, "version"], { timeout: 120_000 });
|
|
133
|
+
if (found.status !== 0 || !found.stdout.trim()) die(`npm 源 ${registry} 上找不到 ${spec}。镜像可能还没有同步这个版本,稍后再试;或用 --registry 换一个 npm 源`);
|
|
134
|
+
let prefix = npm(["prefix", "-g"], { timeout: 60_000 }).stdout.trim();
|
|
135
|
+
let ownPrefix = false;
|
|
136
|
+
const isRoot = typeof process.getuid === "function" && process.getuid() === 0;
|
|
137
|
+
if (!prefix || (!isRoot && !writable(prefix))) {
|
|
138
|
+
// A system Node.js (e.g. /usr/local) needs sudo for global installs; use a directory of our own.
|
|
139
|
+
const home = path.resolve(process.env.LAOSHI_HOME ?? path.join(os.homedir(), ".laoshi"));
|
|
140
|
+
prefix = path.join(home, "npm");
|
|
141
|
+
ownPrefix = true;
|
|
142
|
+
fs.mkdirSync(prefix, { recursive: true });
|
|
143
|
+
warn(`npm 的全局目录不可写,改装到 ${prefix}(不需要 sudo)`);
|
|
144
|
+
}
|
|
145
|
+
const prefixArgs = ownPrefix ? ["--prefix", prefix] : [];
|
|
146
|
+
if (npm(["install", "-g", ...prefixArgs, spec], { inherit: true }).status !== 0) die("npm 安装失败(见上面的输出)。公司内网请确认 npm 源是镜像地址(--registry)");
|
|
147
|
+
const npmRoot = npm(["root", "-g", ...prefixArgs], { timeout: 60_000 }).stdout.trim();
|
|
148
|
+
const copy = path.join(npmRoot, PKG.name);
|
|
149
|
+
const installer = path.join(copy, "bin", "install.mjs");
|
|
150
|
+
if (!fs.existsSync(installer)) die(`安装后没有找到 ${installer}`);
|
|
151
|
+
const version = JSON.parse(fs.readFileSync(path.join(copy, "package.json"), "utf8")).version;
|
|
152
|
+
ok(`已安装 laoshi ${version} 到 ${copy}`);
|
|
153
|
+
const binDir = WINDOWS ? prefix : path.join(prefix, "bin");
|
|
154
|
+
const onPath = (process.env.PATH ?? "").split(path.delimiter).some((p) => p && path.resolve(p) === path.resolve(binDir) && !p.split(/[\\/]/).includes("_npx"));
|
|
155
|
+
if (!onPath) warn(`laoshi 命令在 ${binDir},它不在 PATH 中:把它加进 PATH,或使用安装根 bin 目录中的 laoshi(见下面的"命令"一节)`);
|
|
156
|
+
|
|
157
|
+
// From here on, the installed copy: npx's copy goes away.
|
|
158
|
+
const r = spawnSync(process.execPath, [installer, ...opts.rest], { stdio: "inherit", windowsHide: true, env: childEnv(registry) });
|
|
159
|
+
return r.status ?? 1;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
if (process.argv[1] && path.resolve(process.argv[1]) === fileURLToPath(import.meta.url)) {
|
|
163
|
+
main(process.argv.slice(2)).then(
|
|
164
|
+
(code) => process.exit(code),
|
|
165
|
+
(error) => {
|
|
166
|
+
console.error(error instanceof Abort ? `✗ ${error.message}` : error);
|
|
167
|
+
process.exit(1);
|
|
168
|
+
},
|
|
169
|
+
);
|
|
170
|
+
}
|
package/bin/install.mjs
ADDED
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// `laoshi install`: sets up this machine for the laoshi in this directory (installed with npm,
|
|
3
|
+
// or unpacked from an offline package). Plain Node.js; on Windows it starts only node and cmd.exe.
|
|
4
|
+
//
|
|
5
|
+
// laoshi install [--platform <id>] [--home <LAOSHI_HOME>] [--target <skills dir>]… [--force]
|
|
6
|
+
// [--check] [--uninstall] [--dry-run] [platform options, e.g. --dsh-home, --profile]
|
|
7
|
+
//
|
|
8
|
+
// 1. the install root (LAOSHI_HOME) and its install-level config.json (platform, agents)
|
|
9
|
+
// 2. the skills, rendered for the platform (engine/src/skills-render.ts), into the platform's
|
|
10
|
+
// skills directories (adapters/<id>/install.mjs) and any --target; each skill directory gets a
|
|
11
|
+
// .laoshi-install.json marker, and directories without it are left alone unless --force
|
|
12
|
+
// 3. the platform's own setup (adapters/<id>/install.mjs), e.g. dsh's plugin
|
|
13
|
+
// 4. `laoshi` and `req` commands in <install root>/bin, for installs that npm did not put on PATH
|
|
14
|
+
// install.json in the install root records what was installed, for --check and --uninstall.
|
|
15
|
+
import { spawnSync } from "node:child_process";
|
|
16
|
+
import crypto from "node:crypto";
|
|
17
|
+
import fs from "node:fs";
|
|
18
|
+
import os from "node:os";
|
|
19
|
+
import path from "node:path";
|
|
20
|
+
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
21
|
+
import { parseArgs } from "node:util";
|
|
22
|
+
|
|
23
|
+
const kit = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..");
|
|
24
|
+
const version = JSON.parse(fs.readFileSync(path.join(kit, "package.json"), "utf8")).version;
|
|
25
|
+
export const MARKER = ".laoshi-install.json";
|
|
26
|
+
const REQ_KIT_MARKER = ".req-kit-install.json";
|
|
27
|
+
|
|
28
|
+
const platforms = fs.readdirSync(path.join(kit, "adapters")).filter((d) => fs.existsSync(path.join(kit, "adapters", d, "install.mjs")));
|
|
29
|
+
const modules = Object.fromEntries(await Promise.all(platforms.map(async (p) => [p, await import(pathToFileURL(path.join(kit, "adapters", p, "install.mjs")).href)])));
|
|
30
|
+
const platformOptions = Object.assign({}, ...Object.values(modules).map((m) => m.options ?? {}));
|
|
31
|
+
const { values: args } = parseArgs({
|
|
32
|
+
options: {
|
|
33
|
+
platform: { type: "string" },
|
|
34
|
+
home: { type: "string" },
|
|
35
|
+
target: { type: "string", multiple: true, default: [] },
|
|
36
|
+
force: { type: "boolean", default: false },
|
|
37
|
+
check: { type: "boolean", default: false },
|
|
38
|
+
uninstall: { type: "boolean", default: false },
|
|
39
|
+
"dry-run": { type: "boolean", default: false },
|
|
40
|
+
help: { type: "boolean", short: "h", default: false },
|
|
41
|
+
...platformOptions,
|
|
42
|
+
},
|
|
43
|
+
});
|
|
44
|
+
if (args.help) {
|
|
45
|
+
console.log(`用法:laoshi install --platform <${platforms.join("|")}> [选项]
|
|
46
|
+
|
|
47
|
+
--platform <平台> 装到哪个 agent 平台(第一次安装时要写;之后沿用安装记录)
|
|
48
|
+
--home <目录> 安装根,默认 LAOSHI_HOME 或 ~/.laoshi
|
|
49
|
+
--target <目录> 另外把 skill 装到这个目录(可以写多次)
|
|
50
|
+
--force 覆盖同名的、不是 laoshi 装的 skill
|
|
51
|
+
--check 只检查安装,不改动
|
|
52
|
+
--dry-run 演练:显示要做的事,不写文件
|
|
53
|
+
--uninstall 卸载 skill 和平台的设置(安装根保留)
|
|
54
|
+
dsh 的选项:--dsh-home <DSH_HOME> --profile <名称> --dsh-bin <dsh 的 bin.js> --approvals ask|allow`);
|
|
55
|
+
process.exit(0);
|
|
56
|
+
}
|
|
57
|
+
const dry = args["dry-run"] || args.check;
|
|
58
|
+
const home = path.resolve(args.home ?? process.env.LAOSHI_HOME ?? path.join(os.homedir(), ".laoshi"));
|
|
59
|
+
const configPath = path.join(home, "config.json");
|
|
60
|
+
const recordPath = path.join(home, "install.json");
|
|
61
|
+
|
|
62
|
+
let problems = 0;
|
|
63
|
+
const SYMBOL = { ok: "✓", warn: "⚠", fail: "✗", info: "·" };
|
|
64
|
+
function report(level, text, fix) {
|
|
65
|
+
if (level === "fail") problems += 1;
|
|
66
|
+
console.log(`${SYMBOL[level]} ${text}${fix ? `\n 修复:${fix}` : ""}`);
|
|
67
|
+
}
|
|
68
|
+
const section = (title) => console.log(`\n## ${title}\n`);
|
|
69
|
+
const readJson = (file) => {
|
|
70
|
+
try {
|
|
71
|
+
return JSON.parse(fs.readFileSync(file, "utf8"));
|
|
72
|
+
} catch {
|
|
73
|
+
return null;
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
/** "ours", "req-kit" (installed by req-kit), "foreign", "symlink" or "absent". */
|
|
78
|
+
function ownership(dir) {
|
|
79
|
+
try {
|
|
80
|
+
if (fs.lstatSync(dir).isSymbolicLink()) return "symlink";
|
|
81
|
+
} catch {
|
|
82
|
+
return "absent";
|
|
83
|
+
}
|
|
84
|
+
if (fs.existsSync(path.join(dir, MARKER))) return "ours";
|
|
85
|
+
if (fs.existsSync(path.join(dir, REQ_KIT_MARKER))) return "req-kit";
|
|
86
|
+
return "foreign";
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/** Every file of the rendered skill is in the installed one with the same content. */
|
|
90
|
+
function sameFiles(src, dest) {
|
|
91
|
+
try {
|
|
92
|
+
return listFiles(src).every((f) => fs.readFileSync(path.join(src, f)).equals(fs.readFileSync(path.join(dest, f))));
|
|
93
|
+
} catch {
|
|
94
|
+
return false;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function listFiles(dir, base = dir) {
|
|
99
|
+
return fs.readdirSync(dir, { withFileTypes: true }).flatMap((e) => (e.isDirectory() ? listFiles(path.join(dir, e.name), base) : [path.relative(base, path.join(dir, e.name))]));
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
console.log(`laoshi ${version} 安装${args.check ? "检查(只报告,不改动)" : args["dry-run"] ? "(演练:不写文件)" : args.uninstall ? ":卸载" : ""}\n程序目录:${kit}\n安装根:${home}`);
|
|
103
|
+
|
|
104
|
+
// ---------------------------------------------------------------------------------------------
|
|
105
|
+
section("环境");
|
|
106
|
+
const [major, minor] = process.versions.node.split(".").map(Number);
|
|
107
|
+
if (major > 22 || (major === 22 && minor >= 19)) report("ok", `Node.js ${process.versions.node}`);
|
|
108
|
+
else report("fail", `Node.js ${process.versions.node} 太旧`, "laoshi 需要 Node.js 22.19 或更新");
|
|
109
|
+
const git = spawnSync("git", ["--version"], { encoding: "utf8", windowsHide: true });
|
|
110
|
+
if (git.status === 0) report("ok", git.stdout.trim());
|
|
111
|
+
else report("fail", "找不到 git", "安装 git(Windows:Git for Windows),并确认 git 在 PATH 中");
|
|
112
|
+
const tsx = path.join(kit, "node_modules", "tsx", "dist", "cli.mjs");
|
|
113
|
+
const tsxCli = fs.existsSync(tsx) ? tsx : (() => {
|
|
114
|
+
try {
|
|
115
|
+
return path.join(path.dirname(fileURLToPath(import.meta.resolve("tsx/package.json"))), "dist", "cli.mjs");
|
|
116
|
+
} catch {
|
|
117
|
+
return null;
|
|
118
|
+
}
|
|
119
|
+
})();
|
|
120
|
+
if (tsxCli && fs.existsSync(tsxCli)) report("ok", "依赖已就绪");
|
|
121
|
+
else report("fail", "缺少依赖(tsx)", "用 npm 安装 laoshi,或在程序目录执行 npm ci --omit=dev;内网用带依赖的离线安装包");
|
|
122
|
+
if (problems > 0) process.exit(1);
|
|
123
|
+
|
|
124
|
+
const existing = readJson(configPath);
|
|
125
|
+
const record = readJson(recordPath);
|
|
126
|
+
const platform = args.platform ?? existing?.platform?.adapter ?? record?.platform ?? null;
|
|
127
|
+
if (!platform) {
|
|
128
|
+
report("fail", "没有指定平台", `加上 --platform ${platforms.join(" 或 --platform ")}`);
|
|
129
|
+
process.exit(1);
|
|
130
|
+
}
|
|
131
|
+
const mod = modules[platform];
|
|
132
|
+
if (!mod) {
|
|
133
|
+
report("fail", `没有平台「${platform}」`, `可选:${platforms.join("、")}`);
|
|
134
|
+
process.exit(1);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
// ---------------------------------------------------------------------------------------------
|
|
138
|
+
if (args.uninstall) {
|
|
139
|
+
section("卸载");
|
|
140
|
+
for (const dir of record?.targets ?? []) {
|
|
141
|
+
for (const name of fs.existsSync(dir) ? fs.readdirSync(dir) : []) {
|
|
142
|
+
if (ownership(path.join(dir, name)) === "ours") fs.rmSync(path.join(dir, name), { recursive: true, force: true });
|
|
143
|
+
}
|
|
144
|
+
report("ok", `已从 ${dir} 删除 laoshi 安装的 skill`);
|
|
145
|
+
}
|
|
146
|
+
mod.uninstall?.({ args, config: existing, report });
|
|
147
|
+
for (const f of ["laoshi", "laoshi.cmd", "req", "req.cmd"]) fs.rmSync(path.join(home, "bin", f), { force: true });
|
|
148
|
+
fs.rmSync(recordPath, { force: true });
|
|
149
|
+
report("ok", `保留了安装根 ${home}(配置、使用记录);不再需要时可以手工删除`);
|
|
150
|
+
process.exit(problems > 0 ? 1 : 0);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
// ---------------------------------------------------------------------------------------------
|
|
154
|
+
section("安装级配置");
|
|
155
|
+
if (existing) {
|
|
156
|
+
const current = existing.platform?.adapter ?? "paseo";
|
|
157
|
+
if (current !== platform) {
|
|
158
|
+
report("fail", `${configPath} 用的平台是 ${current},这次要装的是 ${platform}`, `把其中的 platform 改成 { "adapter": "${platform}" },或用 --home 换一个安装根`);
|
|
159
|
+
process.exit(1);
|
|
160
|
+
}
|
|
161
|
+
report("ok", `已有 ${configPath}(平台 ${platform}),不改动`);
|
|
162
|
+
} else {
|
|
163
|
+
const config = { platform: mod.platformConfig(args), agents: mod.defaultAgents };
|
|
164
|
+
if (!dry) {
|
|
165
|
+
fs.mkdirSync(home, { recursive: true });
|
|
166
|
+
fs.writeFileSync(configPath, `${JSON.stringify(config, null, 2)}\n`);
|
|
167
|
+
}
|
|
168
|
+
report("ok", `${dry ? "将写入" : "写入"} ${configPath}(平台 ${platform})`);
|
|
169
|
+
}
|
|
170
|
+
const config = existing ?? { platform: mod.platformConfig(args) };
|
|
171
|
+
|
|
172
|
+
// ---------------------------------------------------------------------------------------------
|
|
173
|
+
section("skill");
|
|
174
|
+
const targets = [...mod.skillTargets(args, config), ...args.target.map((t) => ({ dir: path.resolve(t), label: `自定义目录 ${path.resolve(t)}` }))];
|
|
175
|
+
const rendered = fs.mkdtempSync(path.join(os.tmpdir(), "laoshi-skills-"));
|
|
176
|
+
const renderConfig = path.join(rendered, "config.json");
|
|
177
|
+
fs.writeFileSync(renderConfig, JSON.stringify(config));
|
|
178
|
+
const out = path.join(rendered, "skills");
|
|
179
|
+
const r = spawnSync(process.execPath, [tsxCli, path.join(kit, "engine", "src", "skills-render.ts"), "--out", out, "--config", renderConfig], { encoding: "utf8", windowsHide: true, env: { ...process.env, LAOSHI_HOME: home } });
|
|
180
|
+
if (r.status !== 0) {
|
|
181
|
+
report("fail", `为 ${platform} 渲染 skill 失败:${(r.stderr || r.stdout).trim()}`);
|
|
182
|
+
process.exit(1);
|
|
183
|
+
}
|
|
184
|
+
const skills = fs.readdirSync(out).filter((n) => fs.existsSync(path.join(out, n, "SKILL.md")));
|
|
185
|
+
for (const target of targets) {
|
|
186
|
+
const blocked = [];
|
|
187
|
+
let changed = 0;
|
|
188
|
+
for (const name of skills) {
|
|
189
|
+
const dir = path.join(target.dir, name);
|
|
190
|
+
const owner = ownership(dir);
|
|
191
|
+
if (owner === "symlink" || ((owner === "foreign" || owner === "req-kit") && !args.force)) {
|
|
192
|
+
blocked.push(`${name}(${owner === "req-kit" ? "req-kit 安装的" : owner === "symlink" ? "符号链接" : "不是 laoshi 安装的"})`);
|
|
193
|
+
continue;
|
|
194
|
+
}
|
|
195
|
+
if (dry) {
|
|
196
|
+
if (!sameFiles(path.join(out, name), dir)) changed += 1;
|
|
197
|
+
continue;
|
|
198
|
+
}
|
|
199
|
+
fs.rmSync(dir, { recursive: true, force: true });
|
|
200
|
+
fs.cpSync(path.join(out, name), dir, { recursive: true });
|
|
201
|
+
const files = Object.fromEntries(listFiles(dir).map((f) => [f.split(path.sep).join("/"), crypto.createHash("sha256").update(fs.readFileSync(path.join(dir, f))).digest("hex")]));
|
|
202
|
+
fs.writeFileSync(path.join(dir, MARKER), `${JSON.stringify({ name: "laoshi", skill: name, version, root: kit, platform, installedAt: new Date().toISOString(), files }, null, 2)}\n`);
|
|
203
|
+
changed += 1;
|
|
204
|
+
}
|
|
205
|
+
// Skills an earlier laoshi installed that this one no longer has.
|
|
206
|
+
const stale = fs.existsSync(target.dir) ? fs.readdirSync(target.dir).filter((n) => !skills.includes(n) && ownership(path.join(target.dir, n)) === "ours") : [];
|
|
207
|
+
if (!dry) for (const n of stale) fs.rmSync(path.join(target.dir, n), { recursive: true, force: true });
|
|
208
|
+
const done = dry ? (changed ? `将安装或更新 ${changed} 个 skill` : `${skills.length - blocked.length} 个 skill 已是这个版本的`) : `已安装 ${changed} 个 skill`;
|
|
209
|
+
report(blocked.length || (args.check && changed) ? "warn" : "ok", `${target.label}:${done}${stale.length ? `,删除旧版本留下的 ${stale.join("、")}` : ""}${blocked.length ? `;没有覆盖 ${blocked.join("、")}` : ""}`, blocked.length ? "确认可以覆盖时加 --force" : undefined);
|
|
210
|
+
}
|
|
211
|
+
fs.rmSync(rendered, { recursive: true, force: true });
|
|
212
|
+
|
|
213
|
+
// ---------------------------------------------------------------------------------------------
|
|
214
|
+
section(`平台:${platform}`);
|
|
215
|
+
let next = [];
|
|
216
|
+
try {
|
|
217
|
+
next = mod.setup({ kit, args, config, dry, report }) ?? [];
|
|
218
|
+
} catch (error) {
|
|
219
|
+
report("fail", error.message);
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
// ---------------------------------------------------------------------------------------------
|
|
223
|
+
section("命令");
|
|
224
|
+
const bin = path.join(home, "bin");
|
|
225
|
+
if (!dry) {
|
|
226
|
+
fs.mkdirSync(bin, { recursive: true });
|
|
227
|
+
const entry = path.join(kit, "bin", "req.mjs");
|
|
228
|
+
for (const name of ["laoshi", "req"]) {
|
|
229
|
+
fs.writeFileSync(path.join(bin, name), `#!/bin/sh\nexec node "${entry}" "$@"\n`, { mode: 0o755 });
|
|
230
|
+
fs.writeFileSync(path.join(bin, `${name}.cmd`), `@echo off\r\nnode "${entry}" %*\r\n`);
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
const onPath = (process.env.PATH ?? "").split(path.delimiter).some((p) => p && path.resolve(p) === bin);
|
|
234
|
+
report("ok", `laoshi、req 命令在 ${bin}${onPath ? "" : `(不在 PATH 中:用 npm 全局安装时可以忽略;否则把它加进 PATH${process.platform === "win32" ? `,例如在 cmd 中执行 setx PATH "%PATH%;${bin}"` : ""})`}`);
|
|
235
|
+
if (path.resolve(process.env.LAOSHI_HOME ?? path.join(os.homedir(), ".laoshi")) !== home) {
|
|
236
|
+
report("warn", `安装根不是默认位置,需要设置环境变量 LAOSHI_HOME=${home}(之后新开的终端和平台都要能读到它)`);
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
if (!dry) {
|
|
240
|
+
fs.writeFileSync(recordPath, `${JSON.stringify({ version, root: kit, platform, targets: targets.map((t) => t.dir), installedAt: new Date().toISOString() }, null, 2)}\n`);
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
section("接下来");
|
|
244
|
+
for (const [i, line] of [...next, `体检:laoshi doctor --no-project`].entries()) console.log(`${i + 1}. ${line}`);
|
|
245
|
+
process.exit(problems > 0 ? 1 : 0);
|
package/bin/locate.mjs
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// Finds an installed dependency the way Node does: in <dir>/node_modules, then in each
|
|
2
|
+
// parent directory. A git checkout keeps dependencies in its own node_modules; an npm
|
|
3
|
+
// install puts them next to the package (versions/<v>/node_modules) or inside it (global).
|
|
4
|
+
import fs from "node:fs";
|
|
5
|
+
import path from "node:path";
|
|
6
|
+
|
|
7
|
+
export function findDependency(fromDir, name) {
|
|
8
|
+
let dir = path.resolve(fromDir);
|
|
9
|
+
for (;;) {
|
|
10
|
+
const candidate = path.join(dir, "node_modules", ...name.split("/"));
|
|
11
|
+
if (fs.existsSync(path.join(candidate, "package.json"))) return candidate;
|
|
12
|
+
const parent = path.dirname(dir);
|
|
13
|
+
if (parent === dir) return null;
|
|
14
|
+
dir = parent;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/** tsx's command-line entry, or null when tsx is not installed. */
|
|
19
|
+
export function findTsxCli(fromDir) {
|
|
20
|
+
const tsx = findDependency(fromDir, "tsx");
|
|
21
|
+
return tsx ? path.join(tsx, "dist", "cli.mjs") : null;
|
|
22
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
// Types for the parts of req-docs.mjs the tests use.
|
|
2
|
+
import type { Server } from "node:http";
|
|
3
|
+
export function siteDir(root?: string, env?: NodeJS.ProcessEnv | Record<string, string>): string | null;
|
|
4
|
+
export function resolveFile(dir: string, urlPath: string): string | null;
|
|
5
|
+
export function createServer(dir: string): Server;
|