gentle-pi 3.6.0 → 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +37 -6
- package/assets/agents/gentle-ai-explore.md +4 -4
- package/assets/agents/gentle-ai-verify.md +6 -4
- package/assets/agents/gentle-ai-worker.md +7 -9
- package/assets/orchestrator-delegation.md +40 -41
- package/assets/orchestrator-memory.md +1 -22
- package/assets/orchestrator-skills.md +1 -1
- package/assets/orchestrator.md +12 -24
- package/assets/support/strict-tdd-verify.md +4 -266
- package/assets/support/strict-tdd.md +8 -360
- package/bin/gentle-shell.mjs +254 -29
- package/docs/delegated-verification.md +26 -1
- package/docs/gentle-agents-activity.md +24 -0
- package/docs/gentle-shell.md +95 -30
- package/docs/native-authority-architecture.md +2 -2
- package/docs/prompt-history.md +280 -0
- package/docs/readme-reference.md +117 -235
- package/docs/telemetry.md +1 -1
- package/docs/yolo-mode.md +86 -0
- package/extensions/child-context.ts +26 -0
- package/extensions/child-safety.ts +23 -0
- package/extensions/gentle-agents.ts +509 -275
- package/extensions/gentle-ai.ts +781 -683
- package/extensions/gentle-shell.ts +1375 -88
- package/extensions/gentle-stats.ts +101 -0
- package/extensions/gentle-todo.ts +18 -7
- package/extensions/history/atomic-write.ts +38 -0
- package/extensions/history/hide-prompts.ts +183 -0
- package/extensions/history/index.ts +1419 -0
- package/extensions/history/load-shared-history.ts +39 -0
- package/extensions/history/selector-helpers.ts +538 -0
- package/extensions/history/session-scan.ts +233 -0
- package/extensions/history/store.ts +1119 -0
- package/extensions/nan-provider.ts +6 -0
- package/extensions/quiet-tools.ts +179 -87
- package/extensions/resume-hint.ts +60 -0
- package/extensions/skill-registry.ts +16 -12
- package/extensions/startup-banner.ts +60 -31
- package/lib/agent-assets.ts +604 -0
- package/lib/agent-profile-pin.ts +12 -0
- package/lib/agents-message-delivery.ts +181 -0
- package/lib/agents-protocol.ts +60 -0
- package/lib/agents-runner.ts +105 -98
- package/lib/agents-view.ts +26 -3
- package/lib/agents-widget.ts +16 -9
- package/lib/append-system-prompt.ts +21 -0
- package/lib/bounded-writer-admission.ts +147 -0
- package/lib/card-style-policy.ts +60 -0
- package/lib/child-context-files.ts +166 -0
- package/lib/codemode-renderer.ts +185 -0
- package/lib/command-palette-catalog.ts +3 -9
- package/lib/command-palette.ts +25 -14
- package/lib/destructive-command-guard.ts +144 -0
- package/lib/foreign-target-grants.ts +32 -0
- package/lib/gentle-ai-elapsed-store.ts +87 -0
- package/lib/gentle-ai-renderer.ts +196 -39
- package/lib/gentle-shell-launcher.ts +24 -13
- package/lib/gentle-shell-resume-hint.ts +176 -0
- package/lib/history-capture-policy.ts +95 -0
- package/lib/model-routing-authority.ts +5 -1
- package/lib/nan-provider.ts +227 -0
- package/lib/native-review-cli.ts +53 -108
- package/lib/odd-phase-inference.ts +231 -0
- package/lib/odd-phase.ts +141 -0
- package/lib/overlay-repaint.ts +26 -0
- package/lib/pi-tui-keys.ts +53 -0
- package/lib/review-candidate-view-owner.ts +67 -17
- package/lib/review-candidate-view.ts +112 -25
- package/lib/review-reminder-receipt.ts +48 -8
- package/lib/review-risk-assessment.ts +156 -11
- package/lib/review-sidebar-state.ts +223 -0
- package/lib/selection-engine.ts +515 -0
- package/lib/session-change-capture.ts +10 -1
- package/lib/session-messaging-grants.ts +135 -0
- package/lib/session-worktree-registry.ts +14 -2
- package/lib/shell-bar.ts +179 -24
- package/lib/shell-card.ts +287 -18
- package/lib/shell-changes-view.ts +2 -1
- package/lib/shell-prompt.ts +102 -6
- package/lib/shell-sidebar-layout.ts +78 -14
- package/lib/shell-sidebar.ts +15 -1
- package/lib/shell-todo.ts +23 -13
- package/lib/shell-usage-view.ts +9 -4
- package/lib/shell-usage.ts +66 -10
- package/lib/stats-collector.ts +381 -0
- package/lib/stats-view.ts +431 -0
- package/lib/theme-customization.ts +52 -0
- package/lib/vim-editor-adapter.ts +379 -0
- package/lib/vim-normal-engine.ts +154 -0
- package/lib/vim-operator-engine.ts +416 -0
- package/lib/vim-policy.ts +49 -0
- package/lib/vim-visual-engine.ts +107 -0
- package/lib/visual-customization-policy.ts +108 -0
- package/lib/visual-customize-view.ts +330 -0
- package/lib/visual-profiles.ts +228 -0
- package/lib/yolo-session-policy.ts +240 -0
- package/package.json +20 -8
- package/runtime/gentle-shell-launcher.mjs +23 -12
- package/runtime/gentle-shell-resume-hint.mjs +177 -0
- package/runtime/native-review-cli.mjs +53 -108
- package/runtime/review-risk-assessment.mjs +154 -9
- package/scripts/build-runtime-modules.mjs +1 -0
- package/scripts/gentle-ai-installer.mjs +14 -13
- package/scripts/mirror-odd-routing.mjs +2 -2
- package/scripts/run-test-suite.mjs +76 -0
- package/scripts/test-packed-runner.mjs +31 -14
- package/scripts/verify-package-files.mjs +11 -22
- package/skills/branch-pr/SKILL.md +24 -52
- package/skills/chained-pr/SKILL.md +31 -15
- package/skills/chained-pr/references/chaining-details.md +31 -20
- package/skills/gentle-ai/SKILL.md +9 -15
- package/skills/issue-creation/SKILL.md +8 -2
- package/skills/issue-creation/references/delegated-workflow-actions.md +19 -0
- package/skills/work-unit-commits/SKILL.md +4 -3
- package/tests/agent-profiles.test.ts +18 -0
- package/tests/agents-fake-child.ts +2 -2
- package/tests/agents-message-delivery.test.ts +106 -0
- package/tests/agents-protocol.test.ts +40 -0
- package/tests/agents-runner.test.ts +400 -89
- package/tests/agents-view-thread-identity.test.ts +169 -0
- package/tests/agents-view.test.ts +8 -2
- package/tests/agents-widget.test.ts +154 -15
- package/tests/append-system-prompt-route.test.ts +160 -0
- package/tests/append-system-prompt.test.ts +46 -0
- package/tests/artifact-language.test.ts +19 -213
- package/tests/ask-user-question.test.ts +44 -1
- package/tests/asset-installation-runtime.test.ts +5 -16
- package/tests/autonomous-guard.test.ts +69 -1
- package/tests/bounded-writer-admission.test.ts +95 -0
- package/tests/branch-pr-skill.test.ts +43 -0
- package/tests/card-style-policy.test.ts +55 -0
- package/tests/chained-pr-skill.test.ts +124 -0
- package/tests/child-context-files.test.ts +255 -0
- package/tests/child-safety.test.ts +82 -0
- package/tests/codemode-rendering.test.ts +491 -0
- package/tests/command-palette.test.ts +39 -3
- package/tests/delegated-key-learnings-contract.test.ts +0 -76
- package/tests/destructive-command-guard.test.ts +84 -0
- package/tests/devbinary/native-review-parity.devtest.ts +170 -2
- package/tests/devbinary/non-git-subagent-bootstrap.devtest.ts +193 -0
- package/tests/fixtures/stats/sessions/--work-alpha--/2026-09-28T10-00-00-000Z_aaa.jsonl +7 -0
- package/tests/fixtures/stats/sessions/--work-alpha--/2026-09-29T23-00-00-000Z_bbb.jsonl +3 -0
- package/tests/fixtures/stats/sessions/--work-alpha--/2026-09-30T08-00-00-000Z_ddd.jsonl +2 -0
- package/tests/fixtures/stats/sessions/--work-alpha--/2026-09-30T09-00-00-000Z_eee.jsonl +3 -0
- package/tests/fixtures/stats/sessions/--work-alpha--/run-1/session.jsonl +2 -0
- package/tests/fixtures/stats/sessions/--work-beta--/2026-09-01T12-00-00-000Z_ccc.jsonl +2 -0
- package/tests/fixtures/stats/user-pi/sessions/--work-alpha--/2026-09-28T10-00-00-000Z_aaa.jsonl +2 -0
- package/tests/fixtures/stats/user-pi/sessions/--work-alpha--/2026-09-29T23-00-00-000Z_bbb.jsonl +4 -0
- package/tests/fixtures/stats/user-pi/sessions/--work-gamma--/2026-09-20T09-00-00-000Z_fff.jsonl +3 -0
- package/tests/foreign-target-grants.test.ts +58 -0
- package/tests/generic-agent-tools.test.ts +54 -0
- package/tests/gentle-agents.test.ts +1411 -256
- package/tests/gentle-ai-binary.test.ts +3 -3
- package/tests/gentle-ai-elapsed-store.test.ts +68 -0
- package/tests/gentle-ai-installer.test.ts +68 -54
- package/tests/gentle-ai-renderer.test.ts +487 -8
- package/tests/gentle-ai.test.ts +288 -65
- package/tests/gentle-card-text.ts +2 -1
- package/tests/gentle-shell-bin.test.ts +651 -114
- package/tests/gentle-shell-launcher.test.ts +99 -52
- package/tests/gentle-shell-resume-hint.test.ts +270 -0
- package/tests/gentle-shell.test.ts +3839 -187
- package/tests/gentle-stats.test.ts +152 -0
- package/tests/gentle-theme.test.ts +4 -1
- package/tests/gentle-todo.test.ts +80 -8
- package/tests/history-atomic-write.test.ts +57 -0
- package/tests/history-capture-policy.test.ts +102 -0
- package/tests/history-command-registration.test.ts +164 -0
- package/tests/history-dedupe-entries.test.ts +123 -0
- package/tests/history-delete-backfill.test.ts +190 -0
- package/tests/history-delete-confirm.test.ts +460 -0
- package/tests/history-dispatch.test.ts +180 -0
- package/tests/history-drain-hidden.test.ts +110 -0
- package/tests/history-drain-order.test.ts +98 -0
- package/tests/history-expanded-globals.test.ts +62 -0
- package/tests/history-gc.test.ts +832 -0
- package/tests/history-header-layout.test.ts +265 -0
- package/tests/history-hide-prompts.test.ts +275 -0
- package/tests/history-lazy-windowing.test.ts +508 -0
- package/tests/history-legacy-migrate-v2.test.ts +297 -0
- package/tests/history-load-shared-history.test.ts +53 -0
- package/tests/history-max-results-cap.test.ts +76 -0
- package/tests/history-multi-reader.test.ts +203 -0
- package/tests/history-off-path.test.ts +170 -0
- package/tests/history-openflow-integration.test.ts +173 -0
- package/tests/history-overlay-margin.test.ts +326 -0
- package/tests/history-preview-layout.test.ts +93 -0
- package/tests/history-registry.test.ts +143 -0
- package/tests/history-scope-delete.test.ts +411 -0
- package/tests/history-search-caret-keys.test.ts +142 -0
- package/tests/history-seed-bootstrap.test.ts +170 -0
- package/tests/history-seed-regen.test.ts +129 -0
- package/tests/history-selector-windowing.test.ts +94 -0
- package/tests/history-session-scan-directory.test.ts +87 -0
- package/tests/history-session-scan-extract.test.ts +583 -0
- package/tests/history-session-writer.test.ts +351 -0
- package/tests/history-store-paths.test.ts +79 -0
- package/tests/history-tombstone-exact.test.ts +139 -0
- package/tests/history-wheel-mouse.test.ts +242 -0
- package/tests/inprocess-reviewer.test.ts +29 -19
- package/tests/issue-creation-skill.test.ts +61 -0
- package/tests/model-routing-authority.test.ts +16 -0
- package/tests/nan-provider.test.ts +471 -0
- package/tests/native-review-capability-contract.test.ts +13 -1
- package/tests/native-review-cli.test.ts +6 -120
- package/tests/native-review-parity-runtime.test.ts +100 -3
- package/tests/odd-integration.test.ts +67 -0
- package/tests/odd-phase-inference.test.ts +213 -0
- package/tests/odd-phase-loader.test.ts +253 -0
- package/tests/odd-phase.test.ts +307 -0
- package/tests/odd-routing-canonical-ratchet.test.ts +11 -6
- package/tests/odd-routing-contract.test.ts +86 -35
- package/tests/orchestrator-budget.test.ts +14 -39
- package/tests/orchestrator-rdd-ownership.test.ts +3 -3
- package/tests/overlay-repaint.test.ts +74 -0
- package/tests/package-manifest.test.ts +252 -115
- package/tests/packed-runner-owned-path.test.ts +46 -0
- package/tests/persona-single-channel.test.ts +6 -6
- package/tests/provider-defect-handoff.test.ts +3 -11
- package/tests/quiet-bash-runtime.test.ts +76 -0
- package/tests/quiet-tool-rendering.test.ts +409 -184
- package/tests/rdd-aware-verification-contract.test.ts +76 -1
- package/tests/rdd-status-line.test.ts +9 -4
- package/tests/resume-hint-extension.test.ts +122 -0
- package/tests/review-agent-end-preflight.test.ts +176 -12
- package/tests/review-candidate-owner-retry.test.ts +22 -1
- package/tests/review-candidate-view.test.ts +298 -0
- package/tests/review-contract-prompt.test.ts +108 -43
- package/tests/review-controller-lock-status.test.ts +0 -1
- package/tests/review-controller-native-routing.test.ts +611 -5
- package/tests/review-controller-workspace-root.test.ts +163 -4
- package/tests/review-host-relay-routing.test.ts +338 -2
- package/tests/review-integration-v2-forward.test.ts +200 -0
- package/tests/review-ledger-contract.test.ts +10 -34
- package/tests/review-reminder-receipt.test.ts +47 -1
- package/tests/review-risk-assessment.test.ts +498 -6
- package/tests/review-sidebar-state.test.ts +402 -0
- package/tests/run-test-suite.test.ts +124 -0
- package/tests/runtime-harness.mjs +145 -786
- package/tests/runtime-metrics-children.test.ts +16 -23
- package/tests/selection-engine.test.ts +421 -0
- package/tests/session-change-capture.test.ts +12 -1
- package/tests/session-messaging-grants.test.ts +255 -0
- package/tests/session-worktree-registry.test.ts +77 -0
- package/tests/shell-bar.test.ts +382 -1
- package/tests/shell-card.test.ts +353 -1
- package/tests/shell-changes-view.test.ts +52 -0
- package/tests/shell-prompt.test.ts +94 -2
- package/tests/shell-sidebar-layout.test.ts +325 -21
- package/tests/shell-sidebar-scroll-benchmark.test.ts +255 -0
- package/tests/shell-todo.test.ts +87 -1
- package/tests/shell-usage-view.test.ts +27 -0
- package/tests/shell-usage.test.ts +73 -0
- package/tests/skill-registry.test.ts +50 -1
- package/tests/startup-banner.test.ts +130 -2
- package/tests/stats-collector.test.ts +195 -0
- package/tests/stats-view.test.ts +202 -0
- package/tests/telemetry-trigger.test.ts +81 -20
- package/tests/theme-customization.test.ts +72 -0
- package/tests/vim-editor-adapter-host-resolution.test.ts +37 -0
- package/tests/vim-editor-adapter.test.ts +804 -0
- package/tests/vim-normal-engine.test.ts +101 -0
- package/tests/vim-operator-engine.test.ts +215 -0
- package/tests/vim-policy.test.ts +19 -0
- package/tests/vim-visual-engine.test.ts +52 -0
- package/tests/visual-customization-policy.test.ts +110 -0
- package/tests/visual-customize-view.test.ts +418 -0
- package/tests/visual-profiles.test.ts +87 -0
- package/tests/yolo-customize.test.ts +256 -0
- package/tests/yolo-mode-runtime.test.ts +161 -0
- package/tests/yolo-mode.test.ts +261 -0
- package/tests/yolo-session-policy.test.ts +59 -0
- package/themes/Gentle.json +2 -1
- package/themes/Gentleman-Cute.json +2 -1
- package/themes/Gentleman-Sexy.json +2 -1
- package/assets/agents/sdd-apply.md +0 -159
- package/assets/agents/sdd-archive.md +0 -228
- package/assets/agents/sdd-design.md +0 -49
- package/assets/agents/sdd-explore.md +0 -48
- package/assets/agents/sdd-init.md +0 -56
- package/assets/agents/sdd-onboard.md +0 -52
- package/assets/agents/sdd-proposal.md +0 -64
- package/assets/agents/sdd-remediate.md +0 -37
- package/assets/agents/sdd-research.md +0 -49
- package/assets/agents/sdd-spec.md +0 -192
- package/assets/agents/sdd-status.md +0 -54
- package/assets/agents/sdd-tasks.md +0 -108
- package/assets/agents/sdd-verify.md +0 -124
- package/assets/chains/sdd-full.chain.md +0 -83
- package/assets/chains/sdd-plan.chain.md +0 -56
- package/assets/chains/sdd-verify.chain.md +0 -43
- package/assets/sdd-orchestrator-workflow.md +0 -319
- package/assets/support/sdd-status-contract.md +0 -77
- package/docs/assets/diagrams/sdd-cycle.svg +0 -14
- package/extensions/sdd-init.ts +0 -816
- package/lib/openspec-deltas.ts +0 -156
- package/lib/sdd-preflight.ts +0 -1066
- package/lib/sdd-research-capabilities.ts +0 -94
- package/lib/sdd-status.ts +0 -26
- package/tests/fixtures/legacy/sdd-research-v2.5.0.md +0 -54
- package/tests/fixtures/native-review-cli/v2.1.3/bind-sdd.json +0 -25
- package/tests/fixtures/v0.10.7/assets/agents/sdd-apply.md +0 -132
- package/tests/openspec-deltas.test.ts +0 -209
- package/tests/sdd-agent-tools.test.ts +0 -156
- package/tests/sdd-archive-replay.test.ts +0 -82
- package/tests/sdd-classical-continuation.test.ts +0 -74
- package/tests/sdd-execution-routing-contract.test.ts +0 -44
- package/tests/sdd-managed-runtime-settlement.test.ts +0 -155
- package/tests/sdd-native-managed-uptake.test.ts +0 -243
- package/tests/sdd-no-attempts-contract.test.ts +0 -15
- package/tests/sdd-odd-integration.test.ts +0 -33
- package/tests/sdd-optional-research.test.ts +0 -124
- package/tests/sdd-planning-routing-contract.test.ts +0 -45
- package/tests/sdd-preflight-rpc-input.test.ts +0 -125
- package/tests/sdd-preflight.test.ts +0 -541
- package/tests/sdd-research-capabilities.test.ts +0 -114
- package/tests/sdd-research-live.test.ts +0 -241
- package/tests/sdd-selection-transport.test.ts +0 -653
- package/tests/sdd-status.test.ts +0 -9
- package/tests/sdd-task-truth.test.ts +0 -43
package/extensions/sdd-init.ts
DELETED
|
@@ -1,816 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
existsSync,
|
|
3
|
-
mkdirSync,
|
|
4
|
-
readFileSync,
|
|
5
|
-
readdirSync,
|
|
6
|
-
writeFileSync,
|
|
7
|
-
} from "node:fs";
|
|
8
|
-
import { basename, dirname, join, relative } from "node:path";
|
|
9
|
-
import { applySavedModelConfig } from "./gentle-ai.ts";
|
|
10
|
-
import { ensureSddPreflight, installPackageAssets } from "../lib/sdd-preflight.ts";
|
|
11
|
-
type ExtensionAPI = any;
|
|
12
|
-
|
|
13
|
-
const CONFIG_REL_PATH = "openspec/config.yaml";
|
|
14
|
-
const MAX_SCAN_FILES = 20_000;
|
|
15
|
-
const IGNORED_DIRS = new Set([
|
|
16
|
-
".git",
|
|
17
|
-
".hg",
|
|
18
|
-
".svn",
|
|
19
|
-
"node_modules",
|
|
20
|
-
"vendor",
|
|
21
|
-
"dist",
|
|
22
|
-
"build",
|
|
23
|
-
"target",
|
|
24
|
-
"coverage",
|
|
25
|
-
".next",
|
|
26
|
-
".nuxt",
|
|
27
|
-
".turbo",
|
|
28
|
-
".cache",
|
|
29
|
-
"__pycache__",
|
|
30
|
-
]);
|
|
31
|
-
|
|
32
|
-
interface PackageJson {
|
|
33
|
-
name?: string;
|
|
34
|
-
type?: string;
|
|
35
|
-
scripts?: Record<string, string>;
|
|
36
|
-
dependencies?: Record<string, string>;
|
|
37
|
-
devDependencies?: Record<string, string>;
|
|
38
|
-
peerDependencies?: Record<string, string>;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
interface CommandInfo {
|
|
42
|
-
scope: string;
|
|
43
|
-
command: string;
|
|
44
|
-
framework: string;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
interface Detection {
|
|
48
|
-
projectName: string;
|
|
49
|
-
stack: string[];
|
|
50
|
-
packageManagers: string[];
|
|
51
|
-
markers: string[];
|
|
52
|
-
evidence: string[];
|
|
53
|
-
testCommand?: string;
|
|
54
|
-
testFramework?: string;
|
|
55
|
-
coverageCommand?: string;
|
|
56
|
-
lintCommand?: string;
|
|
57
|
-
typecheckCommand?: string;
|
|
58
|
-
formatCommand?: string;
|
|
59
|
-
commands: {
|
|
60
|
-
unit: CommandInfo[];
|
|
61
|
-
integration: CommandInfo[];
|
|
62
|
-
e2e: CommandInfo[];
|
|
63
|
-
coverage: CommandInfo[];
|
|
64
|
-
lint: CommandInfo[];
|
|
65
|
-
typecheck: CommandInfo[];
|
|
66
|
-
format: CommandInfo[];
|
|
67
|
-
};
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
function yamlString(value: string): string {
|
|
71
|
-
return JSON.stringify(value);
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
function escapeBlockScalar(value: string): string {
|
|
75
|
-
return value
|
|
76
|
-
.split("\n")
|
|
77
|
-
.map((line) => ` ${line}`)
|
|
78
|
-
.join("\n");
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
function readJson<T>(path: string): T | undefined {
|
|
82
|
-
try {
|
|
83
|
-
return JSON.parse(readFileSync(path, "utf8")) as T;
|
|
84
|
-
} catch {
|
|
85
|
-
return undefined;
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
function hasFile(cwd: string, rel: string): boolean {
|
|
90
|
-
return existsSync(join(cwd, rel));
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
function walkProject(cwd: string): string[] {
|
|
94
|
-
const out: string[] = [];
|
|
95
|
-
const stack = [cwd];
|
|
96
|
-
while (stack.length > 0 && out.length < MAX_SCAN_FILES) {
|
|
97
|
-
const dir = stack.pop()!;
|
|
98
|
-
let entries;
|
|
99
|
-
try {
|
|
100
|
-
entries = readdirSync(dir, { withFileTypes: true });
|
|
101
|
-
} catch {
|
|
102
|
-
continue;
|
|
103
|
-
}
|
|
104
|
-
for (const entry of entries) {
|
|
105
|
-
if (out.length >= MAX_SCAN_FILES) break;
|
|
106
|
-
if (entry.isDirectory()) {
|
|
107
|
-
if (!IGNORED_DIRS.has(entry.name)) stack.push(join(dir, entry.name));
|
|
108
|
-
continue;
|
|
109
|
-
}
|
|
110
|
-
if (entry.isFile()) out.push(relative(cwd, join(dir, entry.name)));
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
return out.sort();
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
function deps(pkg: PackageJson | undefined): Set<string> {
|
|
117
|
-
return new Set([
|
|
118
|
-
...Object.keys(pkg?.dependencies ?? {}),
|
|
119
|
-
...Object.keys(pkg?.devDependencies ?? {}),
|
|
120
|
-
...Object.keys(pkg?.peerDependencies ?? {}),
|
|
121
|
-
]);
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
function detectPackageManagerAt(
|
|
125
|
-
cwd: string,
|
|
126
|
-
relDir: string,
|
|
127
|
-
): string | undefined {
|
|
128
|
-
const base = join(cwd, relDir);
|
|
129
|
-
if (existsSync(join(base, "pnpm-lock.yaml"))) return "pnpm";
|
|
130
|
-
if (existsSync(join(base, "yarn.lock"))) return "yarn";
|
|
131
|
-
if (existsSync(join(base, "bun.lockb")) || existsSync(join(base, "bun.lock")))
|
|
132
|
-
return "bun";
|
|
133
|
-
if (existsSync(join(base, "package-lock.json"))) return "npm";
|
|
134
|
-
if (existsSync(join(base, "package.json"))) return "npm";
|
|
135
|
-
return undefined;
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
function commandInScope(scope: string, command: string): string {
|
|
139
|
-
return scope === "." ? command : `cd ${scope} && ${command}`;
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
function runScript(pm: string | undefined, script: string): string {
|
|
143
|
-
if (pm === "yarn") return `yarn ${script}`;
|
|
144
|
-
if (pm === "bun") return `bun run ${script}`;
|
|
145
|
-
return `${pm ?? "npm"} run ${script}`;
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
function scriptCommand(
|
|
149
|
-
pm: string | undefined,
|
|
150
|
-
scripts: Record<string, string> | undefined,
|
|
151
|
-
candidates: string[],
|
|
152
|
-
): { name: string; command: string } | undefined {
|
|
153
|
-
if (!scripts) return undefined;
|
|
154
|
-
for (const name of candidates) {
|
|
155
|
-
if (!scripts[name]) continue;
|
|
156
|
-
const command =
|
|
157
|
-
name === "test" && pm !== "bun"
|
|
158
|
-
? `${pm ?? "npm"} test`
|
|
159
|
-
: runScript(pm, name);
|
|
160
|
-
return { name, command };
|
|
161
|
-
}
|
|
162
|
-
return undefined;
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
function addUnique(list: CommandInfo[], command: CommandInfo): void {
|
|
166
|
-
if (
|
|
167
|
-
list.some(
|
|
168
|
-
(item) =>
|
|
169
|
-
item.scope === command.scope && item.command === command.command,
|
|
170
|
-
)
|
|
171
|
-
)
|
|
172
|
-
return;
|
|
173
|
-
list.push(command);
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
function addMarker(detection: Detection, marker: string): void {
|
|
177
|
-
if (!detection.markers.includes(marker)) detection.markers.push(marker);
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
function addStack(detection: Detection, stack: string): void {
|
|
181
|
-
if (!detection.stack.includes(stack)) detection.stack.push(stack);
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
function addEvidence(detection: Detection, evidence: string): void {
|
|
185
|
-
if (!detection.evidence.includes(evidence)) detection.evidence.push(evidence);
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
interface GenericHint {
|
|
189
|
-
marker: string;
|
|
190
|
-
stack: string;
|
|
191
|
-
testCommand?: string;
|
|
192
|
-
framework?: string;
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
const GENERIC_HINTS: GenericHint[] = [
|
|
196
|
-
{
|
|
197
|
-
marker: "mix.exs",
|
|
198
|
-
stack: "Elixir",
|
|
199
|
-
testCommand: "mix test",
|
|
200
|
-
framework: "ExUnit",
|
|
201
|
-
},
|
|
202
|
-
{
|
|
203
|
-
marker: "rebar.config",
|
|
204
|
-
stack: "Erlang",
|
|
205
|
-
testCommand: "rebar3 eunit",
|
|
206
|
-
framework: "EUnit",
|
|
207
|
-
},
|
|
208
|
-
{
|
|
209
|
-
marker: "gleam.toml",
|
|
210
|
-
stack: "Gleam",
|
|
211
|
-
testCommand: "gleam test",
|
|
212
|
-
framework: "gleam test",
|
|
213
|
-
},
|
|
214
|
-
{
|
|
215
|
-
marker: "deno.json",
|
|
216
|
-
stack: "Deno",
|
|
217
|
-
testCommand: "deno test",
|
|
218
|
-
framework: "deno test",
|
|
219
|
-
},
|
|
220
|
-
{
|
|
221
|
-
marker: "deno.jsonc",
|
|
222
|
-
stack: "Deno",
|
|
223
|
-
testCommand: "deno test",
|
|
224
|
-
framework: "deno test",
|
|
225
|
-
},
|
|
226
|
-
{
|
|
227
|
-
marker: "Gemfile",
|
|
228
|
-
stack: "Ruby",
|
|
229
|
-
testCommand: "bundle exec rake test",
|
|
230
|
-
framework: "Ruby test task",
|
|
231
|
-
},
|
|
232
|
-
{
|
|
233
|
-
marker: "composer.json",
|
|
234
|
-
stack: "PHP",
|
|
235
|
-
testCommand: "composer test",
|
|
236
|
-
framework: "Composer test script",
|
|
237
|
-
},
|
|
238
|
-
{
|
|
239
|
-
marker: "pom.xml",
|
|
240
|
-
stack: "Java/Maven",
|
|
241
|
-
testCommand: "mvn test",
|
|
242
|
-
framework: "Maven test",
|
|
243
|
-
},
|
|
244
|
-
{
|
|
245
|
-
marker: "build.gradle",
|
|
246
|
-
stack: "Java/Gradle",
|
|
247
|
-
testCommand: "./gradlew test",
|
|
248
|
-
framework: "Gradle test",
|
|
249
|
-
},
|
|
250
|
-
{
|
|
251
|
-
marker: "build.gradle.kts",
|
|
252
|
-
stack: "Java/Kotlin Gradle",
|
|
253
|
-
testCommand: "./gradlew test",
|
|
254
|
-
framework: "Gradle test",
|
|
255
|
-
},
|
|
256
|
-
{
|
|
257
|
-
marker: "pubspec.yaml",
|
|
258
|
-
stack: "Dart/Flutter",
|
|
259
|
-
testCommand: "dart test",
|
|
260
|
-
framework: "Dart test",
|
|
261
|
-
},
|
|
262
|
-
{
|
|
263
|
-
marker: "dune-project",
|
|
264
|
-
stack: "OCaml",
|
|
265
|
-
testCommand: "dune runtest",
|
|
266
|
-
framework: "Dune runtest",
|
|
267
|
-
},
|
|
268
|
-
{
|
|
269
|
-
marker: "shard.yml",
|
|
270
|
-
stack: "Crystal",
|
|
271
|
-
testCommand: "crystal spec",
|
|
272
|
-
framework: "Crystal spec",
|
|
273
|
-
},
|
|
274
|
-
{
|
|
275
|
-
marker: "stack.yaml",
|
|
276
|
-
stack: "Haskell",
|
|
277
|
-
testCommand: "stack test",
|
|
278
|
-
framework: "Stack test",
|
|
279
|
-
},
|
|
280
|
-
];
|
|
281
|
-
|
|
282
|
-
function setPrimaryTest(
|
|
283
|
-
detection: Detection,
|
|
284
|
-
command: CommandInfo,
|
|
285
|
-
prefer = false,
|
|
286
|
-
): void {
|
|
287
|
-
if (!detection.testCommand || prefer) {
|
|
288
|
-
detection.testCommand = command.command;
|
|
289
|
-
detection.testFramework = command.framework;
|
|
290
|
-
}
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
function packageDirs(files: string[]): string[] {
|
|
294
|
-
const dirs = files
|
|
295
|
-
.filter((file) => basename(file) === "package.json")
|
|
296
|
-
.map((file) => (dirname(file) === "." ? "." : dirname(file)));
|
|
297
|
-
return [...new Set(dirs)].sort(
|
|
298
|
-
(a, b) => a.split("/").length - b.split("/").length || a.localeCompare(b),
|
|
299
|
-
);
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
function filesInScope(files: string[], scope: string): string[] {
|
|
303
|
-
if (scope === ".") return files;
|
|
304
|
-
const prefix = `${scope}/`;
|
|
305
|
-
return files
|
|
306
|
-
.filter((file) => file.startsWith(prefix))
|
|
307
|
-
.map((file) => file.slice(prefix.length));
|
|
308
|
-
}
|
|
309
|
-
|
|
310
|
-
function detectNodePackage(
|
|
311
|
-
cwd: string,
|
|
312
|
-
files: string[],
|
|
313
|
-
scope: string,
|
|
314
|
-
detection: Detection,
|
|
315
|
-
): void {
|
|
316
|
-
const pkg = readJson<PackageJson>(join(cwd, scope, "package.json"));
|
|
317
|
-
if (!pkg) return;
|
|
318
|
-
const scopedFiles = filesInScope(files, scope);
|
|
319
|
-
const pm = detectPackageManagerAt(cwd, scope);
|
|
320
|
-
if (pm && !detection.packageManagers.includes(pm))
|
|
321
|
-
detection.packageManagers.push(pm);
|
|
322
|
-
addStack(
|
|
323
|
-
detection,
|
|
324
|
-
pkg.type === "module" ? "Node.js/TypeScript ESM" : "Node.js/TypeScript",
|
|
325
|
-
);
|
|
326
|
-
if (pkg.name && detection.projectName === basename(cwd))
|
|
327
|
-
detection.projectName = pkg.name;
|
|
328
|
-
addMarker(
|
|
329
|
-
detection,
|
|
330
|
-
scope === "." ? "package.json" : `${scope}/package.json`,
|
|
331
|
-
);
|
|
332
|
-
if (existsSync(join(cwd, scope, "tsconfig.json")))
|
|
333
|
-
addMarker(detection, `${scope === "." ? "" : `${scope}/`}tsconfig.json`);
|
|
334
|
-
if (pm)
|
|
335
|
-
addMarker(
|
|
336
|
-
detection,
|
|
337
|
-
`${scope === "." ? "" : `${scope}/`}${pm} package manager`,
|
|
338
|
-
);
|
|
339
|
-
|
|
340
|
-
const allDeps = deps(pkg);
|
|
341
|
-
if (allDeps.has("react")) addStack(detection, "React");
|
|
342
|
-
if (allDeps.has("next")) addStack(detection, "Next.js");
|
|
343
|
-
if (allDeps.has("vue")) addStack(detection, "Vue");
|
|
344
|
-
if (allDeps.has("svelte")) addStack(detection, "Svelte");
|
|
345
|
-
if (allDeps.has("@earendil-works/pi-coding-agent"))
|
|
346
|
-
addStack(detection, "Pi extension package");
|
|
347
|
-
|
|
348
|
-
let unit = scriptCommand(pm, pkg.scripts, [
|
|
349
|
-
"test:run",
|
|
350
|
-
"test",
|
|
351
|
-
"vitest",
|
|
352
|
-
"jest",
|
|
353
|
-
"unit",
|
|
354
|
-
]);
|
|
355
|
-
if (!unit) {
|
|
356
|
-
if (
|
|
357
|
-
allDeps.has("vitest") ||
|
|
358
|
-
scopedFiles.some((file) => /^vitest\.config\./.test(basename(file)))
|
|
359
|
-
) {
|
|
360
|
-
unit = { name: "vitest", command: runScript(pm, "vitest") };
|
|
361
|
-
} else if (
|
|
362
|
-
allDeps.has("jest") ||
|
|
363
|
-
scopedFiles.some((file) => /^jest\.config\./.test(basename(file)))
|
|
364
|
-
) {
|
|
365
|
-
unit = { name: "jest", command: runScript(pm, "jest") };
|
|
366
|
-
}
|
|
367
|
-
}
|
|
368
|
-
if (unit) {
|
|
369
|
-
const framework =
|
|
370
|
-
allDeps.has("vitest") || /vitest/i.test(unit.command)
|
|
371
|
-
? "Vitest"
|
|
372
|
-
: allDeps.has("jest") || /jest/i.test(unit.command)
|
|
373
|
-
? "Jest"
|
|
374
|
-
: "package script";
|
|
375
|
-
const info = {
|
|
376
|
-
scope,
|
|
377
|
-
command: commandInScope(scope, unit.command),
|
|
378
|
-
framework,
|
|
379
|
-
};
|
|
380
|
-
addUnique(detection.commands.unit, info);
|
|
381
|
-
setPrimaryTest(detection, info);
|
|
382
|
-
}
|
|
383
|
-
|
|
384
|
-
const integration = scriptCommand(pm, pkg.scripts, [
|
|
385
|
-
"test:integration",
|
|
386
|
-
"integration",
|
|
387
|
-
]);
|
|
388
|
-
if (integration)
|
|
389
|
-
addUnique(detection.commands.integration, {
|
|
390
|
-
scope,
|
|
391
|
-
command: commandInScope(scope, integration.command),
|
|
392
|
-
framework: "package integration script",
|
|
393
|
-
});
|
|
394
|
-
if (allDeps.has("@testing-library/react") || allDeps.has("supertest")) {
|
|
395
|
-
const framework = allDeps.has("supertest")
|
|
396
|
-
? "Supertest"
|
|
397
|
-
: "Testing Library";
|
|
398
|
-
if (unit)
|
|
399
|
-
addUnique(detection.commands.integration, {
|
|
400
|
-
scope,
|
|
401
|
-
command: commandInScope(scope, unit.command),
|
|
402
|
-
framework,
|
|
403
|
-
});
|
|
404
|
-
}
|
|
405
|
-
|
|
406
|
-
let e2e = scriptCommand(pm, pkg.scripts, [
|
|
407
|
-
"test:e2e",
|
|
408
|
-
"e2e",
|
|
409
|
-
"playwright",
|
|
410
|
-
"cypress",
|
|
411
|
-
]);
|
|
412
|
-
if (!e2e) {
|
|
413
|
-
if (
|
|
414
|
-
allDeps.has("@playwright/test") ||
|
|
415
|
-
allDeps.has("playwright") ||
|
|
416
|
-
scopedFiles.some((file) => /^playwright\.config\./.test(basename(file)))
|
|
417
|
-
) {
|
|
418
|
-
e2e = { name: "playwright", command: "npx playwright test" };
|
|
419
|
-
} else if (
|
|
420
|
-
allDeps.has("cypress") ||
|
|
421
|
-
scopedFiles.some((file) => /^cypress\.config\./.test(basename(file)))
|
|
422
|
-
) {
|
|
423
|
-
e2e = { name: "cypress", command: "npx cypress run" };
|
|
424
|
-
}
|
|
425
|
-
}
|
|
426
|
-
if (e2e) {
|
|
427
|
-
const framework = /cypress/i.test(e2e.command) ? "Cypress" : "Playwright";
|
|
428
|
-
addUnique(detection.commands.e2e, {
|
|
429
|
-
scope,
|
|
430
|
-
command: commandInScope(scope, e2e.command),
|
|
431
|
-
framework,
|
|
432
|
-
});
|
|
433
|
-
}
|
|
434
|
-
|
|
435
|
-
const coverage = scriptCommand(pm, pkg.scripts, [
|
|
436
|
-
"test:coverage",
|
|
437
|
-
"coverage",
|
|
438
|
-
]);
|
|
439
|
-
if (coverage)
|
|
440
|
-
addUnique(detection.commands.coverage, {
|
|
441
|
-
scope,
|
|
442
|
-
command: commandInScope(scope, coverage.command),
|
|
443
|
-
framework: "coverage",
|
|
444
|
-
});
|
|
445
|
-
const lint = scriptCommand(pm, pkg.scripts, [
|
|
446
|
-
"lint",
|
|
447
|
-
"lint:check",
|
|
448
|
-
"check:lint",
|
|
449
|
-
]);
|
|
450
|
-
if (lint)
|
|
451
|
-
addUnique(detection.commands.lint, {
|
|
452
|
-
scope,
|
|
453
|
-
command: commandInScope(scope, lint.command),
|
|
454
|
-
framework: "linter",
|
|
455
|
-
});
|
|
456
|
-
const typecheck = scriptCommand(pm, pkg.scripts, [
|
|
457
|
-
"typecheck",
|
|
458
|
-
"type-check",
|
|
459
|
-
"check:types",
|
|
460
|
-
]);
|
|
461
|
-
if (typecheck)
|
|
462
|
-
addUnique(detection.commands.typecheck, {
|
|
463
|
-
scope,
|
|
464
|
-
command: commandInScope(scope, typecheck.command),
|
|
465
|
-
framework: "type checker",
|
|
466
|
-
});
|
|
467
|
-
const format = scriptCommand(pm, pkg.scripts, [
|
|
468
|
-
"format",
|
|
469
|
-
"format:check",
|
|
470
|
-
"fmt",
|
|
471
|
-
"prettier",
|
|
472
|
-
]);
|
|
473
|
-
if (format)
|
|
474
|
-
addUnique(detection.commands.format, {
|
|
475
|
-
scope,
|
|
476
|
-
command: commandInScope(scope, format.command),
|
|
477
|
-
framework: "formatter",
|
|
478
|
-
});
|
|
479
|
-
}
|
|
480
|
-
|
|
481
|
-
function detectNode(cwd: string, files: string[], detection: Detection): void {
|
|
482
|
-
const dirs = packageDirs(files);
|
|
483
|
-
if (dirs.length === 0 && files.some((file) => /\.[cm]?[tj]sx?$/.test(file)))
|
|
484
|
-
addStack(detection, "Node.js/TypeScript");
|
|
485
|
-
for (const dir of dirs) detectNodePackage(cwd, files, dir, detection);
|
|
486
|
-
}
|
|
487
|
-
|
|
488
|
-
function detectGo(cwd: string, files: string[], detection: Detection): void {
|
|
489
|
-
if (!hasFile(cwd, "go.mod")) return;
|
|
490
|
-
addStack(detection, "Go");
|
|
491
|
-
addMarker(detection, "go.mod");
|
|
492
|
-
const info = { scope: ".", command: "go test ./...", framework: "go test" };
|
|
493
|
-
addUnique(detection.commands.unit, info);
|
|
494
|
-
setPrimaryTest(detection, info);
|
|
495
|
-
if (files.some((file) => file.endsWith("_test.go")))
|
|
496
|
-
addUnique(detection.commands.integration, {
|
|
497
|
-
scope: ".",
|
|
498
|
-
command: "go test ./...",
|
|
499
|
-
framework: "Go integration tests where present",
|
|
500
|
-
});
|
|
501
|
-
addUnique(detection.commands.coverage, {
|
|
502
|
-
scope: ".",
|
|
503
|
-
command: "go test -cover ./...",
|
|
504
|
-
framework: "go coverage",
|
|
505
|
-
});
|
|
506
|
-
}
|
|
507
|
-
|
|
508
|
-
function detectRust(cwd: string, detection: Detection): void {
|
|
509
|
-
if (!hasFile(cwd, "Cargo.toml")) return;
|
|
510
|
-
addStack(detection, "Rust");
|
|
511
|
-
addMarker(detection, "Cargo.toml");
|
|
512
|
-
const info = { scope: ".", command: "cargo test", framework: "cargo test" };
|
|
513
|
-
addUnique(detection.commands.unit, info);
|
|
514
|
-
setPrimaryTest(detection, info);
|
|
515
|
-
}
|
|
516
|
-
|
|
517
|
-
function detectPython(
|
|
518
|
-
cwd: string,
|
|
519
|
-
files: string[],
|
|
520
|
-
detection: Detection,
|
|
521
|
-
): void {
|
|
522
|
-
const hasPython =
|
|
523
|
-
hasFile(cwd, "pyproject.toml") ||
|
|
524
|
-
hasFile(cwd, "requirements.txt") ||
|
|
525
|
-
hasFile(cwd, "pytest.ini") ||
|
|
526
|
-
files.some((file) => file.endsWith(".py"));
|
|
527
|
-
if (!hasPython) return;
|
|
528
|
-
addStack(detection, "Python");
|
|
529
|
-
for (const marker of ["pyproject.toml", "requirements.txt", "pytest.ini"]) {
|
|
530
|
-
if (hasFile(cwd, marker)) addMarker(detection, marker);
|
|
531
|
-
}
|
|
532
|
-
if (
|
|
533
|
-
files.some(
|
|
534
|
-
(file) =>
|
|
535
|
-
file.startsWith("tests/") ||
|
|
536
|
-
file.endsWith("_test.py") ||
|
|
537
|
-
basename(file) === "conftest.py",
|
|
538
|
-
)
|
|
539
|
-
) {
|
|
540
|
-
const info = { scope: ".", command: "pytest", framework: "pytest" };
|
|
541
|
-
addUnique(detection.commands.unit, info);
|
|
542
|
-
setPrimaryTest(detection, info);
|
|
543
|
-
}
|
|
544
|
-
}
|
|
545
|
-
|
|
546
|
-
function detectGenericHints(
|
|
547
|
-
cwd: string,
|
|
548
|
-
files: string[],
|
|
549
|
-
detection: Detection,
|
|
550
|
-
): void {
|
|
551
|
-
for (const hint of GENERIC_HINTS) {
|
|
552
|
-
if (!hasFile(cwd, hint.marker)) continue;
|
|
553
|
-
addStack(detection, hint.stack);
|
|
554
|
-
addMarker(detection, hint.marker);
|
|
555
|
-
addEvidence(
|
|
556
|
-
detection,
|
|
557
|
-
`${hint.stack} manifest detected via ${hint.marker}`,
|
|
558
|
-
);
|
|
559
|
-
if (hint.testCommand && hint.framework) {
|
|
560
|
-
const info = {
|
|
561
|
-
scope: ".",
|
|
562
|
-
command: hint.testCommand,
|
|
563
|
-
framework: hint.framework,
|
|
564
|
-
};
|
|
565
|
-
addUnique(detection.commands.unit, info);
|
|
566
|
-
setPrimaryTest(detection, info);
|
|
567
|
-
}
|
|
568
|
-
}
|
|
569
|
-
|
|
570
|
-
const testFiles = files.filter(
|
|
571
|
-
(file) =>
|
|
572
|
-
/(^|\/)(test|tests|spec|specs)(\/|$)/i.test(file) ||
|
|
573
|
-
/[._-](test|spec)\.[^/]+$/i.test(file),
|
|
574
|
-
);
|
|
575
|
-
if (testFiles.length > 0) {
|
|
576
|
-
addEvidence(
|
|
577
|
-
detection,
|
|
578
|
-
`Test-like files detected (${testFiles.length}); examples: ${testFiles.slice(0, 5).join(", ")}`,
|
|
579
|
-
);
|
|
580
|
-
}
|
|
581
|
-
if (detection.stack.length === 0)
|
|
582
|
-
addStack(detection, "Unclassified software project");
|
|
583
|
-
}
|
|
584
|
-
|
|
585
|
-
function detectMakefile(cwd: string, detection: Detection): void {
|
|
586
|
-
const makefile = ["Makefile", "makefile"].find((file) => hasFile(cwd, file));
|
|
587
|
-
if (!makefile) return;
|
|
588
|
-
addMarker(detection, makefile);
|
|
589
|
-
let content = "";
|
|
590
|
-
try {
|
|
591
|
-
content = readFileSync(join(cwd, makefile), "utf8");
|
|
592
|
-
} catch {
|
|
593
|
-
return;
|
|
594
|
-
}
|
|
595
|
-
if (/^test:/m.test(content)) {
|
|
596
|
-
const info = {
|
|
597
|
-
scope: ".",
|
|
598
|
-
command: "make test",
|
|
599
|
-
framework: "pytest via Makefile",
|
|
600
|
-
};
|
|
601
|
-
addUnique(detection.commands.unit, info);
|
|
602
|
-
setPrimaryTest(detection, info, true);
|
|
603
|
-
}
|
|
604
|
-
if (/^coverage:/m.test(content))
|
|
605
|
-
addUnique(detection.commands.coverage, {
|
|
606
|
-
scope: ".",
|
|
607
|
-
command: "make coverage",
|
|
608
|
-
framework: "coverage",
|
|
609
|
-
});
|
|
610
|
-
if (/^lint:/m.test(content))
|
|
611
|
-
addUnique(detection.commands.lint, {
|
|
612
|
-
scope: ".",
|
|
613
|
-
command: "make lint",
|
|
614
|
-
framework: "linter",
|
|
615
|
-
});
|
|
616
|
-
if (/^(fmt|format):/m.test(content))
|
|
617
|
-
addUnique(detection.commands.format, {
|
|
618
|
-
scope: ".",
|
|
619
|
-
command: /^fmt:/m.test(content) ? "make fmt" : "make format",
|
|
620
|
-
framework: "formatter",
|
|
621
|
-
});
|
|
622
|
-
}
|
|
623
|
-
|
|
624
|
-
function detectProject(cwd: string): Detection {
|
|
625
|
-
const files = walkProject(cwd);
|
|
626
|
-
const detection: Detection = {
|
|
627
|
-
projectName: basename(cwd),
|
|
628
|
-
stack: [],
|
|
629
|
-
packageManagers: [],
|
|
630
|
-
markers: [],
|
|
631
|
-
evidence: [],
|
|
632
|
-
commands: {
|
|
633
|
-
unit: [],
|
|
634
|
-
integration: [],
|
|
635
|
-
e2e: [],
|
|
636
|
-
coverage: [],
|
|
637
|
-
lint: [],
|
|
638
|
-
typecheck: [],
|
|
639
|
-
format: [],
|
|
640
|
-
},
|
|
641
|
-
};
|
|
642
|
-
detectNode(cwd, files, detection);
|
|
643
|
-
detectGo(cwd, files, detection);
|
|
644
|
-
detectRust(cwd, detection);
|
|
645
|
-
detectPython(cwd, files, detection);
|
|
646
|
-
detectGenericHints(cwd, files, detection);
|
|
647
|
-
detectMakefile(cwd, detection);
|
|
648
|
-
if (hasFile(cwd, ".github/workflows")) addMarker(detection, "GitHub Actions");
|
|
649
|
-
detection.coverageCommand = detection.commands.coverage[0]?.command;
|
|
650
|
-
detection.lintCommand = detection.commands.lint[0]?.command;
|
|
651
|
-
detection.typecheckCommand = detection.commands.typecheck[0]?.command;
|
|
652
|
-
detection.formatCommand = detection.commands.format[0]?.command;
|
|
653
|
-
return detection;
|
|
654
|
-
}
|
|
655
|
-
|
|
656
|
-
function commandSummary(commands: CommandInfo[]): string {
|
|
657
|
-
if (commands.length === 0) return "none";
|
|
658
|
-
return commands
|
|
659
|
-
.map((command) => `${command.framework} (${command.command})`)
|
|
660
|
-
.join("; ");
|
|
661
|
-
}
|
|
662
|
-
|
|
663
|
-
function renderContext(detection: Detection): string {
|
|
664
|
-
const lines = [
|
|
665
|
-
`${detection.projectName} is a ${detection.stack.length > 0 ? detection.stack.join(", ") : "software"} project.`,
|
|
666
|
-
`Detected markers: ${detection.markers.length > 0 ? detection.markers.join(", ") : "none"}.`,
|
|
667
|
-
];
|
|
668
|
-
if (detection.packageManagers.length > 0)
|
|
669
|
-
lines.push(`Package managers: ${detection.packageManagers.join(", ")}.`);
|
|
670
|
-
if (detection.evidence.length > 0)
|
|
671
|
-
lines.push(`Additional evidence: ${detection.evidence.join("; ")}.`);
|
|
672
|
-
if (detection.testCommand)
|
|
673
|
-
lines.push(`Primary test command: ${detection.testCommand}.`);
|
|
674
|
-
else
|
|
675
|
-
lines.push(
|
|
676
|
-
"No reliable test runner was detected; verify testing manually before enabling strict TDD.",
|
|
677
|
-
);
|
|
678
|
-
lines.push(`Unit tests: ${commandSummary(detection.commands.unit)}.`);
|
|
679
|
-
lines.push(
|
|
680
|
-
`Integration tests: ${commandSummary(detection.commands.integration)}.`,
|
|
681
|
-
);
|
|
682
|
-
lines.push(`E2E tests: ${commandSummary(detection.commands.e2e)}.`);
|
|
683
|
-
return lines.join("\n");
|
|
684
|
-
}
|
|
685
|
-
|
|
686
|
-
function pushCommandList(
|
|
687
|
-
lines: string[],
|
|
688
|
-
indent: string,
|
|
689
|
-
commands: CommandInfo[],
|
|
690
|
-
): void {
|
|
691
|
-
if (commands.length === 0) {
|
|
692
|
-
lines.push(`${indent}[]`);
|
|
693
|
-
return;
|
|
694
|
-
}
|
|
695
|
-
for (const command of commands) {
|
|
696
|
-
lines.push(`${indent}- scope: ${yamlString(command.scope)}`);
|
|
697
|
-
lines.push(`${indent} command: ${yamlString(command.command)}`);
|
|
698
|
-
lines.push(`${indent} framework: ${yamlString(command.framework)}`);
|
|
699
|
-
}
|
|
700
|
-
}
|
|
701
|
-
|
|
702
|
-
function renderConfig(detection: Detection): string {
|
|
703
|
-
const strictTdd = Boolean(detection.testCommand);
|
|
704
|
-
const testCommand = detection.testCommand ?? "";
|
|
705
|
-
const today = new Date().toISOString().slice(0, 10);
|
|
706
|
-
const context = renderContext(detection);
|
|
707
|
-
const unitLayer = detection.commands.unit
|
|
708
|
-
.map((command) => command.framework)
|
|
709
|
-
.join(", ");
|
|
710
|
-
const integrationLayer = detection.commands.integration
|
|
711
|
-
.map((command) => command.framework)
|
|
712
|
-
.join(", ");
|
|
713
|
-
const e2eLayer = detection.commands.e2e
|
|
714
|
-
.map((command) => command.framework)
|
|
715
|
-
.join(", ");
|
|
716
|
-
const lines = [
|
|
717
|
-
`strict_tdd: ${strictTdd}`,
|
|
718
|
-
"context: |",
|
|
719
|
-
escapeBlockScalar(context),
|
|
720
|
-
"rules:",
|
|
721
|
-
" proposal:",
|
|
722
|
-
" require_problem_statement: true",
|
|
723
|
-
" spec:",
|
|
724
|
-
" require_acceptance_criteria: true",
|
|
725
|
-
" design:",
|
|
726
|
-
" require_tradeoffs: true",
|
|
727
|
-
" tasks:",
|
|
728
|
-
" protect_review_workload: true",
|
|
729
|
-
" apply:",
|
|
730
|
-
` test_command: ${yamlString(testCommand)}`,
|
|
731
|
-
" verify:",
|
|
732
|
-
` test_command: ${yamlString(testCommand)}`,
|
|
733
|
-
"testing:",
|
|
734
|
-
` detected: ${yamlString(today)}`,
|
|
735
|
-
" runner:",
|
|
736
|
-
` command: ${yamlString(testCommand)}`,
|
|
737
|
-
` framework: ${yamlString(detection.testFramework ?? "")}`,
|
|
738
|
-
" layers:",
|
|
739
|
-
` unit: ${yamlString(unitLayer)}`,
|
|
740
|
-
` integration: ${yamlString(integrationLayer)}`,
|
|
741
|
-
` e2e: ${yamlString(e2eLayer)}`,
|
|
742
|
-
" commands:",
|
|
743
|
-
" unit:",
|
|
744
|
-
];
|
|
745
|
-
pushCommandList(lines, " ", detection.commands.unit);
|
|
746
|
-
lines.push(" integration:");
|
|
747
|
-
pushCommandList(lines, " ", detection.commands.integration);
|
|
748
|
-
lines.push(" e2e:");
|
|
749
|
-
pushCommandList(lines, " ", detection.commands.e2e);
|
|
750
|
-
lines.push(" coverage:");
|
|
751
|
-
lines.push(` command: ${yamlString(detection.coverageCommand ?? "")}`);
|
|
752
|
-
lines.push(" commands:");
|
|
753
|
-
pushCommandList(lines, " ", detection.commands.coverage);
|
|
754
|
-
lines.push("quality:");
|
|
755
|
-
lines.push(` lint: ${yamlString(detection.lintCommand ?? "")}`);
|
|
756
|
-
lines.push(" lint_commands:");
|
|
757
|
-
pushCommandList(lines, " ", detection.commands.lint);
|
|
758
|
-
lines.push(` typecheck: ${yamlString(detection.typecheckCommand ?? "")}`);
|
|
759
|
-
lines.push(" typecheck_commands:");
|
|
760
|
-
pushCommandList(lines, " ", detection.commands.typecheck);
|
|
761
|
-
lines.push(` format: ${yamlString(detection.formatCommand ?? "")}`);
|
|
762
|
-
lines.push(" format_commands:");
|
|
763
|
-
pushCommandList(lines, " ", detection.commands.format);
|
|
764
|
-
lines.push("");
|
|
765
|
-
return lines.join("\n");
|
|
766
|
-
}
|
|
767
|
-
|
|
768
|
-
function ensureOpenSpecDirs(cwd: string): void {
|
|
769
|
-
mkdirSync(join(cwd, "openspec", "specs"), { recursive: true });
|
|
770
|
-
mkdirSync(join(cwd, "openspec", "changes", "archive"), { recursive: true });
|
|
771
|
-
}
|
|
772
|
-
|
|
773
|
-
export default function (pi: ExtensionAPI) {
|
|
774
|
-
pi.registerCommand("gentle-sdd-init", {
|
|
775
|
-
description:
|
|
776
|
-
"Auto-detect project stack and bootstrap openspec/config.yaml for SDD.",
|
|
777
|
-
handler: async (_args: unknown, ctx: any) => {
|
|
778
|
-
const prefs = await ensureSddPreflight(ctx, { pi, installAssets: (cwd) => installPackageAssets(cwd, true, ["sdd"]), applyModelConfig: () => applySavedModelConfig(ctx) }, { promptFields: [] });
|
|
779
|
-
|
|
780
|
-
const detection = detectProject(ctx.cwd);
|
|
781
|
-
const testSummary = detection.testCommand
|
|
782
|
-
? `strict TDD enabled with \`${detection.testCommand}\``
|
|
783
|
-
: "strict TDD disabled because no test runner was detected";
|
|
784
|
-
const layerSummary = `unit: ${detection.commands.unit.length}, integration: ${detection.commands.integration.length}, e2e: ${detection.commands.e2e.length}`;
|
|
785
|
-
|
|
786
|
-
const shouldCreateOpenSpec =
|
|
787
|
-
prefs.artifactStore === "openspec" ||
|
|
788
|
-
prefs.artifactStore === "hybrid";
|
|
789
|
-
if (!shouldCreateOpenSpec) {
|
|
790
|
-
ctx.ui.notify(
|
|
791
|
-
`SDD initialized for ${prefs.artifactStore}: detected ${detection.stack.join(", ") || "project"}; ${testSummary}; tests found: ${layerSummary}.`,
|
|
792
|
-
"info",
|
|
793
|
-
);
|
|
794
|
-
return;
|
|
795
|
-
}
|
|
796
|
-
|
|
797
|
-
const configPath = join(ctx.cwd, CONFIG_REL_PATH);
|
|
798
|
-
if (existsSync(configPath)) {
|
|
799
|
-
ctx.ui.notify(
|
|
800
|
-
`${CONFIG_REL_PATH} already exists. Edit it manually or remove it before re-running /gentle-sdd-init.`,
|
|
801
|
-
"warning",
|
|
802
|
-
);
|
|
803
|
-
return;
|
|
804
|
-
}
|
|
805
|
-
|
|
806
|
-
ensureOpenSpecDirs(ctx.cwd);
|
|
807
|
-
mkdirSync(dirname(configPath), { recursive: true });
|
|
808
|
-
writeFileSync(configPath, renderConfig(detection));
|
|
809
|
-
|
|
810
|
-
ctx.ui.notify(
|
|
811
|
-
`Wrote ${CONFIG_REL_PATH}: detected ${detection.stack.join(", ") || "project"}; ${testSummary}; tests found: ${layerSummary}.`,
|
|
812
|
-
"info",
|
|
813
|
-
);
|
|
814
|
-
},
|
|
815
|
-
});
|
|
816
|
-
}
|