agentplugged 0.0.0-stage → 1.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 +110 -0
- package/LICENSE-METHOD +21 -0
- package/README.md +250 -2
- package/dist/agent-commands.js +46532 -0
- package/dist/bin.js +13 -0
- package/dist/cli.js +44 -0
- package/dist/esm.js +920 -0
- package/dist/forge-follow.js +231 -0
- package/dist/helpers.js +18526 -0
- package/dist/helpers2.js +1 -0
- package/dist/launcher-env.js +13 -0
- package/dist/launcher.js +308 -0
- package/dist/libsodium-wrappers.js +4384 -0
- package/dist/libsodium-wrappers2.js +4384 -0
- package/dist/main.js +17732 -0
- package/dist/method/LICENSE +21 -0
- package/dist/method/agents/alex/SKILL.md +87 -0
- package/dist/method/agents/alex/agent.yaml +94 -0
- package/dist/method/agents/chloe/SKILL.md +97 -0
- package/dist/method/agents/chloe/agent.yaml +87 -0
- package/dist/method/agents/ethan/SKILL.md +55 -0
- package/dist/method/agents/ethan/agent.yaml +94 -0
- package/dist/method/agents/hugo/SKILL.md +52 -0
- package/dist/method/agents/hugo/agent.yaml +93 -0
- package/dist/method/agents/iris/SKILL.md +69 -0
- package/dist/method/agents/iris/agent.yaml +86 -0
- package/dist/method/agents/izzy/SKILL.md +137 -0
- package/dist/method/agents/izzy/agent.yaml +104 -0
- package/dist/method/agents/jade/SKILL.md +54 -0
- package/dist/method/agents/jade/agent.yaml +94 -0
- package/dist/method/agents/julien/SKILL.md +96 -0
- package/dist/method/agents/julien/agent.yaml +95 -0
- package/dist/method/agents/lina/SKILL.md +54 -0
- package/dist/method/agents/lina/agent.yaml +94 -0
- package/dist/method/agents/lou/SKILL.md +67 -0
- package/dist/method/agents/lou/agent.yaml +84 -0
- package/dist/method/agents/maya/SKILL.md +82 -0
- package/dist/method/agents/maya/agent.yaml +98 -0
- package/dist/method/agents/milo/SKILL.md +79 -0
- package/dist/method/agents/milo/agent.yaml +80 -0
- package/dist/method/agents/noah/SKILL.md +80 -0
- package/dist/method/agents/noah/agent.yaml +73 -0
- package/dist/method/agents/noah/references/conduct.md +98 -0
- package/dist/method/agents/noah/references/decisions.md +122 -0
- package/dist/method/agents/noah/references/environment.md +72 -0
- package/dist/method/agents/noah/references/facts.md +13 -0
- package/dist/method/agents/noah/references/journey.md +80 -0
- package/dist/method/agents/noah/references/team.md +195 -0
- package/dist/method/agents/omar/SKILL.md +92 -0
- package/dist/method/agents/omar/agent.yaml +86 -0
- package/dist/method/agents/quentin/SKILL.md +78 -0
- package/dist/method/agents/quentin/agent.yaml +82 -0
- package/dist/method/agents/sam/SKILL.md +54 -0
- package/dist/method/agents/sam/agent.yaml +94 -0
- package/dist/method/agents/stella/SKILL.md +80 -0
- package/dist/method/agents/stella/agent.yaml +89 -0
- package/dist/method/agents/tess/SKILL.md +64 -0
- package/dist/method/agents/tess/agent.yaml +94 -0
- package/dist/method/agents/zoe/SKILL.md +85 -0
- package/dist/method/agents/zoe/agent.yaml +91 -0
- package/dist/method/doctor.yaml +1029 -0
- package/dist/method/models.yaml +73 -0
- package/dist/method/skills/.gitkeep +0 -0
- package/dist/method/skills/acceptance-qa/SKILL.md +40 -0
- package/dist/method/skills/acceptance-qa/references/run.md +54 -0
- package/dist/method/skills/acceptance-qa/references/scenarios.md +32 -0
- package/dist/method/skills/acceptance-qa/references/verdicts.md +43 -0
- package/dist/method/skills/api-e2e-tests/SKILL.md +61 -0
- package/dist/method/skills/api-e2e-tests/references/ci.md +33 -0
- package/dist/method/skills/api-e2e-tests/references/frameworks.md +58 -0
- package/dist/method/skills/api-e2e-tests/references/generate.md +67 -0
- package/dist/method/skills/audit-pillars/SKILL.md +28 -0
- package/dist/method/skills/audit-pillars/references/accessibility.md +13 -0
- package/dist/method/skills/audit-pillars/references/architecture.md +13 -0
- package/dist/method/skills/audit-pillars/references/dependencies.md +13 -0
- package/dist/method/skills/audit-pillars/references/format.md +20 -0
- package/dist/method/skills/audit-pillars/references/interface.md +13 -0
- package/dist/method/skills/audit-pillars/references/method.md +33 -0
- package/dist/method/skills/audit-pillars/references/performance.md +17 -0
- package/dist/method/skills/audit-pillars/references/quality.md +11 -0
- package/dist/method/skills/audit-pillars/references/security.md +13 -0
- package/dist/method/skills/audit-pillars/references/tests.md +17 -0
- package/dist/method/skills/chain-stories/SKILL.md +30 -0
- package/dist/method/skills/chain-stories/references/attempts.md +19 -0
- package/dist/method/skills/chain-stories/references/stops.md +27 -0
- package/dist/method/skills/check-readiness/SKILL.md +34 -0
- package/dist/method/skills/check-readiness/references/judge.md +21 -0
- package/dist/method/skills/check-readiness/references/settle.md +17 -0
- package/dist/method/skills/check-requirements/SKILL.md +97 -0
- package/dist/method/skills/check-requirements/references/engine-proofs.md +43 -0
- package/dist/method/skills/check-requirements/references/proofs-and-gaps.md +45 -0
- package/dist/method/skills/correct-course/SKILL.md +15 -0
- package/dist/method/skills/correct-course/references/gestures.md +20 -0
- package/dist/method/skills/correct-course/references/starts.md +18 -0
- package/dist/method/skills/correct-course/references/steps.md +14 -0
- package/dist/method/skills/critique-deliverable/SKILL.md +25 -0
- package/dist/method/skills/critique-deliverable/references/assumption-audit.md +11 -0
- package/dist/method/skills/critique-deliverable/references/choose.md +27 -0
- package/dist/method/skills/critique-deliverable/references/compare-existing.md +13 -0
- package/dist/method/skills/critique-deliverable/references/devils-advocate.md +13 -0
- package/dist/method/skills/critique-deliverable/references/divergence.md +15 -0
- package/dist/method/skills/critique-deliverable/references/domain-expert.md +14 -0
- package/dist/method/skills/critique-deliverable/references/extreme-user.md +13 -0
- package/dist/method/skills/critique-deliverable/references/failure-modes.md +13 -0
- package/dist/method/skills/critique-deliverable/references/first-principles.md +12 -0
- package/dist/method/skills/critique-deliverable/references/format.md +25 -0
- package/dist/method/skills/critique-deliverable/references/gestures.md +24 -0
- package/dist/method/skills/critique-deliverable/references/inversion.md +13 -0
- package/dist/method/skills/critique-deliverable/references/judgment.md +14 -0
- package/dist/method/skills/critique-deliverable/references/pre-mortem.md +12 -0
- package/dist/method/skills/critique-deliverable/references/reconcile.md +15 -0
- package/dist/method/skills/critique-deliverable/references/red-team.md +12 -0
- package/dist/method/skills/critique-deliverable/references/reframe.md +12 -0
- package/dist/method/skills/critique-deliverable/references/second-order.md +12 -0
- package/dist/method/skills/critique-deliverable/references/socratic.md +15 -0
- package/dist/method/skills/critique-deliverable/references/steelman.md +13 -0
- package/dist/method/skills/critique-deliverable/references/subtraction.md +12 -0
- package/dist/method/skills/deep-research/SKILL.md +43 -0
- package/dist/method/skills/deep-research/assets/page-template.md +37 -0
- package/dist/method/skills/deep-research/references/candidates.md +29 -0
- package/dist/method/skills/deep-research/references/external.md +37 -0
- package/dist/method/skills/deep-research/references/page-format.md +51 -0
- package/dist/method/skills/deep-research/references/types.md +31 -0
- package/dist/method/skills/develop-story/SKILL.md +211 -0
- package/dist/method/skills/develop-story/evals/cases.yaml +45 -0
- package/dist/method/skills/develop-story/references/acceptance-tests.md +73 -0
- package/dist/method/skills/develop-story/references/self-check.md +46 -0
- package/dist/method/skills/diagnose-bug/SKILL.md +73 -0
- package/dist/method/skills/diagnose-bug/references/hypotheses.md +45 -0
- package/dist/method/skills/diagnose-bug/references/probes.md +40 -0
- package/dist/method/skills/generate-knowledge-base/SKILL.md +251 -0
- package/dist/method/skills/generate-knowledge-base/assets/guide-template.md +49 -0
- package/dist/method/skills/generate-knowledge-base/assets/index-template.md +58 -0
- package/dist/method/skills/generate-knowledge-base/assets/page-template.md +61 -0
- package/dist/method/skills/generate-knowledge-base/assets/release-notes-template.md +38 -0
- package/dist/method/skills/generate-knowledge-base/references/kb-checklist.md +49 -0
- package/dist/method/skills/generate-knowledge-base/references/living-docs.md +81 -0
- package/dist/method/skills/generate-knowledge-base/references/repository-scan.md +48 -0
- package/dist/method/skills/generate-knowledge-base/references/reuse-map.md +21 -0
- package/dist/method/skills/ideation/SKILL.md +44 -0
- package/dist/method/skills/ideation/assets/session-template.md +46 -0
- package/dist/method/skills/ideation/references/choose.md +21 -0
- package/dist/method/skills/ideation/references/close.md +17 -0
- package/dist/method/skills/ideation/references/converge.md +24 -0
- package/dist/method/skills/ideation/references/gestures.md +15 -0
- package/dist/method/skills/ideation/references/stances.md +21 -0
- package/dist/method/skills/ideation/references/techniques-borrowed.md +8 -0
- package/dist/method/skills/ideation/references/techniques-deep.md +12 -0
- package/dist/method/skills/ideation/references/techniques-frames.md +12 -0
- package/dist/method/skills/ideation/references/techniques-futures.md +8 -0
- package/dist/method/skills/ideation/references/techniques-limits.md +9 -0
- package/dist/method/skills/ideation/references/techniques-people.md +7 -0
- package/dist/method/skills/ideation/references/techniques-sparks.md +10 -0
- package/dist/method/skills/ideation/references/techniques-together.md +11 -0
- package/dist/method/skills/improve-code/SKILL.md +74 -0
- package/dist/method/skills/improve-code/references/axes.md +45 -0
- package/dist/method/skills/improve-session/SKILL.md +47 -0
- package/dist/method/skills/order-merges/SKILL.md +71 -0
- package/dist/method/skills/pitch/SKILL.md +40 -0
- package/dist/method/skills/pitch/assets/deck-template.md +31 -0
- package/dist/method/skills/pitch/assets/design-template.md +45 -0
- package/dist/method/skills/pitch/assets/narrative-template.md +40 -0
- package/dist/method/skills/pitch/references/deck-types.md +17 -0
- package/dist/method/skills/pitch/references/deck.md +24 -0
- package/dist/method/skills/pitch/references/design-implementation.md +25 -0
- package/dist/method/skills/pitch/references/design-methods.md +45 -0
- package/dist/method/skills/pitch/references/design-thinking.md +28 -0
- package/dist/method/skills/pitch/references/story-frameworks.md +39 -0
- package/dist/method/skills/pitch/references/story.md +22 -0
- package/dist/method/skills/plan-sprint/SKILL.md +162 -0
- package/dist/method/skills/quick-lane/SKILL.md +143 -0
- package/dist/method/skills/resolve-merge-conflict/SKILL.md +83 -0
- package/dist/method/skills/review-story/SKILL.md +96 -0
- package/dist/method/skills/review-story/evals/cases.yaml +59 -0
- package/dist/method/skills/review-story/references/amend-story.md +16 -0
- package/dist/method/skills/review-story/references/export.md +20 -0
- package/dist/method/skills/review-story/references/format.md +33 -0
- package/dist/method/skills/review-story/references/free-review.md +22 -0
- package/dist/method/skills/review-story/references/judge.md +44 -0
- package/dist/method/skills/review-story/references/lens-adversarial.md +15 -0
- package/dist/method/skills/review-story/references/lens-edge-cases.md +24 -0
- package/dist/method/skills/review-story/references/lens-prose.md +11 -0
- package/dist/method/skills/review-story/references/lens-relevance.md +13 -0
- package/dist/method/skills/review-story/references/lens-security.md +10 -0
- package/dist/method/skills/review-story/references/lens-structure.md +16 -0
- package/dist/method/skills/review-story/references/lens-verification-gaps.md +13 -0
- package/dist/method/skills/review-story/references/pass-assertions.md +17 -0
- package/dist/method/skills/review-story/references/pass-removals.md +13 -0
- package/dist/method/skills/review-tests/SKILL.md +32 -0
- package/dist/method/skills/review-tests/references/check.md +25 -0
- package/dist/method/skills/review-tests/references/grid.md +27 -0
- package/dist/method/skills/round-table/SKILL.md +31 -0
- package/dist/method/skills/round-table/evals/cases.yaml +27 -0
- package/dist/method/skills/round-table/references/cast.md +14 -0
- package/dist/method/skills/round-table/references/gestures.md +24 -0
- package/dist/method/skills/round-table/references/guests.md +17 -0
- package/dist/method/skills/round-table/references/independence.md +21 -0
- package/dist/method/skills/round-table/references/rooms.md +29 -0
- package/dist/method/skills/round-table/references/three-views.md +17 -0
- package/dist/method/skills/round-table/references/turns.md +19 -0
- package/dist/method/skills/run-retrospective/SKILL.md +201 -0
- package/dist/method/skills/security-review-architecture/SKILL.md +129 -0
- package/dist/method/skills/security-review-architecture/assets/architecture-review-template.md +47 -0
- package/dist/method/skills/security-review-architecture/references/spec-review.md +48 -0
- package/dist/method/skills/setup-ci/SKILL.md +121 -0
- package/dist/method/skills/setup-ci/assets/github-actions.yml +52 -0
- package/dist/method/skills/setup-ci/assets/gitlab-ci.yml +34 -0
- package/dist/method/skills/split-into-stories/SKILL.md +205 -0
- package/dist/method/skills/split-into-stories/assets/epic.md.tmpl +31 -0
- package/dist/method/skills/split-into-stories/assets/story.md.tmpl +36 -0
- package/dist/method/skills/strategy/SKILL.md +44 -0
- package/dist/method/skills/strategy/assets/innovation-template.md +60 -0
- package/dist/method/skills/strategy/assets/problem-template.md +54 -0
- package/dist/method/skills/strategy/references/costs.md +28 -0
- package/dist/method/skills/strategy/references/gestures.md +24 -0
- package/dist/method/skills/strategy/references/innovate-frameworks.md +48 -0
- package/dist/method/skills/strategy/references/innovate.md +40 -0
- package/dist/method/skills/strategy/references/solve-methods.md +45 -0
- package/dist/method/skills/strategy/references/solve.md +35 -0
- package/dist/method/skills/test-idea/SKILL.md +29 -0
- package/dist/method/skills/test-idea/assets/forge-template.md +27 -0
- package/dist/method/skills/test-idea/assets/prfaq-template.md +33 -0
- package/dist/method/skills/test-idea/references/bets.md +14 -0
- package/dist/method/skills/test-idea/references/concept.md +24 -0
- package/dist/method/skills/test-idea/references/faq.md +34 -0
- package/dist/method/skills/test-idea/references/forge.md +36 -0
- package/dist/method/skills/test-idea/references/personas.md +23 -0
- package/dist/method/skills/test-idea/references/prfaq.md +33 -0
- package/dist/method/skills/test-idea/references/verdict.md +26 -0
- package/dist/method/skills/workshop/SKILL.md +40 -0
- package/dist/method/skills/workshop/references/analyze.md +36 -0
- package/dist/method/skills/workshop/references/create.md +45 -0
- package/dist/method/skills/workshop/references/customize.md +45 -0
- package/dist/method/skills/workshop/references/evaluate.md +44 -0
- package/dist/method/skills/workshop/references/rules.md +35 -0
- package/dist/method/skills/write-architecture/SKILL.md +233 -0
- package/dist/method/skills/write-architecture/assets/architecture-template.md +110 -0
- package/dist/method/skills/write-architecture/references/guard.md +40 -0
- package/dist/method/skills/write-architecture/references/self-check.md +47 -0
- package/dist/method/skills/write-brand/SKILL.md +36 -0
- package/dist/method/skills/write-brand/assets/brand-template.md +59 -0
- package/dist/method/skills/write-brand/assets/identity-page.html +141 -0
- package/dist/method/skills/write-brand/assets/identity-template.md +132 -0
- package/dist/method/skills/write-brand/references/identity.md +38 -0
- package/dist/method/skills/write-brand/references/platform.md +29 -0
- package/dist/method/skills/write-brand/references/rules.md +43 -0
- package/dist/method/skills/write-brief/SKILL.md +171 -0
- package/dist/method/skills/write-brief/assets/brief-template.md +87 -0
- package/dist/method/skills/write-brief/assets/research-note-template.md +43 -0
- package/dist/method/skills/write-brief/references/brief-checklist.md +37 -0
- package/dist/method/skills/write-content/SKILL.md +233 -0
- package/dist/method/skills/write-content/assets/campaign-template.md +94 -0
- package/dist/method/skills/write-content/assets/content-template.md +76 -0
- package/dist/method/skills/write-content/references/content-checklist.md +67 -0
- package/dist/method/skills/write-positioning/SKILL.md +218 -0
- package/dist/method/skills/write-positioning/assets/page-template.md +85 -0
- package/dist/method/skills/write-positioning/assets/positioning-template.md +79 -0
- package/dist/method/skills/write-positioning/references/positioning-checklist.md +44 -0
- package/dist/method/skills/write-positioning/references/seo-checklist.md +62 -0
- package/dist/method/skills/write-prd/SKILL.md +204 -0
- package/dist/method/skills/write-prd/assets/prd-template.md +121 -0
- package/dist/method/skills/write-prd/evals/cases.yaml +46 -0
- package/dist/method/skills/write-prd/references/prd-checklist.md +68 -0
- package/dist/method/skills/write-sales/SKILL.md +236 -0
- package/dist/method/skills/write-sales/assets/offer-template.md +93 -0
- package/dist/method/skills/write-sales/assets/sequence-template.md +110 -0
- package/dist/method/skills/write-sales/references/before-you-send.md +54 -0
- package/dist/method/skills/write-sales/references/sales-checklist.md +71 -0
- package/dist/method/skills/write-spec/SKILL.md +25 -0
- package/dist/method/skills/write-spec/assets/spec-template.md +59 -0
- package/dist/method/skills/write-spec/references/spec-guide.md +47 -0
- package/dist/method/skills/write-ux-spec/SKILL.md +191 -0
- package/dist/method/skills/write-ux-spec/assets/mockup-page.html +36 -0
- package/dist/method/skills/write-ux-spec/assets/ux-template.md +206 -0
- package/dist/method/skills/write-ux-spec/references/accessibility-check.md +74 -0
- package/dist/method/skills/write-ux-spec/references/mockups.md +71 -0
- package/dist/method/skills/write-ux-spec/references/tokens-and-sketches.md +83 -0
- package/dist/method/skills/write-ux-spec/references/ux-checklist.md +74 -0
- package/dist/product-root.js +21527 -0
- package/dist/rolldown-runtime.js +38 -0
- package/dist/webauthn-verify.js +1 -0
- package/dist/webauthn-verify2.js +107 -0
- package/dist/webauthn.js +9798 -0
- package/package.json +68 -3
package/dist/helpers2.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { A as cose, g as decodeAttestationObject, f as decodeCredentialPublicKey, c as parseAuthenticatorData } from "./helpers.js";
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
//#region src/launcher-env.ts
|
|
2
|
+
/**
|
|
3
|
+
* What the launcher of the MCP server tells the engine it runs, by environment
|
|
4
|
+
* variables: kept apart from the launcher so that the engine reads them without loading it.
|
|
5
|
+
*/
|
|
6
|
+
/** Marks the process the launcher runs: the engine itself (the server), not a launcher again. */
|
|
7
|
+
const ENGINE_CHILD_ENV = "AGENTPLUGGED_ENGINE_CHILD";
|
|
8
|
+
/** The name the server gives its session, kept across children (`server:<id>`). */
|
|
9
|
+
const SESSION_INSTANCE_ENV = "AGENTPLUGGED_SESSION_INSTANCE";
|
|
10
|
+
/** The secret that seals the state of a form, kept across children (64 hexadecimal characters). */
|
|
11
|
+
const SESSION_KEY_ENV = "AGENTPLUGGED_SESSION_KEY";
|
|
12
|
+
//#endregion
|
|
13
|
+
export { SESSION_INSTANCE_ENV as n, SESSION_KEY_ENV as r, ENGINE_CHILD_ENV as t };
|
package/dist/launcher.js
ADDED
|
@@ -0,0 +1,308 @@
|
|
|
1
|
+
import { n as SESSION_INSTANCE_ENV, r as SESSION_KEY_ENV, t as ENGINE_CHILD_ENV } from "./launcher-env.js";
|
|
2
|
+
import { et as installedEntry, n as productRootOf, nt as isReleaseVersion, t as PRODUCT_CONFIG_PATH } from "./product-root.js";
|
|
3
|
+
import { i as randomBytes } from "./webauthn.js";
|
|
4
|
+
import "./agent-commands.js";
|
|
5
|
+
import { readFileSync } from "node:fs";
|
|
6
|
+
import { spawn } from "node:child_process";
|
|
7
|
+
import { join } from "node:path";
|
|
8
|
+
import { StringDecoder } from "node:string_decoder";
|
|
9
|
+
//#region src/launcher.ts
|
|
10
|
+
/**
|
|
11
|
+
* The MCP server of the AI tool as a stable launcher. `agentplugged mcp` no longer is
|
|
12
|
+
* the engine: it is a small relay that runs the engine of one version in a child process (the same
|
|
13
|
+
* program, told by `AGENTPLUGGED_ENGINE_CHILD`) and passes the protocol's lines both ways. Between two
|
|
14
|
+
* calls, when the product pins a newer version of the engine than the one running and that version
|
|
15
|
+
* is installed in its own folder (`~/.agentplugged/engines/<version>/`), it starts that version's
|
|
16
|
+
* child, replays it the handshake the AI tool made, hands it the next call, and lets the old child
|
|
17
|
+
* end. The connection with the AI tool never closes, no call in flight is ever cut (the move waits
|
|
18
|
+
* for none to be), and nothing is replaced in place: a running engine locks its native keychain
|
|
19
|
+
* module on Windows, so every version lives in a folder of its own.
|
|
20
|
+
*
|
|
21
|
+
* What the launcher is not: it does not read the protocol beyond what it needs (the ids of the calls
|
|
22
|
+
* in flight, the handshake), it never installs anything, and it asks no one anything.
|
|
23
|
+
*/
|
|
24
|
+
/** How long a new child has to answer the replayed handshake. */
|
|
25
|
+
const HANDSHAKE_TIMEOUT_MS = 2e4;
|
|
26
|
+
/** How long an old child has to end by itself once its input is closed. */
|
|
27
|
+
const RETIRE_TIMEOUT_MS = 1e4;
|
|
28
|
+
/** The id of the probe sent to a new child when the AI tool made no handshake (revision 2026-07-28). */
|
|
29
|
+
const PROBE_ID = "agentplugged-launcher-probe";
|
|
30
|
+
/**
|
|
31
|
+
* Release versions compared as numbers: negative when `a` < `b`. The core's `compareSemver` does
|
|
32
|
+
* the same; it is written again here so that the launcher does not load the core.
|
|
33
|
+
*/
|
|
34
|
+
function compareRelease(a, b) {
|
|
35
|
+
const x = a.split(".").map(Number);
|
|
36
|
+
const y = b.split(".").map(Number);
|
|
37
|
+
for (let i = 0; i < 3; i++) {
|
|
38
|
+
const diff = (x[i] ?? 0) - (y[i] ?? 0);
|
|
39
|
+
if (diff !== 0) return Math.sign(diff);
|
|
40
|
+
}
|
|
41
|
+
return 0;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* The engine version the product pins (`engine_version` of `method.yaml`), or undefined. A line of
|
|
45
|
+
* the file read as is, never parsed: the launcher loads neither the core nor a YAML reader.
|
|
46
|
+
*/
|
|
47
|
+
function pinnedEngineOf(root) {
|
|
48
|
+
try {
|
|
49
|
+
const text = readFileSync(join(root, PRODUCT_CONFIG_PATH), "utf8");
|
|
50
|
+
return /^engine_version:[ \t]*["']?([0-9]+\.[0-9]+\.[0-9]+)["']?[ \t]*(?:#.*)?$/m.exec(text)?.[1];
|
|
51
|
+
} catch {
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* The engine the session should run now: the version the product pins when it is newer than the one
|
|
57
|
+
* running (at the start: the package that runs the launcher) and installed in its own folder, and not
|
|
58
|
+
* one that already failed to start in this session; else the one running.
|
|
59
|
+
*/
|
|
60
|
+
function chooseEngine(options) {
|
|
61
|
+
const own = {
|
|
62
|
+
version: options.running,
|
|
63
|
+
entry: options.runningEntry
|
|
64
|
+
};
|
|
65
|
+
const pinned = pinnedEngineOf(productRootOf(options.cwd));
|
|
66
|
+
if (pinned === void 0 || !isReleaseVersion(options.running) || compareRelease(pinned, options.running) <= 0 || options.failed?.has(pinned) === true) return own;
|
|
67
|
+
const entry = installedEntry(pinned, options.home);
|
|
68
|
+
return entry === void 0 ? own : {
|
|
69
|
+
version: pinned,
|
|
70
|
+
entry
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
function parse(line) {
|
|
74
|
+
try {
|
|
75
|
+
const value = JSON.parse(line);
|
|
76
|
+
return typeof value === "object" && value !== null && !Array.isArray(value) ? value : void 0;
|
|
77
|
+
} catch {
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
/** An id as a key: `1` and `"1"` are two ids. */
|
|
82
|
+
function idKey(id) {
|
|
83
|
+
return typeof id === "string" || typeof id === "number" ? `${typeof id}:${id}` : void 0;
|
|
84
|
+
}
|
|
85
|
+
/** Splits a stream of text into its lines. */
|
|
86
|
+
var Lines = class {
|
|
87
|
+
#decoder = new StringDecoder("utf8");
|
|
88
|
+
#rest = "";
|
|
89
|
+
push(chunk) {
|
|
90
|
+
this.#rest += typeof chunk === "string" ? chunk : this.#decoder.write(chunk);
|
|
91
|
+
const lines = this.#rest.split("\n");
|
|
92
|
+
this.#rest = lines.pop() ?? "";
|
|
93
|
+
return lines.map((line) => line.replace(/\r$/, "")).filter((line) => line !== "");
|
|
94
|
+
}
|
|
95
|
+
end() {
|
|
96
|
+
const last = (this.#rest + this.#decoder.end()).replace(/\r$/, "");
|
|
97
|
+
this.#rest = "";
|
|
98
|
+
return last === "" ? [] : [last];
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
/**
|
|
102
|
+
* Runs the launcher until the AI tool closes the connection (or the engine ends). Returns the exit
|
|
103
|
+
* code: the engine's.
|
|
104
|
+
*/
|
|
105
|
+
async function runLauncher(options) {
|
|
106
|
+
const instance = `server:${Buffer.from(randomBytes(16)).toString("hex")}`;
|
|
107
|
+
const key = Buffer.from(randomBytes(32)).toString("hex");
|
|
108
|
+
const childEnv = {
|
|
109
|
+
...options.env,
|
|
110
|
+
[ENGINE_CHILD_ENV]: "1",
|
|
111
|
+
[SESSION_INSTANCE_ENV]: instance,
|
|
112
|
+
[SESSION_KEY_ENV]: key
|
|
113
|
+
};
|
|
114
|
+
const start = options.spawnEngine ?? ((entry, args, env) => spawn(process.execPath, [
|
|
115
|
+
entry,
|
|
116
|
+
"mcp",
|
|
117
|
+
...args
|
|
118
|
+
], {
|
|
119
|
+
cwd: options.cwd,
|
|
120
|
+
env,
|
|
121
|
+
stdio: [
|
|
122
|
+
"pipe",
|
|
123
|
+
"pipe",
|
|
124
|
+
"inherit"
|
|
125
|
+
],
|
|
126
|
+
windowsHide: true
|
|
127
|
+
}));
|
|
128
|
+
const failed = /* @__PURE__ */ new Set();
|
|
129
|
+
const engines = /* @__PURE__ */ new Set();
|
|
130
|
+
/** The calls the AI tool made that no answer closed, and those the engine made to the AI tool. */
|
|
131
|
+
const fromClient = /* @__PURE__ */ new Set();
|
|
132
|
+
const fromEngine = /* @__PURE__ */ new Set();
|
|
133
|
+
/** The handshake the AI tool made, to replay to the next engine. */
|
|
134
|
+
let initialize;
|
|
135
|
+
let initialized;
|
|
136
|
+
let finished = false;
|
|
137
|
+
let current;
|
|
138
|
+
let resolveDone = () => void 0;
|
|
139
|
+
const done = new Promise((resolve) => {
|
|
140
|
+
resolveDone = resolve;
|
|
141
|
+
});
|
|
142
|
+
const finish = (code) => {
|
|
143
|
+
if (finished) return;
|
|
144
|
+
finished = true;
|
|
145
|
+
for (const engine of engines) if (!engine.exited && engine.mode !== "retired") engine.child.kill();
|
|
146
|
+
resolveDone(code);
|
|
147
|
+
};
|
|
148
|
+
/** A call or a question the other side gave up (`notifications/cancelled`) is never answered. */
|
|
149
|
+
const forget = (pending, message) => {
|
|
150
|
+
if (message.method !== "notifications/cancelled") return;
|
|
151
|
+
const id = idKey(message.params?.requestId);
|
|
152
|
+
if (id !== void 0) pending.delete(id);
|
|
153
|
+
};
|
|
154
|
+
const startEngine = (choice, mode) => {
|
|
155
|
+
const child = start(choice.entry, options.args, childEnv);
|
|
156
|
+
const engine = {
|
|
157
|
+
choice,
|
|
158
|
+
child,
|
|
159
|
+
mode,
|
|
160
|
+
exited: false
|
|
161
|
+
};
|
|
162
|
+
engines.add(engine);
|
|
163
|
+
const lines = new Lines();
|
|
164
|
+
const onLine = (line) => {
|
|
165
|
+
const message = parse(line);
|
|
166
|
+
if (engine.mode === "trial") {
|
|
167
|
+
if (message !== void 0) engine.onTrialMessage?.(message);
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
if (engine.mode === "retired") return;
|
|
171
|
+
if (message !== void 0) {
|
|
172
|
+
const id = idKey(message.id);
|
|
173
|
+
if (id !== void 0) {
|
|
174
|
+
if (message.method === void 0) fromClient.delete(id);
|
|
175
|
+
else fromEngine.add(id);
|
|
176
|
+
}
|
|
177
|
+
forget(fromEngine, message);
|
|
178
|
+
}
|
|
179
|
+
options.stdout.write(`${line}\n`);
|
|
180
|
+
};
|
|
181
|
+
child.stdout?.on("data", (chunk) => {
|
|
182
|
+
for (const line of lines.push(chunk)) onLine(line);
|
|
183
|
+
});
|
|
184
|
+
child.stdout?.on("end", () => {
|
|
185
|
+
for (const line of lines.end()) onLine(line);
|
|
186
|
+
});
|
|
187
|
+
child.stdin?.on("error", () => void 0);
|
|
188
|
+
child.on("error", (error) => {
|
|
189
|
+
engine.exited = true;
|
|
190
|
+
if (engine.mode === "live") {
|
|
191
|
+
options.stderr(`agentplugged mcp: ${error.message}\n`);
|
|
192
|
+
finish(1);
|
|
193
|
+
} else engine.onTrialEnd?.();
|
|
194
|
+
});
|
|
195
|
+
child.on("close", (code) => {
|
|
196
|
+
engine.exited = true;
|
|
197
|
+
if (engine.mode === "live") finish(code ?? 1);
|
|
198
|
+
else if (engine.mode === "trial") engine.onTrialEnd?.();
|
|
199
|
+
});
|
|
200
|
+
return engine;
|
|
201
|
+
};
|
|
202
|
+
/** Starts the engine of `choice` and tells whether it answers the handshake the session made. */
|
|
203
|
+
const tryEngine = async (choice) => {
|
|
204
|
+
const engine = startEngine(choice, "trial");
|
|
205
|
+
const ok = await new Promise((resolve) => {
|
|
206
|
+
const timer = setTimeout(() => resolve(false), options.handshakeTimeoutMs ?? HANDSHAKE_TIMEOUT_MS);
|
|
207
|
+
const wanted = idKey(initialize === void 0 ? PROBE_ID : parse(initialize)?.id);
|
|
208
|
+
engine.onTrialEnd = () => {
|
|
209
|
+
clearTimeout(timer);
|
|
210
|
+
resolve(false);
|
|
211
|
+
};
|
|
212
|
+
engine.onTrialMessage = (message) => {
|
|
213
|
+
if (message.method === void 0 && idKey(message.id) === wanted) {
|
|
214
|
+
clearTimeout(timer);
|
|
215
|
+
resolve(initialize === void 0 || message.error === void 0);
|
|
216
|
+
}
|
|
217
|
+
};
|
|
218
|
+
engine.child.stdin?.write(`${initialize ?? JSON.stringify({
|
|
219
|
+
jsonrpc: "2.0",
|
|
220
|
+
id: PROBE_ID,
|
|
221
|
+
method: "ping"
|
|
222
|
+
})}\n`);
|
|
223
|
+
});
|
|
224
|
+
delete engine.onTrialMessage;
|
|
225
|
+
delete engine.onTrialEnd;
|
|
226
|
+
if (!ok) {
|
|
227
|
+
engine.mode = "retired";
|
|
228
|
+
engine.child.kill();
|
|
229
|
+
return;
|
|
230
|
+
}
|
|
231
|
+
if (initialized !== void 0) engine.child.stdin?.write(`${initialized}\n`);
|
|
232
|
+
return engine;
|
|
233
|
+
};
|
|
234
|
+
/** Moves the session to `choice`: false (the old engine stays) when it does not start. */
|
|
235
|
+
const moveTo = async (choice) => {
|
|
236
|
+
const next = await tryEngine(choice);
|
|
237
|
+
if (next === void 0) {
|
|
238
|
+
failed.add(choice.version);
|
|
239
|
+
options.stderr(`agentplugged mcp: engine ${choice.version} did not answer; staying on ${current.choice.version}\n`);
|
|
240
|
+
return false;
|
|
241
|
+
}
|
|
242
|
+
const old = current;
|
|
243
|
+
next.mode = "live";
|
|
244
|
+
current = next;
|
|
245
|
+
old.mode = "retired";
|
|
246
|
+
old.child.stdin?.end();
|
|
247
|
+
setTimeout(() => {
|
|
248
|
+
if (!old.exited) old.child.kill();
|
|
249
|
+
}, options.retireTimeoutMs ?? RETIRE_TIMEOUT_MS).unref();
|
|
250
|
+
options.stderr(`agentplugged mcp: engine ${old.choice.version} replaced by ${next.choice.version}\n`);
|
|
251
|
+
return true;
|
|
252
|
+
};
|
|
253
|
+
current = startEngine(chooseEngine({
|
|
254
|
+
cwd: options.cwd,
|
|
255
|
+
running: options.version,
|
|
256
|
+
runningEntry: options.selfEntry,
|
|
257
|
+
...options.home === void 0 ? {} : { home: options.home }
|
|
258
|
+
}), "live");
|
|
259
|
+
/** The lines of the AI tool, one after the other: a move holds the ones behind it. */
|
|
260
|
+
let chain = Promise.resolve();
|
|
261
|
+
const handle = async (line) => {
|
|
262
|
+
if (finished) return;
|
|
263
|
+
const message = parse(line);
|
|
264
|
+
const id = message === void 0 ? void 0 : idKey(message.id);
|
|
265
|
+
const idle = fromClient.size === 0 && fromEngine.size === 0;
|
|
266
|
+
if (message?.method === "tools/call" && id !== void 0 && idle) {
|
|
267
|
+
const wanted = chooseEngine({
|
|
268
|
+
cwd: options.cwd,
|
|
269
|
+
running: current.choice.version,
|
|
270
|
+
runningEntry: current.choice.entry,
|
|
271
|
+
failed,
|
|
272
|
+
...options.home === void 0 ? {} : { home: options.home }
|
|
273
|
+
});
|
|
274
|
+
if (wanted.version !== current.choice.version) await moveTo(wanted);
|
|
275
|
+
}
|
|
276
|
+
if (message !== void 0) {
|
|
277
|
+
if (message.method === "initialize" && id !== void 0) initialize = line;
|
|
278
|
+
else if (message.method === "notifications/initialized") initialized = line;
|
|
279
|
+
if (id !== void 0) {
|
|
280
|
+
if (message.method === void 0) fromEngine.delete(id);
|
|
281
|
+
else fromClient.add(id);
|
|
282
|
+
}
|
|
283
|
+
forget(fromClient, message);
|
|
284
|
+
}
|
|
285
|
+
current.child.stdin?.write(`${line}\n`);
|
|
286
|
+
};
|
|
287
|
+
const clientLines = new Lines();
|
|
288
|
+
const enqueue = (lines) => {
|
|
289
|
+
for (const line of lines) chain = chain.then(() => handle(line)).catch(() => void 0);
|
|
290
|
+
};
|
|
291
|
+
/** The AI tool closed the connection: the engine's input ends after the lines already received. */
|
|
292
|
+
const closeInput = () => {
|
|
293
|
+
enqueue(clientLines.end());
|
|
294
|
+
chain = chain.then(() => {
|
|
295
|
+
current.child.stdin?.end();
|
|
296
|
+
});
|
|
297
|
+
};
|
|
298
|
+
options.stdin.on("data", (chunk) => enqueue(clientLines.push(chunk)));
|
|
299
|
+
options.stdin.on("end", closeInput);
|
|
300
|
+
options.stdin.on("error", closeInput);
|
|
301
|
+
options.stdout.on("error", () => void 0);
|
|
302
|
+
const code = await done;
|
|
303
|
+
options.stdin.removeAllListeners("data");
|
|
304
|
+
options.stdin.pause();
|
|
305
|
+
return code;
|
|
306
|
+
}
|
|
307
|
+
//#endregion
|
|
308
|
+
export { runLauncher };
|