@prestyj/cli 5.32.1 → 5.33.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/assets/motion/skills/motion/SKILL.md +1 -1
- package/assets/skills/bulletproof/SKILL.md +72 -131
- package/assets/skills/bulletproof/references/agent-surface.md +22 -1
- package/assets/skills/bulletproof/references/audit-protocol.md +23 -6
- package/assets/skills/bulletproof/references/platform-playbooks.md +12 -0
- package/assets/skills/bulletproof/references/provenance.md +19 -2
- package/assets/skills/bulletproof/references/secure-defaults.md +13 -1
- package/assets/skills/bulletproof/references/supply-chain.md +8 -5
- package/assets/skills/bulletproof/references/threat-landscape.md +46 -57
- package/assets/skills/compliance-guard/SKILL.md +59 -212
- package/assets/skills/compliance-guard/references/artifacts.md +14 -1
- package/assets/skills/compliance-guard/references/eu-uk.md +17 -7
- package/assets/skills/compliance-guard/references/exposure-triage.md +16 -0
- package/assets/skills/compliance-guard/references/full-review.md +155 -0
- package/assets/skills/compliance-guard/references/lawsuit-vectors.md +14 -2
- package/assets/skills/compliance-guard/references/provenance.md +33 -2
- package/assets/skills/compliance-guard/references/sector-gates.md +15 -1
- package/assets/skills/compliance-guard/references/security-baseline.md +21 -34
- package/assets/skills/compliance-guard/references/trigger-map.md +15 -1
- package/assets/skills/compliance-guard/references/us.md +32 -8
- package/assets/skills/durable/SKILL.md +22 -29
- package/assets/skills/durable/references/agent-db-safety.md +2 -2
- package/assets/skills/durable/references/backups-and-runtime.md +6 -6
- package/assets/skills/durable/references/migrations-and-schema.md +5 -4
- package/assets/skills/lean/SKILL.md +36 -50
- package/assets/skills/lean/references/playbooks.md +9 -7
- package/dist/app-sidecar/app-settings.d.ts +5 -0
- package/dist/app-sidecar/app-settings.js +13 -0
- package/dist/app-sidecar/app-settings.js.map +1 -1
- package/dist/app-sidecar/auth-routes.js +45 -2
- package/dist/app-sidecar/auth-routes.js.map +1 -1
- package/dist/app-sidecar/desktop-guidance.d.ts +1 -0
- package/dist/app-sidecar/desktop-guidance.js +27 -0
- package/dist/app-sidecar/desktop-guidance.js.map +1 -0
- package/dist/app-sidecar/history-routes.d.ts +6 -0
- package/dist/app-sidecar/history-routes.js +57 -2
- package/dist/app-sidecar/history-routes.js.map +1 -1
- package/dist/app-sidecar/history.d.ts +17 -0
- package/dist/app-sidecar/history.js.map +1 -1
- package/dist/app-sidecar/http.d.ts +1 -1
- package/dist/app-sidecar/http.js +2 -2
- package/dist/app-sidecar/http.js.map +1 -1
- package/dist/app-sidecar/integration-routes.js +4 -0
- package/dist/app-sidecar/integration-routes.js.map +1 -1
- package/dist/app-sidecar/prompt-routes.js +28 -5
- package/dist/app-sidecar/prompt-routes.js.map +1 -1
- package/dist/app-sidecar/route-context.d.ts +10 -1
- package/dist/app-sidecar/run-control-routes.js +9 -2
- package/dist/app-sidecar/run-control-routes.js.map +1 -1
- package/dist/app-sidecar/session-routes.js +8 -0
- package/dist/app-sidecar/session-routes.js.map +1 -1
- package/dist/app-sidecar/shell-routes.d.ts +12 -0
- package/dist/app-sidecar/shell-routes.js +133 -0
- package/dist/app-sidecar/shell-routes.js.map +1 -0
- package/dist/app-sidecar/shell-runs.d.ts +103 -0
- package/dist/app-sidecar/shell-runs.js +268 -0
- package/dist/app-sidecar/shell-runs.js.map +1 -0
- package/dist/app-sidecar/shell-suggestions.d.ts +33 -0
- package/dist/app-sidecar/shell-suggestions.js +152 -0
- package/dist/app-sidecar/shell-suggestions.js.map +1 -0
- package/dist/app-sidecar/usage.js +26 -2
- package/dist/app-sidecar/usage.js.map +1 -1
- package/dist/app-sidecar-sessions.js +13 -3
- package/dist/app-sidecar-sessions.js.map +1 -1
- package/dist/app-sidecar.js +231 -60
- package/dist/app-sidecar.js.map +1 -1
- package/dist/chat-agents/index.d.ts +1 -1
- package/dist/chat-agents/index.js +1 -1
- package/dist/chat-agents/index.js.map +1 -1
- package/dist/chat-agents/shared.d.ts +4 -0
- package/dist/chat-agents/shared.js +8 -1
- package/dist/chat-agents/shared.js.map +1 -1
- package/dist/cli.js +28 -6
- package/dist/cli.js.map +1 -1
- package/dist/config.d.ts +22 -2
- package/dist/config.js +40 -97
- package/dist/config.js.map +1 -1
- package/dist/core/agent-session.d.ts +102 -11
- package/dist/core/agent-session.js +740 -164
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/ask-user.d.ts +6 -0
- package/dist/core/ask-user.js +20 -5
- package/dist/core/ask-user.js.map +1 -1
- package/dist/core/autopilot-gate.js +2 -3
- package/dist/core/autopilot-gate.js.map +1 -1
- package/dist/core/bundled-agents.js +9 -29
- package/dist/core/bundled-agents.js.map +1 -1
- package/dist/core/cache-diagnostics.d.ts +4 -0
- package/dist/core/cache-diagnostics.js +4 -1
- package/dist/core/cache-diagnostics.js.map +1 -1
- package/dist/core/cache-expiry.d.ts +2 -0
- package/dist/core/cache-expiry.js +6 -0
- package/dist/core/cache-expiry.js.map +1 -1
- package/dist/core/checklist-items.d.ts +0 -8
- package/dist/core/checklist-items.js +0 -8
- package/dist/core/checklist-items.js.map +1 -1
- package/dist/core/checkpoint-store.d.ts +17 -0
- package/dist/core/checkpoint-store.js +72 -0
- package/dist/core/checkpoint-store.js.map +1 -1
- package/dist/core/claude-code/complete.d.ts +33 -0
- package/dist/core/claude-code/complete.js +112 -0
- package/dist/core/claude-code/complete.js.map +1 -0
- package/dist/core/claude-code/events.d.ts +65 -0
- package/dist/core/claude-code/events.js +434 -0
- package/dist/core/claude-code/events.js.map +1 -0
- package/dist/core/claude-code/live-session.d.ts +92 -0
- package/dist/core/claude-code/live-session.js +519 -0
- package/dist/core/claude-code/live-session.js.map +1 -0
- package/dist/core/claude-code/loop.d.ts +9 -0
- package/dist/core/claude-code/loop.js +15 -0
- package/dist/core/claude-code/loop.js.map +1 -0
- package/dist/core/claude-code/session-sync.d.ts +28 -0
- package/dist/core/claude-code/session-sync.js +53 -0
- package/dist/core/claude-code/session-sync.js.map +1 -0
- package/dist/core/claude-code/tool-bridge.d.ts +49 -0
- package/dist/core/claude-code/tool-bridge.js +352 -0
- package/dist/core/claude-code/tool-bridge.js.map +1 -0
- package/dist/core/claude-code-version.d.ts +1 -1
- package/dist/core/claude-code-version.js +1 -1
- package/dist/core/claude-code-version.js.map +1 -1
- package/dist/core/code-retrieval.d.ts +1 -1
- package/dist/core/code-retrieval.js +2 -2
- package/dist/core/code-retrieval.js.map +1 -1
- package/dist/core/compaction/compactor.d.ts +25 -1
- package/dist/core/compaction/compactor.js +137 -7
- package/dist/core/compaction/compactor.js.map +1 -1
- package/dist/core/compaction/policy.d.ts +18 -0
- package/dist/core/compaction/policy.js +24 -5
- package/dist/core/compaction/policy.js.map +1 -1
- package/dist/core/compaction/tool-result-pruner.d.ts +10 -0
- package/dist/core/compaction/tool-result-pruner.js +14 -0
- package/dist/core/compaction/tool-result-pruner.js.map +1 -1
- package/dist/core/env-delta.d.ts +3 -3
- package/dist/core/env-delta.js +4 -5
- package/dist/core/env-delta.js.map +1 -1
- package/dist/core/goals-store.d.ts +9 -0
- package/dist/core/goals-store.js +111 -50
- package/dist/core/goals-store.js.map +1 -1
- package/dist/core/internal-diagnostics.d.ts +17 -0
- package/dist/core/internal-diagnostics.js +45 -0
- package/dist/core/internal-diagnostics.js.map +1 -1
- package/dist/core/language-detector.d.ts +2 -3
- package/dist/core/language-detector.js.map +1 -1
- package/dist/core/local-endpoint-store.d.ts +4 -0
- package/dist/core/local-endpoint-store.js +31 -15
- package/dist/core/local-endpoint-store.js.map +1 -1
- package/dist/core/logger.d.ts +5 -0
- package/dist/core/logger.js +10 -2
- package/dist/core/logger.js.map +1 -1
- package/dist/core/lsp/edit-telemetry.js +3 -1
- package/dist/core/lsp/edit-telemetry.js.map +1 -1
- package/dist/core/lsp/manager.d.ts +15 -0
- package/dist/core/lsp/manager.js +31 -0
- package/dist/core/lsp/manager.js.map +1 -1
- package/dist/core/mcp/deferred-catalog.d.ts +1 -1
- package/dist/core/mcp/deferred-catalog.js +1 -1
- package/dist/core/openrouter-catalog-store.d.ts +24 -0
- package/dist/core/openrouter-catalog-store.js +140 -0
- package/dist/core/openrouter-catalog-store.js.map +1 -0
- package/dist/core/plan-delta.d.ts +23 -0
- package/dist/core/plan-delta.js +36 -0
- package/dist/core/plan-delta.js.map +1 -0
- package/dist/core/process-gate.d.ts +17 -0
- package/dist/core/process-gate.js +24 -0
- package/dist/core/process-gate.js.map +1 -1
- package/dist/core/project-discovery.js +2 -2
- package/dist/core/project-discovery.js.map +1 -1
- package/dist/core/project-files.d.ts +15 -0
- package/dist/core/project-files.js +37 -0
- package/dist/core/project-files.js.map +1 -0
- package/dist/core/prompt-commands.js +41 -75
- package/dist/core/prompt-commands.js.map +1 -1
- package/dist/core/radio-players.d.ts +28 -0
- package/dist/core/radio-players.js +133 -0
- package/dist/core/radio-players.js.map +1 -0
- package/dist/core/radio.js +20 -3
- package/dist/core/radio.js.map +1 -1
- package/dist/core/runtime-mode.d.ts +9 -0
- package/dist/core/runtime-mode.js +26 -0
- package/dist/core/runtime-mode.js.map +1 -1
- package/dist/core/session-history.d.ts +7 -0
- package/dist/core/session-history.js +34 -2
- package/dist/core/session-history.js.map +1 -1
- package/dist/core/session-manager.d.ts +5 -1
- package/dist/core/session-manager.js +36 -7
- package/dist/core/session-manager.js.map +1 -1
- package/dist/core/session-preview.js +2 -2
- package/dist/core/session-preview.js.map +1 -1
- package/dist/core/session-summary-index.d.ts +18 -4
- package/dist/core/session-summary-index.js +28 -8
- package/dist/core/session-summary-index.js.map +1 -1
- package/dist/core/settings-manager.d.ts +7 -0
- package/dist/core/settings-manager.js +53 -7
- package/dist/core/settings-manager.js.map +1 -1
- package/dist/core/shell.d.ts +4 -0
- package/dist/core/shell.js +15 -1
- package/dist/core/shell.js.map +1 -1
- package/dist/core/skills.d.ts +8 -0
- package/dist/core/skills.js +15 -5
- package/dist/core/skills.js.map +1 -1
- package/dist/core/steering.d.ts +4 -0
- package/dist/core/steering.js +8 -1
- package/dist/core/steering.js.map +1 -1
- package/dist/core/stream-diag-level.d.ts +3 -0
- package/dist/core/stream-diag-level.js +24 -0
- package/dist/core/stream-diag-level.js.map +1 -0
- package/dist/core/subagent-manager.d.ts +11 -0
- package/dist/core/subagent-manager.js +16 -4
- package/dist/core/subagent-manager.js.map +1 -1
- package/dist/core/subagent-policy.d.ts +6 -0
- package/dist/core/subagent-policy.js +22 -3
- package/dist/core/subagent-policy.js.map +1 -1
- package/dist/core/subagent-receipt.d.ts +3 -3
- package/dist/core/subagent-receipt.js +6 -9
- package/dist/core/subagent-receipt.js.map +1 -1
- package/dist/core/threat-feed.js +10 -4
- package/dist/core/threat-feed.js.map +1 -1
- package/dist/core/trophies/catalog-more.js +16 -36
- package/dist/core/trophies/catalog-more.js.map +1 -1
- package/dist/core/trophies/engine.js +0 -4
- package/dist/core/trophies/engine.js.map +1 -1
- package/dist/core/trophies/types.d.ts +1 -1
- package/dist/core/trophies/types.js +0 -2
- package/dist/core/trophies/types.js.map +1 -1
- package/dist/core/user-shell-context.d.ts +8 -0
- package/dist/core/user-shell-context.js +12 -0
- package/dist/core/user-shell-context.js.map +1 -0
- package/dist/core/verify-commands.d.ts +1 -1
- package/dist/goals-agent/goal-team.js +3 -4
- package/dist/goals-agent/goal-team.js.map +1 -1
- package/dist/goals-agent/goals-agent.d.ts +1 -1
- package/dist/goals-agent/goals-agent.js +4 -3
- package/dist/goals-agent/goals-agent.js.map +1 -1
- package/dist/modes/acp-mode.d.ts +1 -1
- package/dist/modes/acp-mode.js +4 -5
- package/dist/modes/acp-mode.js.map +1 -1
- package/dist/modes/agent-home-mode.js +5 -5
- package/dist/modes/agent-home-mode.js.map +1 -1
- package/dist/modes/json-mode.js +5 -0
- package/dist/modes/json-mode.js.map +1 -1
- package/dist/modes/serve-mode.js +5 -5
- package/dist/modes/serve-mode.js.map +1 -1
- package/dist/motion-agent/motion-agent.d.ts +12 -5
- package/dist/motion-agent/motion-agent.js +24 -9
- package/dist/motion-agent/motion-agent.js.map +1 -1
- package/dist/subagent-entry.d.ts +1 -0
- package/dist/subagent-entry.js +50 -0
- package/dist/subagent-entry.js.map +1 -0
- package/dist/system-prompt.d.ts +13 -3
- package/dist/system-prompt.js +47 -21
- package/dist/system-prompt.js.map +1 -1
- package/dist/tools/ask-user.js +3 -2
- package/dist/tools/ask-user.js.map +1 -1
- package/dist/tools/bash.d.ts +7 -0
- package/dist/tools/bash.js +26 -8
- package/dist/tools/bash.js.map +1 -1
- package/dist/tools/checklist.js +6 -11
- package/dist/tools/checklist.js.map +1 -1
- package/dist/tools/debug.js +6 -9
- package/dist/tools/debug.js.map +1 -1
- package/dist/tools/document-text.d.ts +6 -0
- package/dist/tools/document-text.js +154 -0
- package/dist/tools/document-text.js.map +1 -0
- package/dist/tools/enter-plan.js +4 -7
- package/dist/tools/enter-plan.js.map +1 -1
- package/dist/tools/find.d.ts +9 -0
- package/dist/tools/find.js +38 -1
- package/dist/tools/find.js.map +1 -1
- package/dist/tools/generate-image.d.ts +18 -0
- package/dist/tools/generate-image.js +208 -17
- package/dist/tools/generate-image.js.map +1 -1
- package/dist/tools/goals.d.ts +2 -2
- package/dist/tools/index.d.ts +5 -2
- package/dist/tools/index.js +5 -13
- package/dist/tools/index.js.map +1 -1
- package/dist/tools/operations.js +1 -1
- package/dist/tools/operations.js.map +1 -1
- package/dist/tools/overflow.d.ts +2 -0
- package/dist/tools/overflow.js +10 -0
- package/dist/tools/overflow.js.map +1 -1
- package/dist/tools/prompt-hints.d.ts +10 -1
- package/dist/tools/prompt-hints.js +38 -11
- package/dist/tools/prompt-hints.js.map +1 -1
- package/dist/tools/read.js +25 -10
- package/dist/tools/read.js.map +1 -1
- package/dist/tools/routine-output.d.ts +39 -0
- package/dist/tools/routine-output.js +281 -0
- package/dist/tools/routine-output.js.map +1 -0
- package/dist/tools/screenshot.js +6 -10
- package/dist/tools/screenshot.js.map +1 -1
- package/dist/tools/side-web-search.d.ts +35 -0
- package/dist/tools/side-web-search.js +147 -0
- package/dist/tools/side-web-search.js.map +1 -0
- package/dist/tools/skill.d.ts +2 -0
- package/dist/tools/skill.js +33 -6
- package/dist/tools/skill.js.map +1 -1
- package/dist/tools/steroids.d.ts +7 -6
- package/dist/tools/steroids.js +193 -87
- package/dist/tools/steroids.js.map +1 -1
- package/dist/tools/subagent-control.js +66 -10
- package/dist/tools/subagent-control.js.map +1 -1
- package/dist/tools/subagent-shared.d.ts +19 -2
- package/dist/tools/subagent-shared.js +35 -10
- package/dist/tools/subagent-shared.js.map +1 -1
- package/dist/tools/subagent.js +23 -7
- package/dist/tools/subagent.js.map +1 -1
- package/dist/tools/tool-search.js +7 -1
- package/dist/tools/tool-search.js.map +1 -1
- package/dist/tools/tool-tiers.d.ts +3 -2
- package/dist/tools/tool-tiers.js +7 -5
- package/dist/tools/tool-tiers.js.map +1 -1
- package/dist/tools/truncate.js +4 -8
- package/dist/tools/truncate.js.map +1 -1
- package/dist/tools/web-fetch.d.ts +8 -0
- package/dist/tools/web-fetch.js +123 -17
- package/dist/tools/web-fetch.js.map +1 -1
- package/dist/tools/web-search.d.ts +3 -2
- package/dist/tools/web-search.js +25 -1
- package/dist/tools/web-search.js.map +1 -1
- package/dist/ui/App.js +37 -37
- package/dist/ui/App.js.map +1 -1
- package/dist/ui/components/Footer.js +4 -1
- package/dist/ui/components/Footer.js.map +1 -1
- package/dist/ui/components/SkillsOverlay.js +2 -1
- package/dist/ui/components/SkillsOverlay.js.map +1 -1
- package/dist/ui/hooks/useAgentLoop.d.ts +3 -0
- package/dist/ui/hooks/useAgentLoop.js +54 -4
- package/dist/ui/hooks/useAgentLoop.js.map +1 -1
- package/dist/ui/hooks/useContextCompaction.js +1 -0
- package/dist/ui/hooks/useContextCompaction.js.map +1 -1
- package/dist/ui/language-pack-update.d.ts +25 -0
- package/dist/ui/language-pack-update.js +19 -0
- package/dist/ui/language-pack-update.js.map +1 -0
- package/dist/ui/terminal-history.js +3 -1
- package/dist/ui/terminal-history.js.map +1 -1
- package/dist/utils/http-body.d.ts +5 -0
- package/dist/utils/http-body.js +5 -0
- package/dist/utils/http-body.js.map +1 -1
- package/dist/utils/image.d.ts +11 -0
- package/dist/utils/image.js +34 -1
- package/dist/utils/image.js.map +1 -1
- package/dist/utils/plan-steps.d.ts +1 -0
- package/dist/utils/plan-steps.js +10 -0
- package/dist/utils/plan-steps.js.map +1 -1
- package/dist/utils/prompt-enhancer.d.ts +3 -1
- package/dist/utils/prompt-enhancer.js +21 -16
- package/dist/utils/prompt-enhancer.js.map +1 -1
- package/package.json +23 -6
- package/assets/skills/clarify/SKILL.md +0 -39
- package/assets/skills/code-review/SKILL.md +0 -88
- package/assets/skills/code-review/references/agent-diffs.md +0 -27
- package/assets/skills/code-review/references/tests.md +0 -19
- package/assets/skills/evidence-led-ui/LICENSES.md +0 -80
- package/assets/skills/evidence-led-ui/SKILL.md +0 -100
- package/assets/skills/evidence-led-ui/corpus/awesome-design-md/LICENSE +0 -21
- package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/airbnb/DESIGN.md +0 -545
- package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/airtable/DESIGN.md +0 -554
- package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/apple/DESIGN.md +0 -562
- package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/binance/DESIGN.md +0 -634
- package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/bmw/DESIGN.md +0 -544
- package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/bmw-m/DESIGN.md +0 -503
- package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/bugatti/DESIGN.md +0 -454
- package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/cal/DESIGN.md +0 -542
- package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/claude/DESIGN.md +0 -589
- package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/clay/DESIGN.md +0 -541
- package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/clickhouse/DESIGN.md +0 -544
- package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/cohere/DESIGN.md +0 -451
- package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/coinbase/DESIGN.md +0 -570
- package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/composio/DESIGN.md +0 -506
- package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/cursor/DESIGN.md +0 -537
- package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/dell-1996/DESIGN.md +0 -632
- package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/elevenlabs/DESIGN.md +0 -504
- package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/expo/DESIGN.md +0 -526
- package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/ferrari/DESIGN.md +0 -531
- package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/figma/DESIGN.md +0 -578
- package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/framer/DESIGN.md +0 -544
- package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/hashicorp/DESIGN.md +0 -575
- package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/hp/DESIGN.md +0 -670
- package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/ibm/DESIGN.md +0 -550
- package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/intercom/DESIGN.md +0 -546
- package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/kraken/DESIGN.md +0 -125
- package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/lamborghini/DESIGN.md +0 -288
- package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/linear.app/DESIGN.md +0 -548
- package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/lovable/DESIGN.md +0 -298
- package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/mastercard/DESIGN.md +0 -365
- package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/meta/DESIGN.md +0 -683
- package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/minimax/DESIGN.md +0 -746
- package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/mintlify/DESIGN.md +0 -852
- package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/miro/DESIGN.md +0 -825
- package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/mistral.ai/DESIGN.md +0 -773
- package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/mongodb/DESIGN.md +0 -767
- package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/nike/DESIGN.md +0 -575
- package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/nintendo-2001/DESIGN.md +0 -649
- package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/notion/DESIGN.md +0 -821
- package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/nvidia/DESIGN.md +0 -640
- package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/ollama/DESIGN.md +0 -539
- package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/opencode.ai/DESIGN.md +0 -521
- package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/pinterest/DESIGN.md +0 -597
- package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/playstation/DESIGN.md +0 -661
- package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/posthog/DESIGN.md +0 -690
- package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/raycast/DESIGN.md +0 -669
- package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/renault/DESIGN.md +0 -589
- package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/replicate/DESIGN.md +0 -616
- package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/resend/DESIGN.md +0 -585
- package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/revolut/DESIGN.md +0 -636
- package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/runwayml/DESIGN.md +0 -244
- package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/sanity/DESIGN.md +0 -357
- package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/sentry/DESIGN.md +0 -551
- package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/shopify/DESIGN.md +0 -516
- package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/slack/DESIGN.md +0 -482
- package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/spacex/DESIGN.md +0 -363
- package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/spotify/DESIGN.md +0 -246
- package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/starbucks/DESIGN.md +0 -580
- package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/stripe/DESIGN.md +0 -487
- package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/supabase/DESIGN.md +0 -462
- package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/superhuman/DESIGN.md +0 -448
- package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/tesla/DESIGN.md +0 -286
- package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/theverge/DESIGN.md +0 -339
- package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/together.ai/DESIGN.md +0 -633
- package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/uber/DESIGN.md +0 -636
- package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/vercel/DESIGN.md +0 -736
- package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/vodafone/DESIGN.md +0 -538
- package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/voltagent/DESIGN.md +0 -521
- package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/warp/DESIGN.md +0 -526
- package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/webflow/DESIGN.md +0 -588
- package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/wired/DESIGN.md +0 -497
- package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/wise/DESIGN.md +0 -544
- package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/x.ai/DESIGN.md +0 -465
- package/assets/skills/evidence-led-ui/corpus/awesome-design-md/design-md/zapier/DESIGN.md +0 -537
- package/assets/skills/evidence-led-ui/data/corpus-manifest.json +0 -768
- package/assets/skills/evidence-led-ui/data/observations.json +0 -47053
- package/assets/skills/evidence-led-ui/references/anti-defaults.md +0 -110
- package/assets/skills/evidence-led-ui/references/archetypes.md +0 -97
- package/assets/skills/evidence-led-ui/references/craft-rulings.md +0 -242
- package/assets/skills/evidence-led-ui/references/direction.md +0 -124
- package/assets/skills/evidence-led-ui/references/methodology.md +0 -72
- package/assets/skills/evidence-led-ui/references/observed-patterns.md +0 -68
- package/assets/skills/evidence-led-ui/references/production-contract.md +0 -148
- package/assets/skills/evidence-led-ui/references/provenance.md +0 -142
- package/assets/skills/evidence-led-ui/references/quality-rubric.md +0 -126
- package/assets/skills/evidence-led-ui/references/ui-libraries.md +0 -30
- package/assets/skills/refactoring/SKILL.md +0 -87
- package/assets/skills/refactoring/references/agent-pitfalls.md +0 -46
- package/assets/skills/refactoring/references/legacy.md +0 -70
- package/assets/skills/refactoring/references/smells.md +0 -71
- package/assets/skills/root-cause/SKILL.md +0 -46
- package/assets/skills/shared-language/SKILL.md +0 -32
- package/assets/skills/tdd/SKILL.md +0 -42
- package/dist/core/setup-history.d.ts +0 -6
- package/dist/core/setup-history.js +0 -55
- package/dist/core/setup-history.js.map +0 -1
- package/dist/core/style-packs/index.d.ts +0 -18
- package/dist/core/style-packs/index.js +0 -60
- package/dist/core/style-packs/index.js.map +0 -1
- package/dist/core/style-packs/packs.d.ts +0 -8
- package/dist/core/style-packs/packs.js +0 -188
- package/dist/core/style-packs/packs.js.map +0 -1
- package/dist/interactive.d.ts +0 -2
- package/dist/interactive.js +0 -257
- package/dist/interactive.js.map +0 -1
- package/dist/motion-agent/motion-review-coverage.d.ts +0 -12
- package/dist/motion-agent/motion-review-coverage.js +0 -33
- package/dist/motion-agent/motion-review-coverage.js.map +0 -1
- package/dist/motion-agent/motion-review-session.d.ts +0 -65
- package/dist/motion-agent/motion-review-session.js +0 -422
- package/dist/motion-agent/motion-review-session.js.map +0 -1
- package/dist/tools/code-nav.d.ts +0 -29
- package/dist/tools/code-nav.js +0 -299
- package/dist/tools/code-nav.js.map +0 -1
- package/dist/tools/code-skeleton.d.ts +0 -28
- package/dist/tools/code-skeleton.js +0 -115
- package/dist/tools/code-skeleton.js.map +0 -1
- package/dist/tools/search-code.d.ts +0 -10
- package/dist/tools/search-code.js +0 -90
- package/dist/tools/search-code.js.map +0 -1
- package/dist/ui/stores/index.d.ts +0 -2
- package/dist/ui/stores/index.js +0 -3
- package/dist/ui/stores/index.js.map +0 -1
- package/dist/utils/format.d.ts +0 -16
- package/dist/utils/format.js +0 -159
- package/dist/utils/format.js.map +0 -1
- package/dist/utils/shell.d.ts +0 -2
- package/dist/utils/shell.js +0 -8
- package/dist/utils/shell.js.map +0 -1
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { type ChildProcess, type SpawnOptions } from "node:child_process";
|
|
2
|
+
/**
|
|
3
|
+
* Commands the user runs themselves from the app's input (`!git status`).
|
|
4
|
+
*
|
|
5
|
+
* Not the agent's bash tool: no sandbox, no guards, no timeout. These run with
|
|
6
|
+
* the user's own shell, environment and permissions in the project folder,
|
|
7
|
+
* exactly as if typed in a terminal, and only ever because the user submitted
|
|
8
|
+
* them (see shell-routes.ts for the confirmation gate).
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* Error output (stderr) is wrapped in these private-use characters in the
|
|
12
|
+
* window's copy of the output, so it can be shown differently while keeping
|
|
13
|
+
* its place among normal output. The agent's copy never contains them. The
|
|
14
|
+
* app (ShellBlock.tsx) uses the same two characters.
|
|
15
|
+
*/
|
|
16
|
+
export declare const STDERR_START = "\uE000";
|
|
17
|
+
export declare const STDERR_END = "\uE001";
|
|
18
|
+
export declare function stripStderrMarks(text: string): string;
|
|
19
|
+
/** A cut that starts inside error output reopens it, so the first lines keep their look. */
|
|
20
|
+
export declare function reopenStderr(text: string): string;
|
|
21
|
+
/** Output streamed to the window per command; the rest is summarised. */
|
|
22
|
+
export declare const SHELL_DISPLAY_MAX_CHARS = 1000000;
|
|
23
|
+
/** What the agent (and the saved transcript) gets: the end, where results are. */
|
|
24
|
+
export declare const SHELL_CONTEXT_MAX_LINES = 200;
|
|
25
|
+
export declare const SHELL_CONTEXT_MAX_CHARS = 16000;
|
|
26
|
+
export declare const SHELL_COMMAND_MAX_CHARS = 8000;
|
|
27
|
+
export interface ShellRunEnd {
|
|
28
|
+
runId: string;
|
|
29
|
+
command: string;
|
|
30
|
+
cwd: string;
|
|
31
|
+
exitCode: number | null;
|
|
32
|
+
signal: string | null;
|
|
33
|
+
durationMs: number;
|
|
34
|
+
/** Stopped by the user. */
|
|
35
|
+
cancelled: boolean;
|
|
36
|
+
/** The last lines of output (redacted, plain text), for the agent. */
|
|
37
|
+
tail: string;
|
|
38
|
+
/** The same lines with error output marked, for the saved row. */
|
|
39
|
+
displayTail: string;
|
|
40
|
+
/** True when `tail` is not the whole output. */
|
|
41
|
+
tailTruncated: boolean;
|
|
42
|
+
/** True when the window stopped receiving output partway. */
|
|
43
|
+
displayTruncated: boolean;
|
|
44
|
+
/** The shell itself could not start. */
|
|
45
|
+
error?: string;
|
|
46
|
+
}
|
|
47
|
+
export type ParsedShellRun = {
|
|
48
|
+
ok: true;
|
|
49
|
+
runId: string;
|
|
50
|
+
command: string;
|
|
51
|
+
confirmed: boolean;
|
|
52
|
+
} | {
|
|
53
|
+
ok: false;
|
|
54
|
+
error: string;
|
|
55
|
+
};
|
|
56
|
+
export declare function parseShellRunBody(raw: string): ParsedShellRun;
|
|
57
|
+
/** The user's own environment, minus the app's private daemon variables. */
|
|
58
|
+
export declare function userShellEnv(env: NodeJS.ProcessEnv): Record<string, string>;
|
|
59
|
+
/**
|
|
60
|
+
* The user's login shell ($SHELL) where there is one, so their usual shell
|
|
61
|
+
* syntax works; otherwise the same shell the agent uses (Git Bash or cmd on
|
|
62
|
+
* Windows).
|
|
63
|
+
*/
|
|
64
|
+
export declare function userShellLaunch(command: string, opts?: {
|
|
65
|
+
platform?: NodeJS.Platform;
|
|
66
|
+
env?: NodeJS.ProcessEnv;
|
|
67
|
+
}): {
|
|
68
|
+
file: string;
|
|
69
|
+
args: string[];
|
|
70
|
+
};
|
|
71
|
+
/** The last `maxLines` lines, capped to `maxChars`, and whether anything was cut. */
|
|
72
|
+
export declare function tailOutput(text: string, maxLines?: number, maxChars?: number): {
|
|
73
|
+
text: string;
|
|
74
|
+
truncated: boolean;
|
|
75
|
+
};
|
|
76
|
+
/** One command, as the agent reads it. */
|
|
77
|
+
export declare function formatShellContext(run: ShellRunEnd): string;
|
|
78
|
+
export interface ShellRunnerOptions {
|
|
79
|
+
/** Window frames: shell_output { id, chunk }. */
|
|
80
|
+
emit: (type: string, data: unknown) => void;
|
|
81
|
+
onEnd: (run: ShellRunEnd) => void;
|
|
82
|
+
spawn?: (file: string, args: string[], options: SpawnOptions) => ChildProcess;
|
|
83
|
+
env?: NodeJS.ProcessEnv;
|
|
84
|
+
platform?: NodeJS.Platform;
|
|
85
|
+
now?: () => number;
|
|
86
|
+
}
|
|
87
|
+
/** The user's commands for one window session. */
|
|
88
|
+
export declare class ShellRunner {
|
|
89
|
+
private readonly opts;
|
|
90
|
+
private readonly runs;
|
|
91
|
+
constructor(opts: ShellRunnerOptions);
|
|
92
|
+
isRunning(runId: string): boolean;
|
|
93
|
+
start(runId: string, command: string, cwd: string): {
|
|
94
|
+
ok: true;
|
|
95
|
+
} | {
|
|
96
|
+
ok: false;
|
|
97
|
+
error: string;
|
|
98
|
+
};
|
|
99
|
+
/** Stop one command and everything it started. False when it isn't running. */
|
|
100
|
+
cancel(runId: string): boolean;
|
|
101
|
+
/** Window closing: stop every command still running. */
|
|
102
|
+
stopAll(): void;
|
|
103
|
+
}
|
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
import { spawn as nodeSpawn } from "node:child_process";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { StringDecoder } from "node:string_decoder";
|
|
4
|
+
import { environmentSecrets, redactText } from "@prestyj/ai";
|
|
5
|
+
import { resolveShell } from "../core/shell.js";
|
|
6
|
+
import { killProcessTree } from "../utils/process.js";
|
|
7
|
+
/**
|
|
8
|
+
* Commands the user runs themselves from the app's input (`!git status`).
|
|
9
|
+
*
|
|
10
|
+
* Not the agent's bash tool: no sandbox, no guards, no timeout. These run with
|
|
11
|
+
* the user's own shell, environment and permissions in the project folder,
|
|
12
|
+
* exactly as if typed in a terminal, and only ever because the user submitted
|
|
13
|
+
* them (see shell-routes.ts for the confirmation gate).
|
|
14
|
+
*/
|
|
15
|
+
/**
|
|
16
|
+
* Error output (stderr) is wrapped in these private-use characters in the
|
|
17
|
+
* window's copy of the output, so it can be shown differently while keeping
|
|
18
|
+
* its place among normal output. The agent's copy never contains them. The
|
|
19
|
+
* app (ShellBlock.tsx) uses the same two characters.
|
|
20
|
+
*/
|
|
21
|
+
export const STDERR_START = "\uE000";
|
|
22
|
+
export const STDERR_END = "\uE001";
|
|
23
|
+
const STDERR_MARKS = /[\uE000\uE001]/g;
|
|
24
|
+
export function stripStderrMarks(text) {
|
|
25
|
+
return text.replace(STDERR_MARKS, "");
|
|
26
|
+
}
|
|
27
|
+
/** A cut that starts inside error output reopens it, so the first lines keep their look. */
|
|
28
|
+
export function reopenStderr(text) {
|
|
29
|
+
const end = text.indexOf(STDERR_END);
|
|
30
|
+
const start = text.indexOf(STDERR_START);
|
|
31
|
+
return end !== -1 && (start === -1 || end < start) ? STDERR_START + text : text;
|
|
32
|
+
}
|
|
33
|
+
/** Output streamed to the window per command; the rest is summarised. */
|
|
34
|
+
export const SHELL_DISPLAY_MAX_CHARS = 1_000_000;
|
|
35
|
+
/** What the agent (and the saved transcript) gets: the end, where results are. */
|
|
36
|
+
export const SHELL_CONTEXT_MAX_LINES = 200;
|
|
37
|
+
export const SHELL_CONTEXT_MAX_CHARS = 16_000;
|
|
38
|
+
export const SHELL_COMMAND_MAX_CHARS = 8_000;
|
|
39
|
+
/** Batch chunks into one window frame at most this often. */
|
|
40
|
+
const FLUSH_MS = 50;
|
|
41
|
+
/** After the shell exits, how long leftover children may hold its output pipes. */
|
|
42
|
+
const LEFTOVER_GRACE_MS = 1_000;
|
|
43
|
+
const RUN_ID = /^[A-Za-z0-9_-]{1,64}$/;
|
|
44
|
+
export function parseShellRunBody(raw) {
|
|
45
|
+
let body;
|
|
46
|
+
try {
|
|
47
|
+
body = JSON.parse(raw);
|
|
48
|
+
}
|
|
49
|
+
catch {
|
|
50
|
+
return { ok: false, error: "invalid JSON body" };
|
|
51
|
+
}
|
|
52
|
+
if (typeof body !== "object" || body === null)
|
|
53
|
+
return { ok: false, error: "invalid body" };
|
|
54
|
+
const { id, command, confirmed } = body;
|
|
55
|
+
if (typeof id !== "string" || !RUN_ID.test(id))
|
|
56
|
+
return { ok: false, error: "invalid run id" };
|
|
57
|
+
if (typeof command !== "string" || !command.trim())
|
|
58
|
+
return { ok: false, error: "empty command" };
|
|
59
|
+
if (command.length > SHELL_COMMAND_MAX_CHARS)
|
|
60
|
+
return { ok: false, error: "command too long" };
|
|
61
|
+
return { ok: true, runId: id, command: command.trim(), confirmed: confirmed === true };
|
|
62
|
+
}
|
|
63
|
+
/** The user's own environment, minus the app's private daemon variables. */
|
|
64
|
+
export function userShellEnv(env) {
|
|
65
|
+
const out = {};
|
|
66
|
+
for (const [key, value] of Object.entries(env)) {
|
|
67
|
+
if (value === undefined || key.startsWith("GG_APP_"))
|
|
68
|
+
continue;
|
|
69
|
+
out[key] = value;
|
|
70
|
+
}
|
|
71
|
+
// Output goes to a panel, not a terminal: ask tools for plain text.
|
|
72
|
+
out.TERM = "dumb";
|
|
73
|
+
return out;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* The user's login shell ($SHELL) where there is one, so their usual shell
|
|
77
|
+
* syntax works; otherwise the same shell the agent uses (Git Bash or cmd on
|
|
78
|
+
* Windows).
|
|
79
|
+
*/
|
|
80
|
+
export function userShellLaunch(command, opts = {}) {
|
|
81
|
+
const platform = opts.platform ?? process.platform;
|
|
82
|
+
const env = opts.env ?? process.env;
|
|
83
|
+
const login = env.SHELL?.trim();
|
|
84
|
+
if (platform !== "win32" && login && path.isAbsolute(login)) {
|
|
85
|
+
return { file: login, args: ["-c", command] };
|
|
86
|
+
}
|
|
87
|
+
const shell = resolveShell(command, { platform, env });
|
|
88
|
+
return { file: shell.file, args: shell.args };
|
|
89
|
+
}
|
|
90
|
+
/** The last `maxLines` lines, capped to `maxChars`, and whether anything was cut. */
|
|
91
|
+
export function tailOutput(text, maxLines = SHELL_CONTEXT_MAX_LINES, maxChars = SHELL_CONTEXT_MAX_CHARS) {
|
|
92
|
+
const trimmed = text.replace(/\s+$/, "");
|
|
93
|
+
let start = trimmed.length;
|
|
94
|
+
let lines = 0;
|
|
95
|
+
while (start > 0 && lines < maxLines) {
|
|
96
|
+
const nl = trimmed.lastIndexOf("\n", start - 1);
|
|
97
|
+
start = nl === -1 ? 0 : nl;
|
|
98
|
+
lines++;
|
|
99
|
+
if (nl === -1)
|
|
100
|
+
break;
|
|
101
|
+
}
|
|
102
|
+
let out = trimmed.slice(start === 0 ? 0 : start + 1);
|
|
103
|
+
let truncated = start > 0;
|
|
104
|
+
if (out.length > maxChars) {
|
|
105
|
+
out = out.slice(out.length - maxChars);
|
|
106
|
+
const nl = out.indexOf("\n");
|
|
107
|
+
if (nl !== -1 && nl < out.length - 1)
|
|
108
|
+
out = out.slice(nl + 1);
|
|
109
|
+
truncated = true;
|
|
110
|
+
}
|
|
111
|
+
return { text: out, truncated };
|
|
112
|
+
}
|
|
113
|
+
function seconds(ms) {
|
|
114
|
+
return ms < 10_000 ? `${(ms / 1000).toFixed(1)}s` : `${Math.round(ms / 1000)}s`;
|
|
115
|
+
}
|
|
116
|
+
/** One command, as the agent reads it. */
|
|
117
|
+
export function formatShellContext(run) {
|
|
118
|
+
const facts = [
|
|
119
|
+
`in ${run.cwd}`,
|
|
120
|
+
run.error
|
|
121
|
+
? `failed to start: ${run.error}`
|
|
122
|
+
: run.cancelled
|
|
123
|
+
? "stopped by the user before it finished"
|
|
124
|
+
: `exit code ${run.exitCode ?? run.signal ?? "unknown"}`,
|
|
125
|
+
seconds(run.durationMs),
|
|
126
|
+
];
|
|
127
|
+
if (run.tailTruncated)
|
|
128
|
+
facts.push(`showing the last ${SHELL_CONTEXT_MAX_LINES} lines or fewer`);
|
|
129
|
+
const output = run.tail ? run.tail : "(no output)";
|
|
130
|
+
return `$ ${run.command}\n(${facts.join(", ")})\n${output}`;
|
|
131
|
+
}
|
|
132
|
+
/** The user's commands for one window session. */
|
|
133
|
+
export class ShellRunner {
|
|
134
|
+
opts;
|
|
135
|
+
runs = new Map();
|
|
136
|
+
constructor(opts) {
|
|
137
|
+
this.opts = opts;
|
|
138
|
+
}
|
|
139
|
+
isRunning(runId) {
|
|
140
|
+
return this.runs.has(runId);
|
|
141
|
+
}
|
|
142
|
+
start(runId, command, cwd) {
|
|
143
|
+
if (this.runs.has(runId))
|
|
144
|
+
return { ok: false, error: "run id already in use" };
|
|
145
|
+
const env = this.opts.env ?? process.env;
|
|
146
|
+
const now = this.opts.now ?? Date.now;
|
|
147
|
+
const startedAt = now();
|
|
148
|
+
const launch = userShellLaunch(command, { platform: this.opts.platform, env });
|
|
149
|
+
const secrets = environmentSecrets(env);
|
|
150
|
+
let child;
|
|
151
|
+
try {
|
|
152
|
+
child = (this.opts.spawn ?? nodeSpawn)(launch.file, launch.args, {
|
|
153
|
+
cwd,
|
|
154
|
+
env: userShellEnv(env),
|
|
155
|
+
// Own process group, so Stop ends everything the command started.
|
|
156
|
+
detached: process.platform !== "win32",
|
|
157
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
158
|
+
windowsHide: true,
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
catch (err) {
|
|
162
|
+
return { ok: false, error: err instanceof Error ? err.message : String(err) };
|
|
163
|
+
}
|
|
164
|
+
const live = { child, cancelled: false };
|
|
165
|
+
this.runs.set(runId, live);
|
|
166
|
+
let shown = 0;
|
|
167
|
+
let displayTruncated = false;
|
|
168
|
+
let pending = "";
|
|
169
|
+
let tail = "";
|
|
170
|
+
let flushTimer = null;
|
|
171
|
+
const flush = () => {
|
|
172
|
+
flushTimer = null;
|
|
173
|
+
if (!pending)
|
|
174
|
+
return;
|
|
175
|
+
this.opts.emit("shell_output", { id: runId, chunk: pending });
|
|
176
|
+
pending = "";
|
|
177
|
+
};
|
|
178
|
+
const decoders = [new StringDecoder("utf8"), new StringDecoder("utf8")];
|
|
179
|
+
const onText = (raw, isError = false) => {
|
|
180
|
+
if (!raw)
|
|
181
|
+
return;
|
|
182
|
+
const clean = stripStderrMarks(raw);
|
|
183
|
+
const text = isError && clean ? STDERR_START + clean + STDERR_END : clean;
|
|
184
|
+
if (!text)
|
|
185
|
+
return;
|
|
186
|
+
tail = (tail + text).slice(-SHELL_CONTEXT_MAX_CHARS * 2);
|
|
187
|
+
if (displayTruncated)
|
|
188
|
+
return;
|
|
189
|
+
const room = SHELL_DISPLAY_MAX_CHARS - shown;
|
|
190
|
+
const part = text.length > room ? text.slice(0, room) : text;
|
|
191
|
+
shown += part.length;
|
|
192
|
+
pending += part;
|
|
193
|
+
if (part.length < text.length)
|
|
194
|
+
displayTruncated = true;
|
|
195
|
+
flushTimer ??= setTimeout(flush, FLUSH_MS);
|
|
196
|
+
};
|
|
197
|
+
child.stdout?.on("data", (data) => onText(decoders[0].write(data)));
|
|
198
|
+
child.stderr?.on("data", (data) => onText(decoders[1].write(data), true));
|
|
199
|
+
let spawnError;
|
|
200
|
+
let ended = false;
|
|
201
|
+
let leftoverTimer = null;
|
|
202
|
+
const finish = (exitCode, signal) => {
|
|
203
|
+
if (ended)
|
|
204
|
+
return;
|
|
205
|
+
ended = true;
|
|
206
|
+
if (leftoverTimer)
|
|
207
|
+
clearTimeout(leftoverTimer);
|
|
208
|
+
onText(decoders[0].end());
|
|
209
|
+
onText(decoders[1].end(), true);
|
|
210
|
+
if (flushTimer)
|
|
211
|
+
clearTimeout(flushTimer);
|
|
212
|
+
flush();
|
|
213
|
+
this.runs.delete(runId);
|
|
214
|
+
const cut = tailOutput(reopenStderr(tail));
|
|
215
|
+
const displayTail = redactText(reopenStderr(cut.text), { secrets });
|
|
216
|
+
this.opts.onEnd({
|
|
217
|
+
runId,
|
|
218
|
+
command,
|
|
219
|
+
cwd,
|
|
220
|
+
exitCode,
|
|
221
|
+
signal,
|
|
222
|
+
durationMs: Math.max(0, now() - startedAt),
|
|
223
|
+
cancelled: live.cancelled,
|
|
224
|
+
tail: stripStderrMarks(displayTail).replace(/\s+$/, ""),
|
|
225
|
+
displayTail,
|
|
226
|
+
tailTruncated: cut.truncated || tail.length >= SHELL_CONTEXT_MAX_CHARS * 2,
|
|
227
|
+
displayTruncated,
|
|
228
|
+
...(spawnError ? { error: spawnError } : {}),
|
|
229
|
+
});
|
|
230
|
+
};
|
|
231
|
+
child.on("error", (err) => {
|
|
232
|
+
spawnError = err.message;
|
|
233
|
+
finish(null, null);
|
|
234
|
+
});
|
|
235
|
+
child.on("close", (code, signal) => finish(code, signal));
|
|
236
|
+
// `cmd &` leaves children holding the pipes, so "close" would wait on
|
|
237
|
+
// them. Once the shell itself is gone, give output a moment to drain,
|
|
238
|
+
// then stop the leftovers.
|
|
239
|
+
child.on("exit", (code, signal) => {
|
|
240
|
+
leftoverTimer = setTimeout(() => {
|
|
241
|
+
if (child.pid)
|
|
242
|
+
killProcessTree(child.pid);
|
|
243
|
+
child.stdout?.destroy();
|
|
244
|
+
child.stderr?.destroy();
|
|
245
|
+
finish(code, signal);
|
|
246
|
+
}, LEFTOVER_GRACE_MS);
|
|
247
|
+
});
|
|
248
|
+
return { ok: true };
|
|
249
|
+
}
|
|
250
|
+
/** Stop one command and everything it started. False when it isn't running. */
|
|
251
|
+
cancel(runId) {
|
|
252
|
+
const live = this.runs.get(runId);
|
|
253
|
+
if (!live)
|
|
254
|
+
return false;
|
|
255
|
+
live.cancelled = true;
|
|
256
|
+
if (live.child.pid)
|
|
257
|
+
killProcessTree(live.child.pid);
|
|
258
|
+
else
|
|
259
|
+
live.child.kill("SIGKILL");
|
|
260
|
+
return true;
|
|
261
|
+
}
|
|
262
|
+
/** Window closing: stop every command still running. */
|
|
263
|
+
stopAll() {
|
|
264
|
+
for (const runId of [...this.runs.keys()])
|
|
265
|
+
this.cancel(runId);
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
//# sourceMappingURL=shell-runs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shell-runs.js","sourceRoot":"","sources":["../../src/app-sidecar/shell-runs.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,IAAI,SAAS,EAAwC,MAAM,oBAAoB,CAAC;AAC9F,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,kBAAkB,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAC7D,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAChD,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAEtD;;;;;;;GAOG;AAEH;;;;;GAKG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,QAAQ,CAAC;AACrC,MAAM,CAAC,MAAM,UAAU,GAAG,QAAQ,CAAC;AACnC,MAAM,YAAY,GAAG,iBAAiB,CAAC;AAEvC,MAAM,UAAU,gBAAgB,CAAC,IAAY;IAC3C,OAAO,IAAI,CAAC,OAAO,CAAC,YAAY,EAAE,EAAE,CAAC,CAAC;AACxC,CAAC;AAED,4FAA4F;AAC5F,MAAM,UAAU,YAAY,CAAC,IAAY;IACvC,MAAM,GAAG,GAAG,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC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AI,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC;YAAE,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IAChE,CAAC;CACF"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What the `!` picker offers: commands the user already ran in this project
|
|
3
|
+
* (most used first) and commands that fit the project (its git repo, package
|
|
4
|
+
* scripts, build tool) for one they haven't run yet.
|
|
5
|
+
*/
|
|
6
|
+
export interface ShellSuggestion {
|
|
7
|
+
command: string;
|
|
8
|
+
/** Times the user ran it in this project; 0 for a project suggestion. */
|
|
9
|
+
count: number;
|
|
10
|
+
/** Where a never-run suggestion comes from, e.g. "package.json". */
|
|
11
|
+
source?: string;
|
|
12
|
+
}
|
|
13
|
+
interface HistoryEntry {
|
|
14
|
+
command: string;
|
|
15
|
+
count: number;
|
|
16
|
+
lastUsed: number;
|
|
17
|
+
}
|
|
18
|
+
/** Commands kept per project; the least used fall off. */
|
|
19
|
+
export declare const SHELL_HISTORY_MAX = 100;
|
|
20
|
+
export declare function shellHistoryFile(): string;
|
|
21
|
+
/** Most used first; ties go to the most recent, then alphabetical. */
|
|
22
|
+
export declare function rankHistory(entries: readonly HistoryEntry[]): HistoryEntry[];
|
|
23
|
+
export declare function loadShellHistory(cwd: string): Promise<HistoryEntry[]>;
|
|
24
|
+
/** Count one run of `command` in this project. */
|
|
25
|
+
export declare function recordShellCommand(cwd: string, command: string, now?: number): Promise<void>;
|
|
26
|
+
type PackageManager = "pnpm" | "yarn" | "bun" | "npm";
|
|
27
|
+
export declare function scriptCommands(scripts: Record<string, unknown>, pm: PackageManager): string[];
|
|
28
|
+
/** Commands that fit this project, best first. */
|
|
29
|
+
export declare function projectShellSuggestions(cwd: string): Promise<ShellSuggestion[]>;
|
|
30
|
+
/** History first (most used), then project commands not already in it. */
|
|
31
|
+
export declare function mergeShellSuggestions(history: readonly HistoryEntry[], project: readonly ShellSuggestion[]): ShellSuggestion[];
|
|
32
|
+
export declare function shellSuggestions(cwd: string): Promise<ShellSuggestion[]>;
|
|
33
|
+
export {};
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import fs from "node:fs/promises";
|
|
2
|
+
import os from "node:os";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { withFileLock } from "@prestyj/core";
|
|
5
|
+
import { atomicWrite } from "../core/session-storage.js";
|
|
6
|
+
import { projectModelKey } from "./app-settings.js";
|
|
7
|
+
/** Commands kept per project; the least used fall off. */
|
|
8
|
+
export const SHELL_HISTORY_MAX = 100;
|
|
9
|
+
const SUGGESTED_COMMAND_MAX = 200;
|
|
10
|
+
export function shellHistoryFile() {
|
|
11
|
+
return path.join(os.homedir(), ".ezcoder", "shell-history.json");
|
|
12
|
+
}
|
|
13
|
+
function readEntries(value) {
|
|
14
|
+
if (!Array.isArray(value))
|
|
15
|
+
return [];
|
|
16
|
+
return value.flatMap((v) => {
|
|
17
|
+
if (typeof v !== "object" || v === null)
|
|
18
|
+
return [];
|
|
19
|
+
const { command, count, lastUsed } = v;
|
|
20
|
+
if (typeof command !== "string" || !command.trim())
|
|
21
|
+
return [];
|
|
22
|
+
return [
|
|
23
|
+
{
|
|
24
|
+
command,
|
|
25
|
+
count: typeof count === "number" && count > 0 ? Math.floor(count) : 1,
|
|
26
|
+
lastUsed: typeof lastUsed === "number" ? lastUsed : 0,
|
|
27
|
+
},
|
|
28
|
+
];
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
async function loadHistoryFile() {
|
|
32
|
+
try {
|
|
33
|
+
const parsed = JSON.parse(await fs.readFile(shellHistoryFile(), "utf-8"));
|
|
34
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed))
|
|
35
|
+
return {};
|
|
36
|
+
return parsed;
|
|
37
|
+
}
|
|
38
|
+
catch {
|
|
39
|
+
return {};
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
/** Most used first; ties go to the most recent, then alphabetical. */
|
|
43
|
+
export function rankHistory(entries) {
|
|
44
|
+
return [...entries].sort((a, b) => b.count - a.count || b.lastUsed - a.lastUsed || a.command.localeCompare(b.command));
|
|
45
|
+
}
|
|
46
|
+
export async function loadShellHistory(cwd) {
|
|
47
|
+
const file = await loadHistoryFile();
|
|
48
|
+
return rankHistory(readEntries(file[projectModelKey(cwd)]));
|
|
49
|
+
}
|
|
50
|
+
/** Count one run of `command` in this project. */
|
|
51
|
+
export async function recordShellCommand(cwd, command, now = Date.now()) {
|
|
52
|
+
const key = projectModelKey(cwd);
|
|
53
|
+
const file = shellHistoryFile();
|
|
54
|
+
await fs.mkdir(path.dirname(file), { recursive: true });
|
|
55
|
+
await withFileLock(file, async () => {
|
|
56
|
+
const all = await loadHistoryFile();
|
|
57
|
+
const entries = readEntries(all[key]);
|
|
58
|
+
const existing = entries.find((e) => e.command === command);
|
|
59
|
+
if (existing) {
|
|
60
|
+
existing.count += 1;
|
|
61
|
+
existing.lastUsed = now;
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
entries.push({ command, count: 1, lastUsed: now });
|
|
65
|
+
}
|
|
66
|
+
all[key] = rankHistory(entries).slice(0, SHELL_HISTORY_MAX);
|
|
67
|
+
await atomicWrite(file, JSON.stringify(all, null, 2));
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
async function exists(p) {
|
|
71
|
+
return fs.access(p).then(() => true, () => false);
|
|
72
|
+
}
|
|
73
|
+
async function packageManager(cwd) {
|
|
74
|
+
if (await exists(path.join(cwd, "pnpm-lock.yaml")))
|
|
75
|
+
return "pnpm";
|
|
76
|
+
if (await exists(path.join(cwd, "yarn.lock")))
|
|
77
|
+
return "yarn";
|
|
78
|
+
if ((await exists(path.join(cwd, "bun.lockb"))) || (await exists(path.join(cwd, "bun.lock")))) {
|
|
79
|
+
return "bun";
|
|
80
|
+
}
|
|
81
|
+
return "npm";
|
|
82
|
+
}
|
|
83
|
+
/** Scripts people check with most often come first. */
|
|
84
|
+
const SCRIPT_ORDER = ["test", "build", "lint", "check", "typecheck", "format"];
|
|
85
|
+
/** Servers and watchers never finish, so they make poor one-shot suggestions. */
|
|
86
|
+
const LONG_RUNNING = /^(dev|start|serve|preview|watch)(:|$)|:watch$/;
|
|
87
|
+
export function scriptCommands(scripts, pm) {
|
|
88
|
+
const names = Object.keys(scripts).filter((name) => typeof scripts[name] === "string" && !LONG_RUNNING.test(name));
|
|
89
|
+
const rank = (name) => {
|
|
90
|
+
const i = SCRIPT_ORDER.indexOf(name);
|
|
91
|
+
return i === -1 ? SCRIPT_ORDER.length : i;
|
|
92
|
+
};
|
|
93
|
+
names.sort((a, b) => rank(a) - rank(b) || a.localeCompare(b));
|
|
94
|
+
return names.slice(0, 6).map((name) => {
|
|
95
|
+
if (pm === "npm")
|
|
96
|
+
return name === "test" ? "npm test" : `npm run ${name}`;
|
|
97
|
+
return `${pm} ${name}`;
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
/** Commands that fit this project, best first. */
|
|
101
|
+
export async function projectShellSuggestions(cwd) {
|
|
102
|
+
const out = [];
|
|
103
|
+
const add = (source, commands) => {
|
|
104
|
+
for (const command of commands)
|
|
105
|
+
out.push({ command, count: 0, source });
|
|
106
|
+
};
|
|
107
|
+
if (await exists(path.join(cwd, ".git"))) {
|
|
108
|
+
add("git", ["git status", "git diff", "git log --oneline -10"]);
|
|
109
|
+
}
|
|
110
|
+
try {
|
|
111
|
+
const pkg = JSON.parse(await fs.readFile(path.join(cwd, "package.json"), "utf-8"));
|
|
112
|
+
if (pkg.scripts && typeof pkg.scripts === "object" && !Array.isArray(pkg.scripts)) {
|
|
113
|
+
add("package.json", scriptCommands(pkg.scripts, await packageManager(cwd)));
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
catch {
|
|
117
|
+
// No package.json, or one that doesn't parse: nothing to suggest from it.
|
|
118
|
+
}
|
|
119
|
+
if (await exists(path.join(cwd, "Cargo.toml"))) {
|
|
120
|
+
add("Cargo.toml", ["cargo check", "cargo test", "cargo build"]);
|
|
121
|
+
}
|
|
122
|
+
if (await exists(path.join(cwd, "go.mod")))
|
|
123
|
+
add("go.mod", ["go test ./...", "go build ./..."]);
|
|
124
|
+
if (await exists(path.join(cwd, "Makefile")))
|
|
125
|
+
add("Makefile", ["make"]);
|
|
126
|
+
if (out.length === 0)
|
|
127
|
+
add("folder", ["ls -la"]);
|
|
128
|
+
return out;
|
|
129
|
+
}
|
|
130
|
+
/** History first (most used), then project commands not already in it. */
|
|
131
|
+
export function mergeShellSuggestions(history, project) {
|
|
132
|
+
const seen = new Set();
|
|
133
|
+
const out = [];
|
|
134
|
+
for (const item of [
|
|
135
|
+
...history.map((h) => ({ command: h.command, count: h.count })),
|
|
136
|
+
...project,
|
|
137
|
+
]) {
|
|
138
|
+
if (seen.has(item.command) || item.command.length > SUGGESTED_COMMAND_MAX)
|
|
139
|
+
continue;
|
|
140
|
+
seen.add(item.command);
|
|
141
|
+
out.push(item);
|
|
142
|
+
}
|
|
143
|
+
return out;
|
|
144
|
+
}
|
|
145
|
+
export async function shellSuggestions(cwd) {
|
|
146
|
+
const [history, project] = await Promise.all([
|
|
147
|
+
loadShellHistory(cwd).catch(() => []),
|
|
148
|
+
projectShellSuggestions(cwd).catch(() => []),
|
|
149
|
+
]);
|
|
150
|
+
return mergeShellSuggestions(history, project);
|
|
151
|
+
}
|
|
152
|
+
//# sourceMappingURL=shell-suggestions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shell-suggestions.js","sourceRoot":"","sources":["../../src/app-sidecar/shell-suggestions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAClC,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAC7C,OAAO,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AACzD,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAw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G,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,EAAE,CAAC;QACrC,uBAAuB,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,EAAE,CAAC;KAC7C,CAAC,CAAC;IACH,OAAO,qBAAqB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;AACjD,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { fetchSubscriptionUsage, SubscriptionUsageError, oauthStorageKey, } from "@prestyj/core";
|
|
1
|
+
import { fetchSubscriptionUsage, readClaudeCodeUsage, SubscriptionUsageError, oauthStorageKey, } from "@prestyj/core";
|
|
2
2
|
import { log } from "../core/logger.js";
|
|
3
3
|
/** Daemon-level subscription-usage fetcher with caching, 429 backoff and last-good replay. */
|
|
4
4
|
export function createUsageService(auth) {
|
|
@@ -27,7 +27,26 @@ export function createUsageService(auth) {
|
|
|
27
27
|
log("INFO", "app-sidecar", "subscription usage recovered", { provider });
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
|
+
// A Claude Code sign-in reports usage on each request it makes (SDK
|
|
31
|
+
// rate-limit events, saved by the loop): show the last report.
|
|
32
|
+
async function claudeUsage() {
|
|
33
|
+
const displayName = "Anthropic";
|
|
34
|
+
const snapshot = await readClaudeCodeUsage();
|
|
35
|
+
if (!snapshot || snapshot.windows.length === 0) {
|
|
36
|
+
return {
|
|
37
|
+
provider: "anthropic",
|
|
38
|
+
displayName,
|
|
39
|
+
connected: true,
|
|
40
|
+
windows: [],
|
|
41
|
+
fetchedAt: Date.now(),
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
return { ...snapshot, connected: true };
|
|
45
|
+
}
|
|
30
46
|
async function fetchUsageProvider(provider) {
|
|
47
|
+
// A Claude Code sign-in reports its own usage; our Claude sign-in is fetched below.
|
|
48
|
+
if (provider === "anthropic" && (await auth.hasClaudeCodeLogin()))
|
|
49
|
+
return await claudeUsage();
|
|
31
50
|
const displayName = provider === "anthropic" ? "Anthropic" : provider === "openai" ? "Codex" : "Kimi";
|
|
32
51
|
// Kimi plan usage is tracked on the OAuth credential specifically — the
|
|
33
52
|
// Moonshot platform API key is metered per-token, not per plan window.
|
|
@@ -40,6 +59,11 @@ export function createUsageService(auth) {
|
|
|
40
59
|
}
|
|
41
60
|
try {
|
|
42
61
|
let credentials = await auth.resolveCredentials(authKey);
|
|
62
|
+
// Only the Claude sign-in (an OAuth token) has a plan meter; an API key
|
|
63
|
+
// is billed per token, and the usage endpoint would just refuse it.
|
|
64
|
+
if (provider === "anthropic" && !credentials.accessToken.startsWith("sk-ant-oat")) {
|
|
65
|
+
return { provider, displayName, connected: false, windows: [], fetchedAt: Date.now() };
|
|
66
|
+
}
|
|
43
67
|
try {
|
|
44
68
|
const snapshot = {
|
|
45
69
|
...(await fetchSubscriptionUsage(provider, credentials)),
|
|
@@ -75,7 +99,7 @@ export function createUsageService(auth) {
|
|
|
75
99
|
if (error instanceof SubscriptionUsageError && error.status === 429) {
|
|
76
100
|
const backoffMs = Math.min(USAGE_RATE_LIMIT_MAX_BACKOFF_MS, Math.max(USAGE_RATE_LIMIT_MIN_BACKOFF_MS, error.retryAfterMs ?? USAGE_RATE_LIMIT_FALLBACK_BACKOFF_MS));
|
|
77
101
|
usageRateLimitedUntil.set(provider, Date.now() + backoffMs);
|
|
78
|
-
// Rate limits on this auxiliary endpoint are expected (every
|
|
102
|
+
// Rate limits on this auxiliary endpoint are expected (every EZ Coder process
|
|
79
103
|
// on the machine polls it) and already handled by the backoff plus the
|
|
80
104
|
// last-good replay. Log the transition, not every retry.
|
|
81
105
|
if (!usageRateLimitLogged.has(provider)) {
|