@hcu-lab.me/mcp-device 1.0.9 → 1.0.12
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/PRIVACY.md +21 -0
- package/README.md +58 -3
- package/SECURITY.md +67 -0
- package/config/revoked-approvals.json +1 -0
- package/control-plane/config/mcp-servers.example.toml +52 -0
- package/control-plane/config/mcp-servers.toml +52 -0
- package/control-plane/contracts/device-public-contract-v1.json +733 -0
- package/control-plane/scripts/GATEWAY-LICENSE.txt +7 -0
- package/control-plane/scripts/account-http.mjs +220 -0
- package/control-plane/scripts/account-store.mjs +368 -0
- package/control-plane/scripts/admin.mjs +68 -0
- package/control-plane/scripts/auth-session.mjs +411 -0
- package/control-plane/scripts/authenticated-mcp-wrapper.mjs +1281 -0
- package/control-plane/scripts/benchmark-command.mjs +9 -0
- package/control-plane/scripts/benchmark-mcp-catalog.mjs +174 -0
- package/control-plane/scripts/catalog-budget.mjs +87 -0
- package/control-plane/scripts/check-device-public-contract.mjs +20 -0
- package/control-plane/scripts/custom-tools/index.mjs +221 -0
- package/control-plane/scripts/custom-tools/path-utils.mjs +117 -0
- package/control-plane/scripts/custom-tools/response-utils.mjs +34 -0
- package/control-plane/scripts/dashboard-http.mjs +598 -0
- package/control-plane/scripts/device-access-policy.mjs +205 -0
- package/control-plane/scripts/device-admin.mjs +43 -0
- package/control-plane/scripts/device-audit.mjs +63 -0
- package/control-plane/scripts/device-broker.mjs +1461 -0
- package/control-plane/scripts/device-execution-tool-definitions.mjs +217 -0
- package/control-plane/scripts/device-inventory.mjs +128 -0
- package/control-plane/scripts/device-pairing-http.mjs +109 -0
- package/control-plane/scripts/device-pairing-store.mjs +245 -0
- package/control-plane/scripts/device-public-contract.mjs +165 -0
- package/control-plane/scripts/device-release.mjs +95 -0
- package/control-plane/scripts/device-secure-transport.mjs +128 -0
- package/control-plane/scripts/device-store.mjs +283 -0
- package/control-plane/scripts/device-usage.mjs +657 -0
- package/control-plane/scripts/embedded-device.mjs +149 -0
- package/control-plane/scripts/enduser-ui.mjs +45 -0
- package/control-plane/scripts/external-tool-broker.mjs +179 -0
- package/control-plane/scripts/oauth-authorization-server.mjs +589 -0
- package/control-plane/scripts/operator-dashboard-http.mjs +81 -0
- package/control-plane/scripts/project-inspection.mjs +227 -0
- package/control-plane/scripts/projects/project-id.mjs +69 -0
- package/control-plane/scripts/projects/trusted-roots-projects.mjs +375 -0
- package/control-plane/scripts/prompts/index.mjs +60 -0
- package/control-plane/scripts/remote-process-sessions.mjs +78 -0
- package/control-plane/scripts/remote-tool-result.mjs +9 -0
- package/control-plane/scripts/resources/index.mjs +166 -0
- package/control-plane/scripts/runtime-profile.mjs +54 -0
- package/control-plane/scripts/shell-tool-descriptor.mjs +17 -0
- package/control-plane/scripts/skill-source-safety.mjs +46 -0
- package/control-plane/scripts/skills/README.md +70 -0
- package/control-plane/scripts/skills/_upstream_licenses/anthropic-THIRD_PARTY_NOTICES.md +405 -0
- package/control-plane/scripts/skills/_upstream_licenses/hallmark-LICENSE.txt +21 -0
- package/control-plane/scripts/skills/_upstream_licenses/ponytail-LICENSE.txt +21 -0
- package/control-plane/scripts/skills/_upstream_licenses/stitch-skills-LICENSE.txt +201 -0
- package/control-plane/scripts/skills/_upstream_licenses/superpowers-LICENSE.txt +21 -0
- package/control-plane/scripts/skills/algorithmic-art/LICENSE.txt +202 -0
- package/control-plane/scripts/skills/algorithmic-art/SKILL.md +405 -0
- package/control-plane/scripts/skills/algorithmic-art/templates/generator_template.js +223 -0
- package/control-plane/scripts/skills/algorithmic-art/templates/viewer.html +599 -0
- package/control-plane/scripts/skills/brainstorming/SKILL.md +285 -0
- package/control-plane/scripts/skills/brainstorming/scripts/frame-template.html +213 -0
- package/control-plane/scripts/skills/brainstorming/scripts/helper.js +167 -0
- package/control-plane/scripts/skills/brainstorming/scripts/server.cjs +723 -0
- package/control-plane/scripts/skills/brainstorming/scripts/start-server.sh +209 -0
- package/control-plane/scripts/skills/brainstorming/scripts/stop-server.sh +120 -0
- package/control-plane/scripts/skills/brainstorming/spec-document-reviewer-prompt.md +49 -0
- package/control-plane/scripts/skills/brainstorming/visual-companion.md +299 -0
- package/control-plane/scripts/skills/brand-guidelines/LICENSE.txt +202 -0
- package/control-plane/scripts/skills/brand-guidelines/SKILL.md +73 -0
- package/control-plane/scripts/skills/claude-api/LICENSE.txt +202 -0
- package/control-plane/scripts/skills/claude-api/SKILL.md +570 -0
- package/control-plane/scripts/skills/claude-api/csharp/claude-api/README.md +362 -0
- package/control-plane/scripts/skills/claude-api/csharp/claude-api/batches.md +14 -0
- package/control-plane/scripts/skills/claude-api/csharp/claude-api/files-api.md +25 -0
- package/control-plane/scripts/skills/claude-api/csharp/claude-api/streaming.md +28 -0
- package/control-plane/scripts/skills/claude-api/csharp/claude-api/tool-use.md +164 -0
- package/control-plane/scripts/skills/claude-api/curl/examples.md +256 -0
- package/control-plane/scripts/skills/claude-api/curl/managed-agents.md +371 -0
- package/control-plane/scripts/skills/claude-api/go/claude-api/README.md +188 -0
- package/control-plane/scripts/skills/claude-api/go/claude-api/files-api.md +23 -0
- package/control-plane/scripts/skills/claude-api/go/claude-api/streaming.md +43 -0
- package/control-plane/scripts/skills/claude-api/go/claude-api/tool-use.md +220 -0
- package/control-plane/scripts/skills/claude-api/go/managed-agents/README.md +564 -0
- package/control-plane/scripts/skills/claude-api/java/claude-api/README.md +238 -0
- package/control-plane/scripts/skills/claude-api/java/claude-api/files-api.md +27 -0
- package/control-plane/scripts/skills/claude-api/java/claude-api/streaming.md +24 -0
- package/control-plane/scripts/skills/claude-api/java/claude-api/tool-use.md +228 -0
- package/control-plane/scripts/skills/claude-api/java/managed-agents/README.md +443 -0
- package/control-plane/scripts/skills/claude-api/php/claude-api/README.md +174 -0
- package/control-plane/scripts/skills/claude-api/php/claude-api/batches.md +15 -0
- package/control-plane/scripts/skills/claude-api/php/claude-api/files-api.md +13 -0
- package/control-plane/scripts/skills/claude-api/php/claude-api/streaming.md +27 -0
- package/control-plane/scripts/skills/claude-api/php/claude-api/tool-use.md +253 -0
- package/control-plane/scripts/skills/claude-api/php/managed-agents/README.md +443 -0
- package/control-plane/scripts/skills/claude-api/python/claude-api/README.md +565 -0
- package/control-plane/scripts/skills/claude-api/python/claude-api/batches.md +198 -0
- package/control-plane/scripts/skills/claude-api/python/claude-api/files-api.md +170 -0
- package/control-plane/scripts/skills/claude-api/python/claude-api/sdk-upgrade.md +286 -0
- package/control-plane/scripts/skills/claude-api/python/claude-api/streaming.md +179 -0
- package/control-plane/scripts/skills/claude-api/python/claude-api/tool-use.md +627 -0
- package/control-plane/scripts/skills/claude-api/python/managed-agents/README.md +335 -0
- package/control-plane/scripts/skills/claude-api/ruby/claude-api/README.md +134 -0
- package/control-plane/scripts/skills/claude-api/ruby/claude-api/streaming.md +16 -0
- package/control-plane/scripts/skills/claude-api/ruby/claude-api/tool-use.md +41 -0
- package/control-plane/scripts/skills/claude-api/ruby/managed-agents/README.md +394 -0
- package/control-plane/scripts/skills/claude-api/shared/admin-api.md +179 -0
- package/control-plane/scripts/skills/claude-api/shared/agent-design.md +101 -0
- package/control-plane/scripts/skills/claude-api/shared/anthropic-cli.md +269 -0
- package/control-plane/scripts/skills/claude-api/shared/claude-platform-on-aws.md +59 -0
- package/control-plane/scripts/skills/claude-api/shared/cost-optimization.md +233 -0
- package/control-plane/scripts/skills/claude-api/shared/error-codes.md +262 -0
- package/control-plane/scripts/skills/claude-api/shared/live-sources.md +166 -0
- package/control-plane/scripts/skills/claude-api/shared/managed-agents-api-reference.md +455 -0
- package/control-plane/scripts/skills/claude-api/shared/managed-agents-client-patterns.md +220 -0
- package/control-plane/scripts/skills/claude-api/shared/managed-agents-core.md +359 -0
- package/control-plane/scripts/skills/claude-api/shared/managed-agents-environments.md +226 -0
- package/control-plane/scripts/skills/claude-api/shared/managed-agents-events.md +290 -0
- package/control-plane/scripts/skills/claude-api/shared/managed-agents-memory.md +201 -0
- package/control-plane/scripts/skills/claude-api/shared/managed-agents-multiagent.md +260 -0
- package/control-plane/scripts/skills/claude-api/shared/managed-agents-onboarding.md +82 -0
- package/control-plane/scripts/skills/claude-api/shared/managed-agents-outcomes.md +108 -0
- package/control-plane/scripts/skills/claude-api/shared/managed-agents-overview.md +77 -0
- package/control-plane/scripts/skills/claude-api/shared/managed-agents-scheduled-deployments.md +156 -0
- package/control-plane/scripts/skills/claude-api/shared/managed-agents-self-hosted-sandboxes.md +282 -0
- package/control-plane/scripts/skills/claude-api/shared/managed-agents-tools.md +504 -0
- package/control-plane/scripts/skills/claude-api/shared/managed-agents-webhooks.md +143 -0
- package/control-plane/scripts/skills/claude-api/shared/model-migration.md +1872 -0
- package/control-plane/scripts/skills/claude-api/shared/models.md +142 -0
- package/control-plane/scripts/skills/claude-api/shared/platform-availability.md +52 -0
- package/control-plane/scripts/skills/claude-api/shared/prompt-audit.md +223 -0
- package/control-plane/scripts/skills/claude-api/shared/prompt-caching.md +292 -0
- package/control-plane/scripts/skills/claude-api/shared/token-counting.md +56 -0
- package/control-plane/scripts/skills/claude-api/shared/tool-use-concepts.md +526 -0
- package/control-plane/scripts/skills/claude-api/typescript/claude-api/README.md +405 -0
- package/control-plane/scripts/skills/claude-api/typescript/claude-api/batches.md +106 -0
- package/control-plane/scripts/skills/claude-api/typescript/claude-api/files-api.md +98 -0
- package/control-plane/scripts/skills/claude-api/typescript/claude-api/streaming.md +178 -0
- package/control-plane/scripts/skills/claude-api/typescript/claude-api/tool-use.md +586 -0
- package/control-plane/scripts/skills/claude-api/typescript/managed-agents/README.md +359 -0
- package/control-plane/scripts/skills/dispatching-parallel-agents/SKILL.md +167 -0
- package/control-plane/scripts/skills/enhance-prompt/README.md +34 -0
- package/control-plane/scripts/skills/enhance-prompt/SKILL.md +204 -0
- package/control-plane/scripts/skills/enhance-prompt/references/KEYWORDS.md +114 -0
- package/control-plane/scripts/skills/executing-plans/SKILL.md +371 -0
- package/control-plane/scripts/skills/executing-plans/scripts/task-done +52 -0
- package/control-plane/scripts/skills/executing-plans/scripts/task-start +28 -0
- package/control-plane/scripts/skills/extract-design-md/SKILL.md +358 -0
- package/control-plane/scripts/skills/extract-design-md/examples/DESIGN.md +210 -0
- package/control-plane/scripts/skills/extract-design-md/references/angular.md +122 -0
- package/control-plane/scripts/skills/extract-design-md/references/plain-css.md +161 -0
- package/control-plane/scripts/skills/extract-design-md/references/react-tailwind.md +157 -0
- package/control-plane/scripts/skills/extract-design-md/references/svelte.md +101 -0
- package/control-plane/scripts/skills/extract-design-md/references/vue.md +107 -0
- package/control-plane/scripts/skills/finishing-a-development-branch/SKILL.md +225 -0
- package/control-plane/scripts/skills/frontend-design/LICENSE.txt +177 -0
- package/control-plane/scripts/skills/frontend-design/SKILL.md +71 -0
- package/control-plane/scripts/skills/hallmark/SKILL.md +558 -0
- package/control-plane/scripts/skills/hallmark/references/anti-patterns.md +418 -0
- package/control-plane/scripts/skills/hallmark/references/assets.md +406 -0
- package/control-plane/scripts/skills/hallmark/references/color.md +95 -0
- package/control-plane/scripts/skills/hallmark/references/component-cookbook.md +263 -0
- package/control-plane/scripts/skills/hallmark/references/components/c1-outlined-chip.md +12 -0
- package/control-plane/scripts/skills/hallmark/references/components/c2-inline-form-as-cta.md +16 -0
- package/control-plane/scripts/skills/hallmark/references/components/c3-typographic-link.md +8 -0
- package/control-plane/scripts/skills/hallmark/references/components/c4-sticky-bottom-bar.md +16 -0
- package/control-plane/scripts/skills/hallmark/references/components/f1-bento-grid.md +20 -0
- package/control-plane/scripts/skills/hallmark/references/components/f2-sticky-scroll-stack.md +20 -0
- package/control-plane/scripts/skills/hallmark/references/components/f3-tabular-spec-sheet.md +11 -0
- package/control-plane/scripts/skills/hallmark/references/components/f4-step-sequence.md +11 -0
- package/control-plane/scripts/skills/hallmark/references/components/f5-annotated-screenshot.md +11 -0
- package/control-plane/scripts/skills/hallmark/references/components/f6-product-card-grid.md +41 -0
- package/control-plane/scripts/skills/hallmark/references/components/ft1-mast-headed.md +13 -0
- package/control-plane/scripts/skills/hallmark/references/components/ft2-inline-rule-single-line.md +10 -0
- package/control-plane/scripts/skills/hallmark/references/components/ft3-index-style-category-list.md +12 -0
- package/control-plane/scripts/skills/hallmark/references/components/ft4-dense-typographic.md +10 -0
- package/control-plane/scripts/skills/hallmark/references/components/ft5-statement.md +21 -0
- package/control-plane/scripts/skills/hallmark/references/components/ft6-letter-close.md +19 -0
- package/control-plane/scripts/skills/hallmark/references/components/ft7-newsletter-first.md +27 -0
- package/control-plane/scripts/skills/hallmark/references/components/ft8-marquee-scroll.md +25 -0
- package/control-plane/scripts/skills/hallmark/references/components/h1-marquee.md +15 -0
- package/control-plane/scripts/skills/hallmark/references/components/h2-split-diptych.md +15 -0
- package/control-plane/scripts/skills/hallmark/references/components/h3-quote-led.md +11 -0
- package/control-plane/scripts/skills/hallmark/references/components/h4-stat-led.md +14 -0
- package/control-plane/scripts/skills/hallmark/references/components/h5-letter-hero.md +11 -0
- package/control-plane/scripts/skills/hallmark/references/components/h6-photographic-fold.md +16 -0
- package/control-plane/scripts/skills/hallmark/references/components/h7-demo-video-clipped-by-viewport-edge.md +27 -0
- package/control-plane/scripts/skills/hallmark/references/components/h8-mockup-split-browser-framed.md +23 -0
- package/control-plane/scripts/skills/hallmark/references/components/h9-custom-illustration-centerpiece.md +27 -0
- package/control-plane/scripts/skills/hallmark/references/components/n1-wordmark-2-links.md +12 -0
- package/control-plane/scripts/skills/hallmark/references/components/n10-floating-on-scroll-morph.md +19 -0
- package/control-plane/scripts/skills/hallmark/references/components/n11-mega-menu.md +40 -0
- package/control-plane/scripts/skills/hallmark/references/components/n12-banner-retract.md +34 -0
- package/control-plane/scripts/skills/hallmark/references/components/n13-inline-cmdk-pill.md +39 -0
- package/control-plane/scripts/skills/hallmark/references/components/n1b-saas-three-section.md +35 -0
- package/control-plane/scripts/skills/hallmark/references/components/n2-floating-chip.md +14 -0
- package/control-plane/scripts/skills/hallmark/references/components/n3-side-rail.md +14 -0
- package/control-plane/scripts/skills/hallmark/references/components/n4-hidden-behind-k.md +9 -0
- package/control-plane/scripts/skills/hallmark/references/components/n5-floating-pill.md +28 -0
- package/control-plane/scripts/skills/hallmark/references/components/n6-newspaper-masthead.md +24 -0
- package/control-plane/scripts/skills/hallmark/references/components/n7-brutal-slab.md +22 -0
- package/control-plane/scripts/skills/hallmark/references/components/n8-terminal-command.md +21 -0
- package/control-plane/scripts/skills/hallmark/references/components/n9-edge-aligned-minimal.md +17 -0
- package/control-plane/scripts/skills/hallmark/references/components/s1-left-margin-numbered.md +15 -0
- package/control-plane/scripts/skills/hallmark/references/components/s2-hanging.md +13 -0
- package/control-plane/scripts/skills/hallmark/references/components/s3-sticky-pinned.md +19 -0
- package/control-plane/scripts/skills/hallmark/references/components/s4-inline-no-break.md +11 -0
- package/control-plane/scripts/skills/hallmark/references/components/s5-bottom-anchored.md +13 -0
- package/control-plane/scripts/skills/hallmark/references/components/t1-pull-quote-with-marginalia.md +12 -0
- package/control-plane/scripts/skills/hallmark/references/components/t2-logo-wall-hairline.md +19 -0
- package/control-plane/scripts/skills/hallmark/references/components/t3-single-huge-quote.md +11 -0
- package/control-plane/scripts/skills/hallmark/references/components/t4-numbered-stat-strip.md +14 -0
- package/control-plane/scripts/skills/hallmark/references/contract.md +25 -0
- package/control-plane/scripts/skills/hallmark/references/copy.md +182 -0
- package/control-plane/scripts/skills/hallmark/references/custom-craft.md +626 -0
- package/control-plane/scripts/skills/hallmark/references/custom-theme.md +367 -0
- package/control-plane/scripts/skills/hallmark/references/design-md.md +116 -0
- package/control-plane/scripts/skills/hallmark/references/export-formats.md +329 -0
- package/control-plane/scripts/skills/hallmark/references/floating-nav.md +89 -0
- package/control-plane/scripts/skills/hallmark/references/genres/atmospheric.md +69 -0
- package/control-plane/scripts/skills/hallmark/references/genres/editorial.md +72 -0
- package/control-plane/scripts/skills/hallmark/references/genres/modern-minimal.md +71 -0
- package/control-plane/scripts/skills/hallmark/references/genres/playful.md +70 -0
- package/control-plane/scripts/skills/hallmark/references/hero-enrichment.md +475 -0
- package/control-plane/scripts/skills/hallmark/references/imagery-kit.md +170 -0
- package/control-plane/scripts/skills/hallmark/references/interaction-and-states.md +208 -0
- package/control-plane/scripts/skills/hallmark/references/layout-and-space.md +112 -0
- package/control-plane/scripts/skills/hallmark/references/macrostructures/01-bento-grid.md +35 -0
- package/control-plane/scripts/skills/hallmark/references/macrostructures/02-long-document.md +34 -0
- package/control-plane/scripts/skills/hallmark/references/macrostructures/03-marquee-hero.md +31 -0
- package/control-plane/scripts/skills/hallmark/references/macrostructures/04-stat-led.md +34 -0
- package/control-plane/scripts/skills/hallmark/references/macrostructures/05-workbench.md +32 -0
- package/control-plane/scripts/skills/hallmark/references/macrostructures/06-conversational-faq.md +33 -0
- package/control-plane/scripts/skills/hallmark/references/macrostructures/07-manifesto.md +32 -0
- package/control-plane/scripts/skills/hallmark/references/macrostructures/08-photographic.md +34 -0
- package/control-plane/scripts/skills/hallmark/references/macrostructures/09-quote-led.md +32 -0
- package/control-plane/scripts/skills/hallmark/references/macrostructures/10-specimen.md +32 -0
- package/control-plane/scripts/skills/hallmark/references/macrostructures/11-catalogue.md +23 -0
- package/control-plane/scripts/skills/hallmark/references/macrostructures/12-letter.md +23 -0
- package/control-plane/scripts/skills/hallmark/references/macrostructures/13-index-first.md +23 -0
- package/control-plane/scripts/skills/hallmark/references/macrostructures/14-narrative-workflow.md +23 -0
- package/control-plane/scripts/skills/hallmark/references/macrostructures/15-split-studio.md +23 -0
- package/control-plane/scripts/skills/hallmark/references/macrostructures/16-feature-stack.md +23 -0
- package/control-plane/scripts/skills/hallmark/references/macrostructures/17-type-specimen.md +23 -0
- package/control-plane/scripts/skills/hallmark/references/macrostructures/18-portfolio-grid.md +23 -0
- package/control-plane/scripts/skills/hallmark/references/macrostructures/19-map-diagram.md +23 -0
- package/control-plane/scripts/skills/hallmark/references/macrostructures/20-ecosystem-index.md +23 -0
- package/control-plane/scripts/skills/hallmark/references/macrostructures/21-component-playground.md +23 -0
- package/control-plane/scripts/skills/hallmark/references/macrostructures.md +89 -0
- package/control-plane/scripts/skills/hallmark/references/microinteractions.md +258 -0
- package/control-plane/scripts/skills/hallmark/references/motion.md +109 -0
- package/control-plane/scripts/skills/hallmark/references/preview-examples.md +49 -0
- package/control-plane/scripts/skills/hallmark/references/responsive.md +138 -0
- package/control-plane/scripts/skills/hallmark/references/slop-test.md +192 -0
- package/control-plane/scripts/skills/hallmark/references/structure.md +160 -0
- package/control-plane/scripts/skills/hallmark/references/study.md +509 -0
- package/control-plane/scripts/skills/hallmark/references/themes/carnival.md +301 -0
- package/control-plane/scripts/skills/hallmark/references/themes/cobalt.md +146 -0
- package/control-plane/scripts/skills/hallmark/references/themes/grid.md +161 -0
- package/control-plane/scripts/skills/hallmark/references/themes/hum.md +403 -0
- package/control-plane/scripts/skills/hallmark/references/themes/lumen.md +478 -0
- package/control-plane/scripts/skills/hallmark/references/typography.md +243 -0
- package/control-plane/scripts/skills/hallmark/references/upstream/recipes.md +186 -0
- package/control-plane/scripts/skills/hallmark/references/upstream/study-examples.md +176 -0
- package/control-plane/scripts/skills/hallmark/references/upstream/tokens.css +1221 -0
- package/control-plane/scripts/skills/hallmark/references/verbs/audit.md +25 -0
- package/control-plane/scripts/skills/hallmark/references/verbs/redesign.md +269 -0
- package/control-plane/scripts/skills/human-comms/SKILL.md +29 -0
- package/control-plane/scripts/skills/index.mjs +432 -0
- package/control-plane/scripts/skills/internal-comms/LICENSE.txt +202 -0
- package/control-plane/scripts/skills/internal-comms/SKILL.md +32 -0
- package/control-plane/scripts/skills/internal-comms/examples/3p-updates.md +47 -0
- package/control-plane/scripts/skills/internal-comms/examples/company-newsletter.md +65 -0
- package/control-plane/scripts/skills/internal-comms/examples/faq-answers.md +30 -0
- package/control-plane/scripts/skills/internal-comms/examples/general-comms.md +16 -0
- package/control-plane/scripts/skills/mcp-adapter.mjs +94 -0
- package/control-plane/scripts/skills/mcp-builder/LICENSE.txt +202 -0
- package/control-plane/scripts/skills/mcp-builder/SKILL.md +236 -0
- package/control-plane/scripts/skills/mcp-builder/reference/evaluation.md +602 -0
- package/control-plane/scripts/skills/mcp-builder/reference/mcp_best_practices.md +249 -0
- package/control-plane/scripts/skills/mcp-builder/reference/node_mcp_server.md +970 -0
- package/control-plane/scripts/skills/mcp-builder/reference/python_mcp_server.md +719 -0
- package/control-plane/scripts/skills/mcp-builder/scripts/connections.py +151 -0
- package/control-plane/scripts/skills/mcp-builder/scripts/evaluation.py +373 -0
- package/control-plane/scripts/skills/mcp-builder/scripts/example_evaluation.xml +22 -0
- package/control-plane/scripts/skills/mcp-builder/scripts/requirements.txt +2 -0
- package/control-plane/scripts/skills/ponytail/SKILL.md +120 -0
- package/control-plane/scripts/skills/ponytail-audit/SKILL.md +41 -0
- package/control-plane/scripts/skills/ponytail-debt/SKILL.md +44 -0
- package/control-plane/scripts/skills/ponytail-gain/SKILL.md +50 -0
- package/control-plane/scripts/skills/ponytail-help/SKILL.md +71 -0
- package/control-plane/scripts/skills/ponytail-review/SKILL.md +57 -0
- package/control-plane/scripts/skills/receiving-code-review/SKILL.md +205 -0
- package/control-plane/scripts/skills/requesting-code-review/SKILL.md +95 -0
- package/control-plane/scripts/skills/requesting-code-review/code-reviewer.md +198 -0
- package/control-plane/scripts/skills/skill-creator/LICENSE.txt +202 -0
- package/control-plane/scripts/skills/skill-creator/SKILL.md +485 -0
- package/control-plane/scripts/skills/skill-creator/agents/analyzer.md +274 -0
- package/control-plane/scripts/skills/skill-creator/agents/comparator.md +202 -0
- package/control-plane/scripts/skills/skill-creator/agents/grader.md +223 -0
- package/control-plane/scripts/skills/skill-creator/assets/eval_review.html +146 -0
- package/control-plane/scripts/skills/skill-creator/eval-viewer/generate_review.py +471 -0
- package/control-plane/scripts/skills/skill-creator/eval-viewer/viewer.html +1325 -0
- package/control-plane/scripts/skills/skill-creator/references/schemas.md +430 -0
- package/control-plane/scripts/skills/skill-creator/scripts/__init__.py +0 -0
- package/control-plane/scripts/skills/skill-creator/scripts/aggregate_benchmark.py +401 -0
- package/control-plane/scripts/skills/skill-creator/scripts/generate_report.py +326 -0
- package/control-plane/scripts/skills/skill-creator/scripts/improve_description.py +247 -0
- package/control-plane/scripts/skills/skill-creator/scripts/package_skill.py +136 -0
- package/control-plane/scripts/skills/skill-creator/scripts/quick_validate.py +103 -0
- package/control-plane/scripts/skills/skill-creator/scripts/run_eval.py +310 -0
- package/control-plane/scripts/skills/skill-creator/scripts/run_loop.py +328 -0
- package/control-plane/scripts/skills/skill-creator/scripts/utils.py +47 -0
- package/control-plane/scripts/skills/slack-gif-creator/LICENSE.txt +202 -0
- package/control-plane/scripts/skills/slack-gif-creator/SKILL.md +254 -0
- package/control-plane/scripts/skills/slack-gif-creator/core/easing.py +234 -0
- package/control-plane/scripts/skills/slack-gif-creator/core/frame_composer.py +176 -0
- package/control-plane/scripts/skills/slack-gif-creator/core/gif_builder.py +269 -0
- package/control-plane/scripts/skills/slack-gif-creator/core/validators.py +136 -0
- package/control-plane/scripts/skills/slack-gif-creator/requirements.txt +4 -0
- package/control-plane/scripts/skills/sources.json +401 -0
- package/control-plane/scripts/skills/sources.lock.json +416 -0
- package/control-plane/scripts/skills/subagent-driven-development/SKILL.md +570 -0
- package/control-plane/scripts/skills/subagent-driven-development/implementer-prompt.md +154 -0
- package/control-plane/scripts/skills/subagent-driven-development/re-review-prompt.md +115 -0
- package/control-plane/scripts/skills/subagent-driven-development/scripts/review-package +53 -0
- package/control-plane/scripts/skills/subagent-driven-development/scripts/sdd-workspace +82 -0
- package/control-plane/scripts/skills/subagent-driven-development/scripts/task-brief +43 -0
- package/control-plane/scripts/skills/subagent-driven-development/task-reviewer-prompt.md +207 -0
- package/control-plane/scripts/skills/systematic-debugging/CREATION-LOG.md +119 -0
- package/control-plane/scripts/skills/systematic-debugging/SKILL.md +283 -0
- package/control-plane/scripts/skills/systematic-debugging/condition-based-waiting-example.ts +158 -0
- package/control-plane/scripts/skills/systematic-debugging/condition-based-waiting.md +115 -0
- package/control-plane/scripts/skills/systematic-debugging/defense-in-depth.md +122 -0
- package/control-plane/scripts/skills/systematic-debugging/find-polluter.sh +72 -0
- package/control-plane/scripts/skills/systematic-debugging/root-cause-tracing.md +169 -0
- package/control-plane/scripts/skills/systematic-debugging/test-academic.md +14 -0
- package/control-plane/scripts/skills/systematic-debugging/test-pressure-1.md +58 -0
- package/control-plane/scripts/skills/systematic-debugging/test-pressure-2.md +68 -0
- package/control-plane/scripts/skills/systematic-debugging/test-pressure-3.md +69 -0
- package/control-plane/scripts/skills/test-driven-development/SKILL.md +330 -0
- package/control-plane/scripts/skills/test-driven-development/writing-good-tests.md +198 -0
- package/control-plane/scripts/skills/theme-factory/LICENSE.txt +202 -0
- package/control-plane/scripts/skills/theme-factory/SKILL.md +59 -0
- package/control-plane/scripts/skills/theme-factory/theme-showcase.pdf +0 -0
- package/control-plane/scripts/skills/theme-factory/themes/arctic-frost.md +19 -0
- package/control-plane/scripts/skills/theme-factory/themes/botanical-garden.md +19 -0
- package/control-plane/scripts/skills/theme-factory/themes/desert-rose.md +19 -0
- package/control-plane/scripts/skills/theme-factory/themes/forest-canopy.md +19 -0
- package/control-plane/scripts/skills/theme-factory/themes/golden-hour.md +19 -0
- package/control-plane/scripts/skills/theme-factory/themes/midnight-galaxy.md +19 -0
- package/control-plane/scripts/skills/theme-factory/themes/modern-minimalist.md +19 -0
- package/control-plane/scripts/skills/theme-factory/themes/ocean-depths.md +19 -0
- package/control-plane/scripts/skills/theme-factory/themes/sunset-boulevard.md +19 -0
- package/control-plane/scripts/skills/theme-factory/themes/tech-innovation.md +19 -0
- package/control-plane/scripts/skills/using-git-worktrees/SKILL.md +167 -0
- package/control-plane/scripts/skills/verification-before-completion/SKILL.md +120 -0
- package/control-plane/scripts/skills/web-artifacts-builder/LICENSE.txt +202 -0
- package/control-plane/scripts/skills/web-artifacts-builder/SKILL.md +74 -0
- package/control-plane/scripts/skills/web-artifacts-builder/scripts/bundle-artifact.sh +54 -0
- package/control-plane/scripts/skills/web-artifacts-builder/scripts/init-artifact.sh +322 -0
- package/control-plane/scripts/skills/web-artifacts-builder/scripts/shadcn-components.tar.gz +0 -0
- package/control-plane/scripts/skills/webapp-testing/LICENSE.txt +202 -0
- package/control-plane/scripts/skills/webapp-testing/SKILL.md +96 -0
- package/control-plane/scripts/skills/webapp-testing/examples/console_logging.py +35 -0
- package/control-plane/scripts/skills/webapp-testing/examples/element_discovery.py +40 -0
- package/control-plane/scripts/skills/webapp-testing/examples/static_html_automation.py +33 -0
- package/control-plane/scripts/skills/webapp-testing/scripts/with_server.py +106 -0
- package/control-plane/scripts/skills/writing-plans/SKILL.md +192 -0
- package/control-plane/scripts/skills/writing-plans/plan-document-reviewer-prompt.md +49 -0
- package/control-plane/scripts/skills/writing-skills/SKILL.md +681 -0
- package/control-plane/scripts/skills/writing-skills/anthropic-best-practices.md +1150 -0
- package/control-plane/scripts/skills/writing-skills/examples/CLAUDE_MD_TESTING.md +189 -0
- package/control-plane/scripts/skills/writing-skills/graphviz-conventions.dot +172 -0
- package/control-plane/scripts/skills/writing-skills/persuasion-principles.md +187 -0
- package/control-plane/scripts/skills/writing-skills/render-graphs.js +169 -0
- package/control-plane/scripts/skills/writing-skills/testing-skills-with-subagents.md +384 -0
- package/control-plane/scripts/smoke-mcp-schemas.mjs +30 -0
- package/control-plane/scripts/surface-config.mjs +45 -0
- package/control-plane/scripts/sync-skills.mjs +370 -0
- package/control-plane/scripts/tool-metrics.mjs +74 -0
- package/control-plane/scripts/tool-risk.mjs +156 -0
- package/control-plane/scripts/tool-surface-stability.mjs +38 -0
- package/control-plane/scripts/upstreams/catalog-cache.mjs +28 -0
- package/control-plane/scripts/upstreams/config.mjs +158 -0
- package/control-plane/scripts/upstreams/diagnostics.mjs +21 -0
- package/control-plane/scripts/upstreams/http-client.mjs +67 -0
- package/control-plane/scripts/upstreams/manager.mjs +535 -0
- package/control-plane/scripts/upstreams/names.mjs +55 -0
- package/control-plane/scripts/upstreams/presets.mjs +60 -0
- package/control-plane/scripts/upstreams/resource-uri.mjs +29 -0
- package/control-plane/scripts/upstreams/stdio-client.mjs +73 -0
- package/control-plane/scripts/workspace-registry.mjs +147 -0
- package/dist/context/authorization.d.ts +5 -0
- package/dist/context/authorization.js +70 -0
- package/dist/context/capture.d.ts +46 -0
- package/dist/context/capture.js +187 -0
- package/dist/context/cli.d.ts +47 -0
- package/dist/context/cli.js +287 -0
- package/dist/context/device-adapter.d.ts +102 -0
- package/dist/context/device-adapter.js +79 -0
- package/dist/context/gateway.d.ts +354 -0
- package/dist/context/gateway.js +50 -0
- package/dist/context/graph.d.ts +63 -0
- package/dist/context/graph.js +214 -0
- package/dist/context/importer.d.ts +8 -0
- package/dist/context/importer.js +69 -0
- package/dist/context/indexer.d.ts +14 -0
- package/dist/context/indexer.js +57 -0
- package/dist/context/migrations/index.d.ts +4 -0
- package/dist/context/migrations/index.js +87 -0
- package/dist/context/redact.d.ts +15 -0
- package/dist/context/redact.js +43 -0
- package/dist/context/repositories.d.ts +9 -0
- package/dist/context/repositories.js +45 -0
- package/dist/context/search.d.ts +63 -0
- package/dist/context/search.js +207 -0
- package/dist/context/service.d.ts +278 -0
- package/dist/context/service.js +160 -0
- package/dist/context/store.d.ts +134 -0
- package/dist/context/store.js +722 -0
- package/dist/context/text.d.ts +4 -0
- package/dist/context/text.js +14 -0
- package/dist/context/tool-contract.d.ts +534 -0
- package/dist/context/tool-contract.js +45 -0
- package/dist/device/core.d.ts +29 -0
- package/dist/device/core.js +66 -0
- package/dist/device/device.d.ts +5 -0
- package/dist/device/device.js +94 -37
- package/dist/device/gateway-channel.d.ts +8 -1
- package/dist/device/gateway-channel.js +51 -3
- package/dist/device/gateway-tool-adapter.d.ts +11 -3
- package/dist/device/gateway-tool-adapter.js +141 -98
- package/dist/device/official-trust.d.ts +12 -0
- package/dist/device/official-trust.js +25 -1
- package/dist/device/runtime-owner.js +9 -1
- package/dist/distribution.d.ts +4 -0
- package/dist/distribution.js +8 -0
- package/dist/handlers/filesystem-handlers.js +53 -37
- package/dist/handlers/search-handlers.d.ts +1 -0
- package/dist/handlers/search-handlers.js +51 -1
- package/dist/log-palace/cli.d.ts +7 -0
- package/dist/log-palace/cli.js +89 -0
- package/dist/log-palace/formats.d.ts +26 -0
- package/dist/log-palace/formats.js +126 -0
- package/dist/log-palace/store.d.ts +129 -0
- package/dist/log-palace/store.js +856 -0
- package/dist/mcp-device.d.ts +1 -1
- package/dist/mcp-device.js +28 -6
- package/dist/npm-scripts/remote.js +1 -0
- package/dist/platform/activity-journal.d.ts +16 -0
- package/dist/platform/activity-journal.js +68 -0
- package/dist/platform/cli.d.ts +1 -0
- package/dist/platform/cli.js +300 -0
- package/dist/platform/coordination-lock.d.ts +45 -0
- package/dist/platform/coordination-lock.js +233 -0
- package/dist/platform/device-runtime.d.ts +16 -0
- package/dist/platform/device-runtime.js +83 -0
- package/dist/platform/knowledge-contract.d.ts +46 -0
- package/dist/platform/knowledge-contract.js +1 -0
- package/dist/platform/knowledge-mcp.d.ts +29 -0
- package/dist/platform/knowledge-mcp.js +95 -0
- package/dist/platform/knowledge-router.d.ts +64 -0
- package/dist/platform/knowledge-router.js +320 -0
- package/dist/platform/plugin-child.d.ts +1 -0
- package/dist/platform/plugin-child.js +115 -0
- package/dist/platform/plugin-contract.d.ts +76 -0
- package/dist/platform/plugin-contract.js +53 -0
- package/dist/platform/plugin-driver.d.ts +8 -0
- package/dist/platform/plugin-driver.js +443 -0
- package/dist/platform/plugin-host.d.ts +88 -0
- package/dist/platform/plugin-host.js +817 -0
- package/dist/platform/plugin-policy.d.ts +3 -0
- package/dist/platform/plugin-policy.js +29 -0
- package/dist/platform/plugin-services.d.ts +14 -0
- package/dist/platform/plugin-services.js +32 -0
- package/dist/platform/process-identity.d.ts +9 -0
- package/dist/platform/process-identity.js +68 -0
- package/dist/platform/runtime-lease.d.ts +4 -0
- package/dist/platform/runtime-lease.js +58 -0
- package/dist/platform/runtime-root.d.ts +9 -0
- package/dist/platform/runtime-root.js +61 -0
- package/dist/platform/state-backup.d.ts +92 -0
- package/dist/platform/state-backup.js +399 -0
- package/dist/plugins/reference/plugin.d.ts +3 -0
- package/dist/plugins/reference/plugin.js +13 -0
- package/dist/search-manager.d.ts +6 -0
- package/dist/search-manager.js +123 -0
- package/dist/server.d.ts +13 -0
- package/dist/server.js +7 -3
- package/dist/terminal-manager.d.ts +16 -0
- package/dist/terminal-manager.js +137 -42
- package/dist/tool-dispatcher.d.ts +11 -0
- package/dist/tool-dispatcher.js +228 -0
- package/dist/tools/edit.js +72 -1
- package/dist/tools/filesystem.d.ts +1 -1
- package/dist/tools/filesystem.js +2 -2
- package/dist/tools/improved-process-tools.js +91 -108
- package/dist/tools/schemas.d.ts +94 -2
- package/dist/tools/schemas.js +20 -6
- package/dist/types.d.ts +8 -0
- package/dist/utils/output-budget.d.ts +6 -0
- package/dist/utils/output-budget.js +15 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +29 -6
- package/skills/mcp-device-context/SKILL.md +40 -0
|
@@ -0,0 +1,399 @@
|
|
|
1
|
+
import { closeSync, constants, copyFileSync, existsSync, fstatSync, fsyncSync, lstatSync, mkdirSync, openSync, readFileSync, readSync, readdirSync, renameSync, rmSync, writeFileSync, chmodSync } from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { createHash, randomUUID } from 'node:crypto';
|
|
4
|
+
import { acquireServerLease } from './runtime-lease.js';
|
|
5
|
+
import { probeRuntimeOwner } from '../device/runtime-owner.js';
|
|
6
|
+
const EXCLUDED = ['server-runtime.lock', 'plugins/registry.lock'];
|
|
7
|
+
const MAX_FILES = 100000, MAX_BYTES = 32 * 1024 * 1024 * 1024;
|
|
8
|
+
function digest(value) { return createHash('sha256').update(JSON.stringify(value)).digest('hex'); }
|
|
9
|
+
function fail(message) { throw new Error(message); }
|
|
10
|
+
function relativePath(value) {
|
|
11
|
+
if (typeof value !== 'string' || !value || value.includes('\\') || value.includes(':') || value.includes('\0') ||
|
|
12
|
+
path.posix.isAbsolute(value) || path.win32.isAbsolute(value) || value.split('/').some(x => !x || x === '.' || x === '..'))
|
|
13
|
+
fail('UNSAFE_BACKUP_PATH');
|
|
14
|
+
return value;
|
|
15
|
+
}
|
|
16
|
+
function noSymlinkAncestors(input) {
|
|
17
|
+
const absolute = path.resolve(input), parsed = path.parse(absolute);
|
|
18
|
+
let current = parsed.root;
|
|
19
|
+
for (const segment of absolute.slice(parsed.root.length).split(path.sep).filter(Boolean)) {
|
|
20
|
+
current = path.join(current, segment);
|
|
21
|
+
try {
|
|
22
|
+
if (lstatSync(current).isSymbolicLink())
|
|
23
|
+
fail('SYMLINK_STATE_PATH');
|
|
24
|
+
}
|
|
25
|
+
catch (error) {
|
|
26
|
+
if (error.code === 'ENOENT')
|
|
27
|
+
break;
|
|
28
|
+
throw error;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return absolute;
|
|
32
|
+
}
|
|
33
|
+
function sourceRoot(input) {
|
|
34
|
+
const root = noSymlinkAncestors(input);
|
|
35
|
+
if (root === path.parse(root).root || !existsSync(root) || !lstatSync(root).isDirectory())
|
|
36
|
+
fail('STATE_SOURCE_DIRECTORY_REQUIRED');
|
|
37
|
+
return root;
|
|
38
|
+
}
|
|
39
|
+
function absentTarget(input) {
|
|
40
|
+
const target = noSymlinkAncestors(input);
|
|
41
|
+
if (target === path.parse(target).root || existsSync(target))
|
|
42
|
+
fail('STATE_TARGET_MUST_NOT_EXIST');
|
|
43
|
+
return target;
|
|
44
|
+
}
|
|
45
|
+
function contained(a, b) { const r = path.relative(a, b); return r === '' || (!r.startsWith('..' + path.sep) && r !== '..' && !path.isAbsolute(r)); }
|
|
46
|
+
function separate(...roots) {
|
|
47
|
+
for (let i = 0; i < roots.length; i++)
|
|
48
|
+
for (let j = i + 1; j < roots.length; j++)
|
|
49
|
+
if (contained(roots[i], roots[j]) || contained(roots[j], roots[i]))
|
|
50
|
+
fail('STATE_ROOTS_OVERLAP');
|
|
51
|
+
}
|
|
52
|
+
async function assertStopped(root, ownedLease = false) {
|
|
53
|
+
const owner = await probeRuntimeOwner({ root, identity: path.join(root, 'gateway-identity.json'), config: path.join(root, 'gateway-config.json'),
|
|
54
|
+
status: path.join(root, 'gateway-status.json'), runtime: path.join(root, 'runtime'), update: path.join(root, 'update') });
|
|
55
|
+
if (owner)
|
|
56
|
+
fail('DEVICE_RUNTIME_ACTIVE');
|
|
57
|
+
if (existsSync(path.join(root, 'runtime-control.json')))
|
|
58
|
+
fail('DEVICE_RUNTIME_STOP_NOT_PROVEN');
|
|
59
|
+
const registry = path.join(root, 'plugins', 'registry.lock');
|
|
60
|
+
if (existsSync(registry))
|
|
61
|
+
fail('PLUGIN_REGISTRY_BUSY');
|
|
62
|
+
const lease = path.join(root, 'server-runtime.lock');
|
|
63
|
+
if (!ownedLease && existsSync(lease)) {
|
|
64
|
+
let pid;
|
|
65
|
+
try {
|
|
66
|
+
pid = JSON.parse(readFileSync(lease, 'utf8')).pid;
|
|
67
|
+
}
|
|
68
|
+
catch {
|
|
69
|
+
fail('STATE_RUNTIME_LEASE_UNREADABLE');
|
|
70
|
+
}
|
|
71
|
+
if (!Number.isSafeInteger(pid) || pid <= 0)
|
|
72
|
+
fail('STATE_RUNTIME_LEASE_UNREADABLE');
|
|
73
|
+
try {
|
|
74
|
+
process.kill(pid, 0);
|
|
75
|
+
fail('STATE_RUNTIME_ACTIVE');
|
|
76
|
+
}
|
|
77
|
+
catch (error) {
|
|
78
|
+
if (error.code !== 'ESRCH')
|
|
79
|
+
throw error;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
function fileRecord(root, relative) {
|
|
84
|
+
relativePath(relative);
|
|
85
|
+
const full = path.join(root, ...relative.split('/'));
|
|
86
|
+
noSymlinkAncestors(full);
|
|
87
|
+
const before = lstatSync(full);
|
|
88
|
+
if (!before.isFile() || before.isSymbolicLink())
|
|
89
|
+
fail('NONREGULAR_STATE_FILE');
|
|
90
|
+
if (before.size > MAX_BYTES)
|
|
91
|
+
fail('STATE_BACKUP_TOO_LARGE');
|
|
92
|
+
const fd = openSync(full, constants.O_RDONLY | (constants.O_NOFOLLOW ?? 0));
|
|
93
|
+
const hasher = createHash('sha256'), buffer = Buffer.allocUnsafe(64 * 1024);
|
|
94
|
+
let offset = 0;
|
|
95
|
+
try {
|
|
96
|
+
if (!fstatSync(fd).isFile())
|
|
97
|
+
fail('NONREGULAR_STATE_FILE');
|
|
98
|
+
for (;;) {
|
|
99
|
+
const size = readSync(fd, buffer, 0, buffer.length, offset);
|
|
100
|
+
if (!size)
|
|
101
|
+
break;
|
|
102
|
+
hasher.update(buffer.subarray(0, size));
|
|
103
|
+
offset += size;
|
|
104
|
+
}
|
|
105
|
+
const after = fstatSync(fd);
|
|
106
|
+
if (offset !== before.size || after.size !== before.size || after.mtimeMs !== before.mtimeMs || after.ino !== before.ino)
|
|
107
|
+
fail('STATE_CHANGED_DURING_BACKUP');
|
|
108
|
+
}
|
|
109
|
+
finally {
|
|
110
|
+
closeSync(fd);
|
|
111
|
+
}
|
|
112
|
+
return { path: relative, bytes: offset, sha256: hasher.digest('hex'), mode: before.mode & 0o777 };
|
|
113
|
+
}
|
|
114
|
+
function inventory(root, options = {}) {
|
|
115
|
+
const files = [], directories = [];
|
|
116
|
+
let totalBytes = 0;
|
|
117
|
+
const names = new Set();
|
|
118
|
+
const visit = (directory, prefix = '') => {
|
|
119
|
+
for (const entry of readdirSync(directory, { withFileTypes: true }).sort((a, b) => a.name.localeCompare(b.name))) {
|
|
120
|
+
const rel = relativePath(prefix ? prefix + '/' + entry.name : entry.name);
|
|
121
|
+
if (options.excludeLocks !== false && EXCLUDED.includes(rel))
|
|
122
|
+
continue;
|
|
123
|
+
// An ancestor lease does not stop a nested Device/server or its plugin writer.
|
|
124
|
+
if (options.excludeLocks !== false && rel.includes('/') &&
|
|
125
|
+
(['server-runtime.lock', 'runtime-control.json'].includes(entry.name) || rel.endsWith('/plugins/registry.lock')))
|
|
126
|
+
fail('NESTED_RUNTIME_REQUIRES_SEPARATE_STOPPED_BACKUP');
|
|
127
|
+
const key = rel.toLocaleLowerCase('en-US');
|
|
128
|
+
if (names.has(key))
|
|
129
|
+
fail('CASE_COLLIDING_STATE_PATH');
|
|
130
|
+
names.add(key);
|
|
131
|
+
const full = path.join(directory, entry.name), stat = lstatSync(full);
|
|
132
|
+
if (stat.isSymbolicLink())
|
|
133
|
+
fail('SYMLINK_STATE_PATH');
|
|
134
|
+
if (stat.isDirectory()) {
|
|
135
|
+
directories.push(rel);
|
|
136
|
+
visit(full, rel);
|
|
137
|
+
continue;
|
|
138
|
+
}
|
|
139
|
+
if (!stat.isFile())
|
|
140
|
+
fail('NONREGULAR_STATE_FILE');
|
|
141
|
+
if (options.rejectWal !== false && /(?:-wal|-journal)$/i.test(rel) && stat.size > 0)
|
|
142
|
+
fail('SQLITE_CHECKPOINT_REQUIRED');
|
|
143
|
+
if (files.length >= MAX_FILES)
|
|
144
|
+
fail('STATE_FILE_LIMIT');
|
|
145
|
+
const file = fileRecord(root, rel);
|
|
146
|
+
files.push(file);
|
|
147
|
+
totalBytes += file.bytes;
|
|
148
|
+
if (totalBytes > MAX_BYTES)
|
|
149
|
+
fail('STATE_BACKUP_TOO_LARGE');
|
|
150
|
+
}
|
|
151
|
+
};
|
|
152
|
+
visit(root);
|
|
153
|
+
files.sort((a, b) => a.path.localeCompare(b.path));
|
|
154
|
+
directories.sort();
|
|
155
|
+
return { files, directories, totalBytes, sourceDigest: digest({ files: files.map(({ mode, ...file }) => file), directories, totalBytes }) };
|
|
156
|
+
}
|
|
157
|
+
function flushFile(file) {
|
|
158
|
+
const mode = lstatSync(file).mode & 0o777;
|
|
159
|
+
chmodSync(file, mode | 0o600);
|
|
160
|
+
const fd = openSync(file, 'r+');
|
|
161
|
+
try {
|
|
162
|
+
fsyncSync(fd);
|
|
163
|
+
}
|
|
164
|
+
finally {
|
|
165
|
+
closeSync(fd);
|
|
166
|
+
chmodSync(file, mode);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
function writeJson(file, value) { writeFileSync(file, JSON.stringify(value, null, 2) + '\n', { mode: 0o600, flag: 'wx' }); flushFile(file); }
|
|
170
|
+
function copyInventory(from, to, items) {
|
|
171
|
+
mkdirSync(to, { recursive: false, mode: 0o700 });
|
|
172
|
+
for (const directory of items.directories)
|
|
173
|
+
mkdirSync(path.join(to, ...relativePath(directory).split('/')), { recursive: true, mode: 0o700 });
|
|
174
|
+
for (const file of items.files) {
|
|
175
|
+
const destination = path.join(to, ...relativePath(file.path).split('/'));
|
|
176
|
+
mkdirSync(path.dirname(destination), { recursive: true, mode: 0o700 });
|
|
177
|
+
copyFileSync(path.join(from, ...file.path.split('/')), destination, constants.COPYFILE_EXCL);
|
|
178
|
+
chmodSync(destination, file.mode);
|
|
179
|
+
flushFile(destination);
|
|
180
|
+
if (fileRecord(to, file.path).sha256 !== file.sha256)
|
|
181
|
+
fail('STATE_CHANGED_DURING_BACKUP');
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
function stageFor(target) {
|
|
185
|
+
mkdirSync(path.dirname(target), { recursive: true, mode: 0o700 });
|
|
186
|
+
noSymlinkAncestors(path.dirname(target));
|
|
187
|
+
const stage = path.join(path.dirname(target), '.' + path.basename(target) + '.' + randomUUID() + '.staging');
|
|
188
|
+
mkdirSync(stage, { mode: 0o700 });
|
|
189
|
+
return stage;
|
|
190
|
+
}
|
|
191
|
+
function publish(stage, target) { absentTarget(target); renameSync(stage, target); }
|
|
192
|
+
async function destinationGuard(target, operation) {
|
|
193
|
+
mkdirSync(path.dirname(target), { recursive: true, mode: 0o700 });
|
|
194
|
+
noSymlinkAncestors(path.dirname(target));
|
|
195
|
+
const guard = path.join(path.dirname(target), '.' + path.basename(target) + '.state-operation.lock');
|
|
196
|
+
let fd;
|
|
197
|
+
try {
|
|
198
|
+
fd = openSync(guard, 'wx', 0o600);
|
|
199
|
+
}
|
|
200
|
+
catch (error) {
|
|
201
|
+
if (error.code === 'EEXIST')
|
|
202
|
+
fail('STATE_OPERATION_BUSY');
|
|
203
|
+
throw error;
|
|
204
|
+
}
|
|
205
|
+
try {
|
|
206
|
+
writeFileSync(fd, JSON.stringify({ pid: process.pid, token: randomUUID() }));
|
|
207
|
+
return await operation();
|
|
208
|
+
}
|
|
209
|
+
finally {
|
|
210
|
+
closeSync(fd);
|
|
211
|
+
rmSync(guard, { force: true });
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
function manifestFor(root, items) {
|
|
215
|
+
const base = { schemaVersion: 1, kind: 'mcp-device-state-backup', createdAt: new Date().toISOString(),
|
|
216
|
+
sourceRoot: root, ...items, excluded: [...EXCLUDED] };
|
|
217
|
+
return { ...base, manifestHash: digest(base) };
|
|
218
|
+
}
|
|
219
|
+
function writeBundle(root, destination, items) {
|
|
220
|
+
mkdirSync(destination, { mode: 0o700 });
|
|
221
|
+
copyInventory(root, path.join(destination, 'data'), items);
|
|
222
|
+
const manifest = manifestFor(root, items);
|
|
223
|
+
writeJson(path.join(destination, 'manifest.json'), manifest);
|
|
224
|
+
return manifest;
|
|
225
|
+
}
|
|
226
|
+
function verifyBundle(root) {
|
|
227
|
+
sourceRoot(root);
|
|
228
|
+
const manifestPath = path.join(root, 'manifest.json');
|
|
229
|
+
noSymlinkAncestors(manifestPath);
|
|
230
|
+
if (lstatSync(manifestPath).size > 32 * 1024 * 1024)
|
|
231
|
+
fail('BACKUP_MANIFEST_TOO_LARGE');
|
|
232
|
+
const parsed = JSON.parse(readFileSync(manifestPath, 'utf8'));
|
|
233
|
+
if (parsed.schemaVersion !== 1 || parsed.kind !== 'mcp-device-state-backup' || !Array.isArray(parsed.files) ||
|
|
234
|
+
!Array.isArray(parsed.directories) || parsed.files.length > MAX_FILES)
|
|
235
|
+
fail('INVALID_BACKUP_MANIFEST');
|
|
236
|
+
const { manifestHash, ...body } = parsed;
|
|
237
|
+
if (digest(body) !== manifestHash)
|
|
238
|
+
fail('BACKUP_MANIFEST_HASH_MISMATCH');
|
|
239
|
+
for (const file of parsed.files) {
|
|
240
|
+
relativePath(file.path);
|
|
241
|
+
if (!Number.isSafeInteger(file.bytes) || file.bytes < 0 || !Number.isSafeInteger(file.mode) || file.mode < 0 || file.mode > 0o777 ||
|
|
242
|
+
!/^[a-f0-9]{64}$/.test(file.sha256))
|
|
243
|
+
fail('INVALID_BACKUP_MANIFEST');
|
|
244
|
+
}
|
|
245
|
+
for (const directory of parsed.directories)
|
|
246
|
+
relativePath(directory);
|
|
247
|
+
const data = sourceRoot(path.join(root, 'data')), actual = inventory(data, { excludeLocks: false, rejectWal: false });
|
|
248
|
+
if (actual.sourceDigest !== parsed.sourceDigest || actual.totalBytes !== parsed.totalBytes ||
|
|
249
|
+
digest(actual.files.map(({ mode, ...file }) => file)) !== digest(parsed.files.map(({ mode, ...file }) => file)) || digest(actual.directories) !== digest(parsed.directories))
|
|
250
|
+
fail('BACKUP_CONTENT_HASH_MISMATCH');
|
|
251
|
+
const extras = readdirSync(root).filter(name => !['data', 'manifest.json'].includes(name));
|
|
252
|
+
if (extras.length)
|
|
253
|
+
fail('UNMANIFESTED_BACKUP_FILE');
|
|
254
|
+
return parsed;
|
|
255
|
+
}
|
|
256
|
+
export async function planStateBackup(options) {
|
|
257
|
+
const root = sourceRoot(options.sourceRoot), backupRoot = absentTarget(options.backupRoot);
|
|
258
|
+
separate(root, backupRoot);
|
|
259
|
+
await assertStopped(root);
|
|
260
|
+
return { schemaVersion: 1, kind: 'mcp-device-state-backup-plan', sourceRoot: root, backupRoot, dryRun: true, excluded: [...EXCLUDED], ...inventory(root) };
|
|
261
|
+
}
|
|
262
|
+
export async function createStateBackup(options) {
|
|
263
|
+
const root = sourceRoot(options.sourceRoot), backupRoot = absentTarget(options.backupRoot);
|
|
264
|
+
separate(root, backupRoot);
|
|
265
|
+
return destinationGuard(backupRoot, async () => {
|
|
266
|
+
const release = await acquireServerLease(root);
|
|
267
|
+
let stage;
|
|
268
|
+
try {
|
|
269
|
+
await assertStopped(root, true);
|
|
270
|
+
const items = inventory(root);
|
|
271
|
+
stage = stageFor(backupRoot);
|
|
272
|
+
const bundle = path.join(stage, 'bundle');
|
|
273
|
+
const manifest = writeBundle(root, bundle, items);
|
|
274
|
+
await assertStopped(root, true);
|
|
275
|
+
if (inventory(root).sourceDigest !== items.sourceDigest)
|
|
276
|
+
fail('STATE_CHANGED_DURING_BACKUP');
|
|
277
|
+
verifyBundle(bundle);
|
|
278
|
+
publish(bundle, backupRoot);
|
|
279
|
+
return { backupRoot, manifest };
|
|
280
|
+
}
|
|
281
|
+
finally {
|
|
282
|
+
if (stage)
|
|
283
|
+
rmSync(stage, { recursive: true, force: true });
|
|
284
|
+
await release();
|
|
285
|
+
}
|
|
286
|
+
});
|
|
287
|
+
}
|
|
288
|
+
export async function verifyStateBackup(options) {
|
|
289
|
+
const backupRoot = sourceRoot(options.backupRoot);
|
|
290
|
+
return { valid: true, backupRoot, manifest: verifyBundle(backupRoot) };
|
|
291
|
+
}
|
|
292
|
+
export async function restoreStateBackup(options) {
|
|
293
|
+
const backupRoot = sourceRoot(options.backupRoot), targetRoot = absentTarget(options.targetRoot);
|
|
294
|
+
separate(backupRoot, targetRoot);
|
|
295
|
+
return destinationGuard(targetRoot, async () => {
|
|
296
|
+
const manifest = verifyBundle(backupRoot);
|
|
297
|
+
const stage = stageFor(targetRoot), restored = path.join(stage, 'state');
|
|
298
|
+
try {
|
|
299
|
+
copyInventory(path.join(backupRoot, 'data'), restored, manifest);
|
|
300
|
+
if (inventory(restored, { excludeLocks: false, rejectWal: false }).sourceDigest !== manifest.sourceDigest)
|
|
301
|
+
fail('RESTORE_HASH_MISMATCH');
|
|
302
|
+
verifyBundle(backupRoot);
|
|
303
|
+
publish(restored, targetRoot);
|
|
304
|
+
return { targetRoot, files: manifest.files.length, bytes: manifest.totalBytes, sourceDigest: manifest.sourceDigest };
|
|
305
|
+
}
|
|
306
|
+
finally {
|
|
307
|
+
rmSync(stage, { recursive: true, force: true });
|
|
308
|
+
}
|
|
309
|
+
});
|
|
310
|
+
}
|
|
311
|
+
function collisionCheck(device, gateway) {
|
|
312
|
+
const files = new Set(device.files.map(f => f.path.toLowerCase())), dirs = new Set(device.directories.map(d => d.toLowerCase()));
|
|
313
|
+
for (const file of gateway.files)
|
|
314
|
+
if (files.has(file.path.toLowerCase()) || dirs.has(file.path.toLowerCase()))
|
|
315
|
+
fail('MIGRATION_PATH_COLLISION:' + file.path);
|
|
316
|
+
for (const directory of gateway.directories)
|
|
317
|
+
if (files.has(directory.toLowerCase()))
|
|
318
|
+
fail('MIGRATION_PATH_COLLISION:' + directory);
|
|
319
|
+
}
|
|
320
|
+
export async function planLegacyMigration(options) {
|
|
321
|
+
const deviceRoot = sourceRoot(options.deviceRoot), gatewayRoot = sourceRoot(options.gatewayRoot), targetRoot = absentTarget(options.targetRoot), backupRoot = absentTarget(options.backupRoot);
|
|
322
|
+
separate(deviceRoot, gatewayRoot, targetRoot, backupRoot);
|
|
323
|
+
await assertStopped(deviceRoot);
|
|
324
|
+
await assertStopped(gatewayRoot);
|
|
325
|
+
const device = inventory(deviceRoot), gateway = inventory(gatewayRoot);
|
|
326
|
+
collisionCheck(device, gateway);
|
|
327
|
+
if (!gateway.files.some(file => file.path === 'gateway.sqlite'))
|
|
328
|
+
fail('LEGACY_GATEWAY_DATABASE_REQUIRED');
|
|
329
|
+
const mappings = [
|
|
330
|
+
...device.files.map(file => ({ source: 'device', path: file.path, targetPath: file.path })),
|
|
331
|
+
...gateway.files.map(file => ({ source: 'gateway', path: file.path, targetPath: file.path }))
|
|
332
|
+
];
|
|
333
|
+
const base = { schemaVersion: 1, kind: 'mcp-device-legacy-migration-plan', dryRun: options.dryRun !== false,
|
|
334
|
+
deviceRoot, gatewayRoot, targetRoot, backupRoot, device, gateway, mappings };
|
|
335
|
+
return { ...base, planHash: digest(base) };
|
|
336
|
+
}
|
|
337
|
+
export async function applyLegacyMigration(options) {
|
|
338
|
+
const plan = options.plan, { planHash, ...body } = plan;
|
|
339
|
+
if (plan.schemaVersion !== 1 || plan.kind !== 'mcp-device-legacy-migration-plan' || digest(body) !== planHash)
|
|
340
|
+
fail('MIGRATION_PLAN_HASH_MISMATCH');
|
|
341
|
+
const fresh = await planLegacyMigration(plan);
|
|
342
|
+
if (fresh.planHash !== plan.planHash)
|
|
343
|
+
fail('MIGRATION_PLAN_STALE');
|
|
344
|
+
return destinationGuard(plan.targetRoot, async () => destinationGuard(plan.backupRoot, async () => {
|
|
345
|
+
const releases = [];
|
|
346
|
+
let backupStage, targetStage;
|
|
347
|
+
try {
|
|
348
|
+
for (const root of [plan.deviceRoot, plan.gatewayRoot].sort())
|
|
349
|
+
releases.push(await acquireServerLease(root));
|
|
350
|
+
await assertStopped(plan.deviceRoot, true);
|
|
351
|
+
await assertStopped(plan.gatewayRoot, true);
|
|
352
|
+
const device = inventory(plan.deviceRoot), gateway = inventory(plan.gatewayRoot);
|
|
353
|
+
collisionCheck(device, gateway);
|
|
354
|
+
if (device.sourceDigest !== plan.device.sourceDigest || gateway.sourceDigest !== plan.gateway.sourceDigest)
|
|
355
|
+
fail('MIGRATION_PLAN_STALE');
|
|
356
|
+
backupStage = stageFor(plan.backupRoot);
|
|
357
|
+
const bundle = path.join(backupStage, 'backup');
|
|
358
|
+
mkdirSync(bundle, { mode: 0o700 });
|
|
359
|
+
writeBundle(plan.deviceRoot, path.join(bundle, 'device'), device);
|
|
360
|
+
writeBundle(plan.gatewayRoot, path.join(bundle, 'gateway'), gateway);
|
|
361
|
+
writeJson(path.join(bundle, 'migration-plan.json'), plan);
|
|
362
|
+
verifyBundle(path.join(bundle, 'device'));
|
|
363
|
+
verifyBundle(path.join(bundle, 'gateway'));
|
|
364
|
+
if (inventory(plan.deviceRoot).sourceDigest !== device.sourceDigest || inventory(plan.gatewayRoot).sourceDigest !== gateway.sourceDigest)
|
|
365
|
+
fail('MIGRATION_PLAN_STALE');
|
|
366
|
+
publish(bundle, plan.backupRoot);
|
|
367
|
+
targetStage = stageFor(plan.targetRoot);
|
|
368
|
+
const target = path.join(targetStage, 'state');
|
|
369
|
+
const combined = { files: [...device.files, ...gateway.files].sort((a, b) => a.path.localeCompare(b.path)),
|
|
370
|
+
directories: [...new Set([...device.directories, ...gateway.directories])].sort(),
|
|
371
|
+
totalBytes: device.totalBytes + gateway.totalBytes, sourceDigest: '' };
|
|
372
|
+
combined.sourceDigest = digest({ files: combined.files.map(({ mode, ...file }) => file), directories: combined.directories, totalBytes: combined.totalBytes });
|
|
373
|
+
mkdirSync(target, { mode: 0o700 });
|
|
374
|
+
for (const directory of combined.directories)
|
|
375
|
+
mkdirSync(path.join(target, ...directory.split('/')), { recursive: true, mode: 0o700 });
|
|
376
|
+
for (const [name, items] of [['device', device], ['gateway', gateway]])
|
|
377
|
+
for (const file of items.files) {
|
|
378
|
+
const destination = path.join(target, ...file.path.split('/'));
|
|
379
|
+
mkdirSync(path.dirname(destination), { recursive: true, mode: 0o700 });
|
|
380
|
+
copyFileSync(path.join(plan.backupRoot, name, 'data', ...file.path.split('/')), destination, constants.COPYFILE_EXCL);
|
|
381
|
+
chmodSync(destination, file.mode);
|
|
382
|
+
flushFile(destination);
|
|
383
|
+
}
|
|
384
|
+
if (inventory(target, { excludeLocks: false, rejectWal: false }).sourceDigest !== combined.sourceDigest)
|
|
385
|
+
fail('MIGRATION_RESTORE_HASH_MISMATCH');
|
|
386
|
+
publish(target, plan.targetRoot);
|
|
387
|
+
return { targetRoot: plan.targetRoot, backupRoot: plan.backupRoot, files: combined.files.length, sourceDigest: combined.sourceDigest,
|
|
388
|
+
rollback: { deviceBackup: path.join(plan.backupRoot, 'device'), gatewayBackup: path.join(plan.backupRoot, 'gateway') } };
|
|
389
|
+
}
|
|
390
|
+
finally {
|
|
391
|
+
if (backupStage)
|
|
392
|
+
rmSync(backupStage, { recursive: true, force: true });
|
|
393
|
+
if (targetStage)
|
|
394
|
+
rmSync(targetStage, { recursive: true, force: true });
|
|
395
|
+
for (const release of releases.reverse())
|
|
396
|
+
await release();
|
|
397
|
+
}
|
|
398
|
+
}));
|
|
399
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/** Small unrelated extension used to exercise the public plugin contract. */
|
|
2
|
+
export function createPlugin(context) {
|
|
3
|
+
return {
|
|
4
|
+
invoke(capability, input) {
|
|
5
|
+
if (capability !== 'text.transform')
|
|
6
|
+
throw Object.assign(new Error('Unsupported capability'), { code: 'CAPABILITY_UNSUPPORTED' });
|
|
7
|
+
const value = input;
|
|
8
|
+
if (typeof value?.text !== 'string' || value.text.length > 8192)
|
|
9
|
+
throw Object.assign(new Error('text must be at most 8192 characters'), { code: 'INVALID_ARGUMENT' });
|
|
10
|
+
return { text: value.mode === 'upper' ? value.text.toUpperCase() : value.mode === 'lower' ? value.text.toLowerCase() : value.text, deviceId: context.deviceId };
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
}
|
package/dist/search-manager.d.ts
CHANGED
|
@@ -51,6 +51,12 @@ export interface SearchSessionOptions {
|
|
|
51
51
|
totalResults: number;
|
|
52
52
|
runtime: number;
|
|
53
53
|
}>;
|
|
54
|
+
searchOnce(options: SearchSessionOptions, maxResults?: number, maxBytes?: number): Promise<{
|
|
55
|
+
results: SearchResult[];
|
|
56
|
+
runtime: number;
|
|
57
|
+
truncated: boolean;
|
|
58
|
+
timedOut: boolean;
|
|
59
|
+
}>;
|
|
54
60
|
/**
|
|
55
61
|
* Read search results with offset-based pagination (like read_file)
|
|
56
62
|
* Supports both range reading and tail behavior
|
package/dist/search-manager.js
CHANGED
|
@@ -142,6 +142,129 @@ import PizZip from 'pizzip';
|
|
|
142
142
|
runtime: Date.now() - session.startTime
|
|
143
143
|
};
|
|
144
144
|
}
|
|
145
|
+
async searchOnce(options, maxResults = 100, maxBytes = 256 * 1024) {
|
|
146
|
+
const startTime = Date.now();
|
|
147
|
+
const validPath = await validatePath(options.rootPath);
|
|
148
|
+
const args = this.buildRipgrepArgs({
|
|
149
|
+
...options,
|
|
150
|
+
rootPath: validPath,
|
|
151
|
+
maxResults: maxResults + 1,
|
|
152
|
+
});
|
|
153
|
+
const rgPath = await getRipgrepPath();
|
|
154
|
+
return new Promise((resolve, reject) => {
|
|
155
|
+
const child = spawn(rgPath, args, { windowsHide: true });
|
|
156
|
+
const results = [];
|
|
157
|
+
const pendingContext = [];
|
|
158
|
+
let buffered = '';
|
|
159
|
+
let capturedBytes = 0;
|
|
160
|
+
let matchCount = 0;
|
|
161
|
+
let truncated = false;
|
|
162
|
+
let timedOut = false;
|
|
163
|
+
let settled = false;
|
|
164
|
+
let timer;
|
|
165
|
+
const stopForTruncation = () => {
|
|
166
|
+
truncated = true;
|
|
167
|
+
if (!child.killed)
|
|
168
|
+
child.kill('SIGTERM');
|
|
169
|
+
};
|
|
170
|
+
const flushPendingContext = (reservedBytes = 0) => {
|
|
171
|
+
let dropped = false;
|
|
172
|
+
for (const item of pendingContext) {
|
|
173
|
+
if (capturedBytes + item.bytes + reservedBytes > maxBytes) {
|
|
174
|
+
dropped = true;
|
|
175
|
+
continue;
|
|
176
|
+
}
|
|
177
|
+
results.push(item.result);
|
|
178
|
+
capturedBytes += item.bytes;
|
|
179
|
+
}
|
|
180
|
+
pendingContext.length = 0;
|
|
181
|
+
return dropped;
|
|
182
|
+
};
|
|
183
|
+
const finish = () => {
|
|
184
|
+
if (settled)
|
|
185
|
+
return;
|
|
186
|
+
if (pendingContext.length > 0 && matchCount > 0) {
|
|
187
|
+
if (flushPendingContext())
|
|
188
|
+
truncated = true;
|
|
189
|
+
}
|
|
190
|
+
settled = true;
|
|
191
|
+
if (timer)
|
|
192
|
+
clearTimeout(timer);
|
|
193
|
+
resolve({
|
|
194
|
+
results,
|
|
195
|
+
runtime: Date.now() - startTime,
|
|
196
|
+
truncated,
|
|
197
|
+
timedOut,
|
|
198
|
+
});
|
|
199
|
+
};
|
|
200
|
+
const fail = (error) => {
|
|
201
|
+
if (settled)
|
|
202
|
+
return;
|
|
203
|
+
settled = true;
|
|
204
|
+
if (timer)
|
|
205
|
+
clearTimeout(timer);
|
|
206
|
+
reject(error);
|
|
207
|
+
};
|
|
208
|
+
const acceptLine = (line) => {
|
|
209
|
+
if (!line.trim() || truncated)
|
|
210
|
+
return;
|
|
211
|
+
const result = this.parseLine(line, options.searchType);
|
|
212
|
+
if (!result)
|
|
213
|
+
return;
|
|
214
|
+
const resultBytes = Buffer.byteLength(`${result.file}\n${result.match ?? ''}\n`, 'utf8');
|
|
215
|
+
const isContext = options.searchType === 'content' && line.includes('"type":"context"');
|
|
216
|
+
if (isContext) {
|
|
217
|
+
pendingContext.push({ result, bytes: resultBytes });
|
|
218
|
+
return;
|
|
219
|
+
}
|
|
220
|
+
if (matchCount >= maxResults) {
|
|
221
|
+
pendingContext.length = 0;
|
|
222
|
+
stopForTruncation();
|
|
223
|
+
return;
|
|
224
|
+
}
|
|
225
|
+
if (capturedBytes + resultBytes > maxBytes) {
|
|
226
|
+
pendingContext.length = 0;
|
|
227
|
+
stopForTruncation();
|
|
228
|
+
return;
|
|
229
|
+
}
|
|
230
|
+
const droppedContext = flushPendingContext(resultBytes);
|
|
231
|
+
results.push(result);
|
|
232
|
+
capturedBytes += resultBytes;
|
|
233
|
+
matchCount++;
|
|
234
|
+
if (droppedContext) {
|
|
235
|
+
stopForTruncation();
|
|
236
|
+
}
|
|
237
|
+
};
|
|
238
|
+
child.stdout?.on('data', (data) => {
|
|
239
|
+
buffered += data.toString();
|
|
240
|
+
const lines = buffered.split(/\r?\n/);
|
|
241
|
+
buffered = lines.pop() ?? '';
|
|
242
|
+
for (const line of lines)
|
|
243
|
+
acceptLine(line);
|
|
244
|
+
});
|
|
245
|
+
let stderr = '';
|
|
246
|
+
child.stderr?.on('data', (data) => {
|
|
247
|
+
stderr += data.toString();
|
|
248
|
+
});
|
|
249
|
+
child.once('error', fail);
|
|
250
|
+
child.once('close', code => {
|
|
251
|
+
if (buffered)
|
|
252
|
+
acceptLine(buffered);
|
|
253
|
+
if (code && code !== 1 && !truncated && !timedOut) {
|
|
254
|
+
fail(new Error(stderr.trim() || `ripgrep exited with code ${code}`));
|
|
255
|
+
return;
|
|
256
|
+
}
|
|
257
|
+
finish();
|
|
258
|
+
});
|
|
259
|
+
const timeoutMs = options.timeout ?? 5000;
|
|
260
|
+
timer = setTimeout(() => {
|
|
261
|
+
timedOut = true;
|
|
262
|
+
truncated = true;
|
|
263
|
+
if (!child.killed)
|
|
264
|
+
child.kill('SIGTERM');
|
|
265
|
+
}, timeoutMs);
|
|
266
|
+
});
|
|
267
|
+
}
|
|
145
268
|
/**
|
|
146
269
|
* Read search results with offset-based pagination (like read_file)
|
|
147
270
|
* Supports both range reading and tail behavior
|
package/dist/server.d.ts
CHANGED
|
@@ -39,8 +39,21 @@ declare let currentClient: {
|
|
|
39
39
|
version: string;
|
|
40
40
|
};
|
|
41
41
|
declare let currentCallIsRemote: boolean;
|
|
42
|
+
/**
|
|
43
|
+
* Set whether the current tool call is from a remote device.
|
|
44
|
+
* Called once per tool call by the CallTool handler.
|
|
45
|
+
*/
|
|
46
|
+
export declare function setCurrentCallIsRemote(isRemote: boolean): void;
|
|
42
47
|
declare let currentRemoteClient: {
|
|
43
48
|
name?: string;
|
|
44
49
|
version?: string;
|
|
45
50
|
} | null;
|
|
51
|
+
/**
|
|
52
|
+
* Set the remote caller's client for the current tool call (null when local).
|
|
53
|
+
* Called once per tool call by the CallTool handler.
|
|
54
|
+
*/
|
|
55
|
+
export declare function setCurrentRemoteClient(clientInfo: {
|
|
56
|
+
name?: string;
|
|
57
|
+
version?: string;
|
|
58
|
+
} | null): void;
|
|
46
59
|
export { currentClient, currentCallIsRemote, currentRemoteClient };
|
package/dist/server.js
CHANGED
|
@@ -17,6 +17,7 @@ import { trackToolCall } from './utils/trackTools.js';
|
|
|
17
17
|
import { usageTracker } from './utils/usageTracker.js';
|
|
18
18
|
import { processDockerPrompt } from './utils/dockerPrompt.js';
|
|
19
19
|
import { toolHistory } from './utils/toolHistory.js';
|
|
20
|
+
import { observePublicInvocation, isCapturingInvocation } from './context/capture.js';
|
|
20
21
|
import { handleWelcomePageOnboarding, skipWelcomePageOnboarding } from './utils/welcome-onboarding.js';
|
|
21
22
|
import { VERSION } from './version.js';
|
|
22
23
|
import { capture, capture_call_tool, runInUiOriginCallContext } from "./utils/capture.js";
|
|
@@ -83,7 +84,7 @@ let currentCallIsRemote = false;
|
|
|
83
84
|
* Set whether the current tool call is from a remote device.
|
|
84
85
|
* Called once per tool call by the CallTool handler.
|
|
85
86
|
*/
|
|
86
|
-
function setCurrentCallIsRemote(isRemote) {
|
|
87
|
+
export function setCurrentCallIsRemote(isRemote) {
|
|
87
88
|
currentCallIsRemote = isRemote;
|
|
88
89
|
}
|
|
89
90
|
// The remote caller's client for the in-flight tool call (e.g. openai-mcp,
|
|
@@ -96,7 +97,7 @@ let currentRemoteClient = null;
|
|
|
96
97
|
* Set the remote caller's client for the current tool call (null when local).
|
|
97
98
|
* Called once per tool call by the CallTool handler.
|
|
98
99
|
*/
|
|
99
|
-
function setCurrentRemoteClient(clientInfo) {
|
|
100
|
+
export function setCurrentRemoteClient(clientInfo) {
|
|
100
101
|
currentRemoteClient = clientInfo;
|
|
101
102
|
}
|
|
102
103
|
/**
|
|
@@ -1097,6 +1098,9 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
|
1097
1098
|
return handleCallToolRequest(request);
|
|
1098
1099
|
});
|
|
1099
1100
|
async function handleCallToolRequest(request) {
|
|
1101
|
+
return observePublicInvocation({ tool: request.params.name, args: request.params.arguments }, () => executeCallToolRequest(request));
|
|
1102
|
+
}
|
|
1103
|
+
async function executeCallToolRequest(request) {
|
|
1100
1104
|
const { name, arguments: args } = request.params;
|
|
1101
1105
|
const startTime = Date.now();
|
|
1102
1106
|
// Hoisted above the try so the finally block can read them when emitting the
|
|
@@ -1336,7 +1340,7 @@ async function handleCallToolRequest(request) {
|
|
|
1336
1340
|
'get_recent_tool_calls',
|
|
1337
1341
|
'track_ui_event'
|
|
1338
1342
|
];
|
|
1339
|
-
if (!currentCallIsRemote && process.env.MCP_DEVICE_REMOTE !== 'true' && !EXCLUDED_TOOLS.includes(name)) {
|
|
1343
|
+
if (!isCapturingInvocation() && !currentCallIsRemote && process.env.MCP_DEVICE_REMOTE !== 'true' && !EXCLUDED_TOOLS.includes(name)) {
|
|
1340
1344
|
toolHistory.addCall(name, args, result, duration);
|
|
1341
1345
|
}
|
|
1342
1346
|
// Track success or failure based on result
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { TerminalSession, CommandExecutionResult, ActiveSession } from './types.js';
|
|
2
2
|
interface CompletedSession {
|
|
3
|
+
executionId: string;
|
|
3
4
|
pid: number;
|
|
4
5
|
outputLines: string[];
|
|
5
6
|
exitCode: number | null;
|
|
@@ -7,6 +8,9 @@ interface CompletedSession {
|
|
|
7
8
|
endTime: Date;
|
|
8
9
|
evictedLines: number;
|
|
9
10
|
evictedChars: number;
|
|
11
|
+
lastReadIndex: number;
|
|
12
|
+
lastReadOffset: number;
|
|
13
|
+
bufferedChars: number;
|
|
10
14
|
}
|
|
11
15
|
/**
|
|
12
16
|
* Output buffering caps. Without a cap, a process emitting enough output makes
|
|
@@ -31,6 +35,12 @@ export interface PaginatedOutputResult {
|
|
|
31
35
|
export declare class TerminalManager {
|
|
32
36
|
private sessions;
|
|
33
37
|
private completedSessions;
|
|
38
|
+
private readonly runtimeGeneration;
|
|
39
|
+
processIdentity(pid: number): {
|
|
40
|
+
execution_id: string;
|
|
41
|
+
runtime_generation: `${string}-${string}-${string}-${string}-${string}`;
|
|
42
|
+
pid: number;
|
|
43
|
+
} | undefined;
|
|
34
44
|
/**
|
|
35
45
|
* Send input to a running process
|
|
36
46
|
* @param pid Process ID
|
|
@@ -43,6 +53,8 @@ export declare class TerminalManager {
|
|
|
43
53
|
* Append text to a session's line buffer
|
|
44
54
|
* Handles partial lines and newline splitting
|
|
45
55
|
*/
|
|
56
|
+
private notifyOutputProgress;
|
|
57
|
+
waitForOutputProgress(pid: number, sinceVersion: number, timeoutMs: number): Promise<void>;
|
|
46
58
|
private appendToLineBuffer;
|
|
47
59
|
/**
|
|
48
60
|
* Read process output with pagination (like file reading)
|
|
@@ -51,6 +63,10 @@ export declare class TerminalManager {
|
|
|
51
63
|
* @param length Max lines to return
|
|
52
64
|
* @param updateReadIndex Whether to update lastReadIndex (default: true for offset=0)
|
|
53
65
|
*/
|
|
66
|
+
markOutputConsumed(pid: number, cursor?: {
|
|
67
|
+
lineIndex: number;
|
|
68
|
+
lineOffset: number;
|
|
69
|
+
}): void;
|
|
54
70
|
readOutputPaginated(pid: number, offset?: number, length?: number): PaginatedOutputResult | null;
|
|
55
71
|
/**
|
|
56
72
|
* Internal helper to read from a line buffer with offset/length
|