@specdest/devkit 0.2.1 → 0.3.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.
Files changed (138) hide show
  1. package/README.md +15 -20
  2. package/package.json +4 -4
  3. package/src/canonical-project-operations.js +157 -0
  4. package/src/canonical-project.js +50 -0
  5. package/src/canonical-source.js +114 -0
  6. package/src/cli.js +2 -2
  7. package/src/git-catalog.js +105 -0
  8. package/src/index.js +6 -2
  9. package/src/project-operations.js +69 -9
  10. package/src/remote-installer.js +462 -0
  11. package/src/sync-core.js +26 -10
  12. package/catalog/README.md +0 -11
  13. package/catalog/modules/backend-convex/manifest.json +0 -14
  14. package/catalog/modules/backend-convex-expo/manifest.json +0 -11
  15. package/catalog/modules/backend-supabase/manifest.json +0 -15
  16. package/catalog/modules/backend-supabase-expo/manifest.json +0 -11
  17. package/catalog/modules/checker-runtime/config.ts +0 -25
  18. package/catalog/modules/checker-runtime/fs.ts +0 -48
  19. package/catalog/modules/checker-runtime/manifest.json +0 -28
  20. package/catalog/modules/checker-runtime/runtime.ts +0 -79
  21. package/catalog/modules/devflow/.agents/skills/devflow/SKILL.md +0 -33
  22. package/catalog/modules/devflow/.devflow.json +0 -10
  23. package/catalog/modules/devflow/manifest.json +0 -35
  24. package/catalog/modules/e2e-playwright/.agents/skills/e2e-playwright/SKILL.md +0 -85
  25. package/catalog/modules/e2e-playwright/.agents/skills/e2e-playwright/scripts/activeScenario.mjs +0 -130
  26. package/catalog/modules/e2e-playwright/.agents/skills/e2e-playwright/scripts/checkLocalEnvironment.mjs +0 -7
  27. package/catalog/modules/e2e-playwright/.agents/skills/e2e-playwright/scripts/completeActiveScenario.mjs +0 -36
  28. package/catalog/modules/e2e-playwright/.agents/skills/e2e-playwright/scripts/createActiveScenario.mjs +0 -143
  29. package/catalog/modules/e2e-playwright/.agents/skills/e2e-playwright/scripts/localEnvironment.mjs +0 -43
  30. package/catalog/modules/e2e-playwright/.agents/skills/e2e-playwright/scripts/prompt.mjs +0 -25
  31. package/catalog/modules/e2e-playwright/.agents/skills/e2e-playwright/scripts/runActiveScenario.mjs +0 -66
  32. package/catalog/modules/e2e-playwright/.agents/skills/e2e-playwright/scripts/runAuthoringScenario.mjs +0 -146
  33. package/catalog/modules/e2e-playwright/.agents/skills/e2e-playwright/scripts/seed.mjs +0 -56
  34. package/catalog/modules/e2e-playwright/.agents/skills/e2e-playwright/scripts/seedActiveScenario.mjs +0 -6
  35. package/catalog/modules/e2e-playwright/docs/e2e-playwright/README.md +0 -103
  36. package/catalog/modules/e2e-playwright/manifest.json +0 -206
  37. package/catalog/modules/e2e-playwright/playwright.e2e.config.ts +0 -39
  38. package/catalog/modules/e2e-playwright/tests/e2e/support/e2ePlaywrightFlow.ts +0 -107
  39. package/catalog/modules/e2e-playwright/tests/e2e/support/fixtures.ts +0 -27
  40. package/catalog/modules/local-log/AGENTS.local-log.md +0 -13
  41. package/catalog/modules/local-log/docs/features/local-logging/README.md +0 -70
  42. package/catalog/modules/local-log/manifest.json +0 -39
  43. package/catalog/modules/local-log/tmp/logs/.gitignore +0 -2
  44. package/catalog/modules/local-log/tools/local-log/README.md +0 -47
  45. package/catalog/modules/local-log/tools/local-log/local-log.mjs +0 -241
  46. package/catalog/modules/stack-common-vite/manifest.json +0 -16
  47. package/catalog/modules/stack-expo-convex/manifest.json +0 -31
  48. package/catalog/modules/stack-expo-supabase/manifest.json +0 -44
  49. package/catalog/modules/stack-vite-convex/manifest.json +0 -32
  50. package/catalog/modules/stack-vite-supabase/manifest.json +0 -45
  51. package/catalog/rules/abac-permissions-convex/SKILL.md +0 -17
  52. package/catalog/rules/abac-permissions-convex/check.ts +0 -87
  53. package/catalog/rules/abac-permissions-convex/manifest.json +0 -33
  54. package/catalog/rules/abac-permissions-supabase/SKILL.md +0 -17
  55. package/catalog/rules/abac-permissions-supabase/check.ts +0 -87
  56. package/catalog/rules/abac-permissions-supabase/manifest.json +0 -33
  57. package/catalog/rules/convex-multi-presentation/SKILL.md +0 -47
  58. package/catalog/rules/convex-multi-presentation/check.ts +0 -205
  59. package/catalog/rules/convex-multi-presentation/manifest.json +0 -47
  60. package/catalog/rules/convex-multi-presentation/policy.ts +0 -261
  61. package/catalog/rules/design-rules/SKILL.md +0 -12
  62. package/catalog/rules/design-rules/check.ts +0 -84
  63. package/catalog/rules/design-rules/config.json +0 -5
  64. package/catalog/rules/design-rules/manifest.json +0 -38
  65. package/catalog/rules/e2e-test-rules/SKILL.md +0 -46
  66. package/catalog/rules/e2e-test-rules/check.ts +0 -145
  67. package/catalog/rules/e2e-test-rules/config.json +0 -32
  68. package/catalog/rules/e2e-test-rules/manifest.json +0 -38
  69. package/catalog/rules/error-handling-rules/SKILL.md +0 -21
  70. package/catalog/rules/error-handling-rules/check.ts +0 -73
  71. package/catalog/rules/error-handling-rules/manifest.json +0 -33
  72. package/catalog/rules/layers-and-contracts/SKILL.md +0 -36
  73. package/catalog/rules/layers-and-contracts/check.ts +0 -266
  74. package/catalog/rules/layers-and-contracts/manifest.json +0 -33
  75. package/catalog/rules/layers-and-contracts-convex/SKILL.md +0 -49
  76. package/catalog/rules/layers-and-contracts-convex/check.ts +0 -289
  77. package/catalog/rules/layers-and-contracts-convex/manifest.json +0 -38
  78. package/catalog/rules/layers-and-contracts-convex/policy.ts +0 -68
  79. package/catalog/rules/layers-and-contracts-supabase/SKILL.md +0 -52
  80. package/catalog/rules/layers-and-contracts-supabase/check.ts +0 -371
  81. package/catalog/rules/layers-and-contracts-supabase/manifest.json +0 -38
  82. package/catalog/rules/layers-and-contracts-supabase/policy.ts +0 -68
  83. package/catalog/rules/module-size-rules/SKILL.md +0 -5
  84. package/catalog/rules/module-size-rules/check.ts +0 -144
  85. package/catalog/rules/module-size-rules/config.json +0 -6
  86. package/catalog/rules/module-size-rules/manifest.json +0 -38
  87. package/catalog/rules/module-size-rules-convex/SKILL.md +0 -5
  88. package/catalog/rules/module-size-rules-convex/check.ts +0 -146
  89. package/catalog/rules/module-size-rules-convex/config.json +0 -6
  90. package/catalog/rules/module-size-rules-convex/manifest.json +0 -38
  91. package/catalog/rules/module-size-rules-supabase/SKILL.md +0 -5
  92. package/catalog/rules/module-size-rules-supabase/check.ts +0 -146
  93. package/catalog/rules/module-size-rules-supabase/config.json +0 -12
  94. package/catalog/rules/module-size-rules-supabase/manifest.json +0 -38
  95. package/catalog/rules/mutation-command-rules/SKILL.md +0 -15
  96. package/catalog/rules/mutation-command-rules/check.ts +0 -30
  97. package/catalog/rules/mutation-command-rules/config.json +0 -19
  98. package/catalog/rules/mutation-command-rules/manifest.json +0 -38
  99. package/catalog/rules/nearby-contracts/SKILL.md +0 -18
  100. package/catalog/rules/nearby-contracts/check.ts +0 -138
  101. package/catalog/rules/nearby-contracts/config.json +0 -10
  102. package/catalog/rules/nearby-contracts/manifest.json +0 -38
  103. package/catalog/rules/no-raw-click-buttons/SKILL.md +0 -5
  104. package/catalog/rules/no-raw-click-buttons/check.ts +0 -37
  105. package/catalog/rules/no-raw-click-buttons/manifest.json +0 -33
  106. package/catalog/rules/public-api-export-barrels/SKILL.md +0 -45
  107. package/catalog/rules/public-api-export-barrels/check.ts +0 -73
  108. package/catalog/rules/public-api-export-barrels/config.json +0 -4
  109. package/catalog/rules/public-api-export-barrels/manifest.json +0 -38
  110. package/catalog/rules/route-tree-fresh/SKILL.md +0 -16
  111. package/catalog/rules/route-tree-fresh/check.ts +0 -66
  112. package/catalog/rules/route-tree-fresh/manifest.json +0 -33
  113. package/catalog/rules/strict-typescript/SKILL.md +0 -3
  114. package/catalog/rules/strict-typescript/check.ts +0 -119
  115. package/catalog/rules/strict-typescript/manifest.json +0 -33
  116. package/catalog/rules/supabase-contracts/SKILL.md +0 -3
  117. package/catalog/rules/supabase-contracts/check.ts +0 -172
  118. package/catalog/rules/supabase-contracts/manifest.json +0 -33
  119. package/catalog/rules/supabase-declarative-schema/SKILL.md +0 -30
  120. package/catalog/rules/supabase-declarative-schema/check.ts +0 -262
  121. package/catalog/rules/supabase-declarative-schema/config.json +0 -8
  122. package/catalog/rules/supabase-declarative-schema/manifest.json +0 -38
  123. package/catalog/rules/tanstack-form-rules/SKILL.md +0 -11
  124. package/catalog/rules/tanstack-form-rules/check.ts +0 -58
  125. package/catalog/rules/tanstack-form-rules/manifest.json +0 -33
  126. package/catalog/rules/unit-test-rules/SKILL.md +0 -55
  127. package/catalog/rules/unit-test-rules/check.ts +0 -132
  128. package/catalog/rules/unit-test-rules/config.json +0 -22
  129. package/catalog/rules/unit-test-rules/manifest.json +0 -38
  130. package/catalog/rules/unit-test-rules-convex/SKILL.md +0 -41
  131. package/catalog/rules/unit-test-rules-convex/check.ts +0 -418
  132. package/catalog/rules/unit-test-rules-convex/manifest.json +0 -33
  133. package/catalog/rules/unit-test-rules-supabase/SKILL.md +0 -40
  134. package/catalog/rules/unit-test-rules-supabase/check.ts +0 -492
  135. package/catalog/rules/unit-test-rules-supabase/manifest.json +0 -33
  136. package/catalog/rules/workstation-controller-rules/SKILL.md +0 -22
  137. package/catalog/rules/workstation-controller-rules/check.ts +0 -108
  138. package/catalog/rules/workstation-controller-rules/manifest.json +0 -33
@@ -1,28 +0,0 @@
1
- {
2
- "id": "checker-runtime",
3
- "kind": "module",
4
- "version": "2.0.0",
5
- "artifacts": [
6
- {
7
- "kind": "managed-file",
8
- "path": ".agents/skills/shared/runtime.ts",
9
- "source": "runtime.ts"
10
- },
11
- {
12
- "kind": "managed-file",
13
- "path": ".agents/skills/shared/fs.ts",
14
- "source": "fs.ts"
15
- },
16
- {
17
- "kind": "managed-file",
18
- "path": ".agents/skills/shared/config.ts",
19
- "source": "config.ts"
20
- },
21
- {
22
- "kind": "shared-line",
23
- "path": ".gitignore",
24
- "line": ".specdest/checks.json"
25
- }
26
- ],
27
- "obsolete": []
28
- }
@@ -1,79 +0,0 @@
1
- import { readFile as readFileNode, readdir, stat as statNode } from "node:fs/promises";
2
- import process from "node:process";
3
-
4
- export class NotFoundError extends Error {
5
- constructor(path: string) {
6
- super(`No such file or directory: ${path}`);
7
- this.name = "NotFoundError";
8
- }
9
- }
10
-
11
- function translateNotFound(error: unknown, path: string): never {
12
- if (
13
- error instanceof Error &&
14
- "code" in error &&
15
- (error as NodeJS.ErrnoException).code === "ENOENT"
16
- ) {
17
- throw new NotFoundError(path);
18
- }
19
- throw error;
20
- }
21
-
22
- async function stat(path: string) {
23
- try {
24
- return await statNode(path);
25
- } catch (error) {
26
- return translateNotFound(error, path);
27
- }
28
- }
29
-
30
- async function readFile(path: string | URL): Promise<Uint8Array> {
31
- try {
32
- return await readFileNode(path);
33
- } catch (error) {
34
- return translateNotFound(error, String(path));
35
- }
36
- }
37
-
38
- async function readTextFile(path: string | URL): Promise<string> {
39
- try {
40
- return await readFileNode(path, "utf8");
41
- } catch (error) {
42
- return translateNotFound(error, String(path));
43
- }
44
- }
45
-
46
- async function* readDir(path: string) {
47
- let entries;
48
- try {
49
- entries = await readdir(path, { withFileTypes: true });
50
- } catch (error) {
51
- return translateNotFound(error, path);
52
- }
53
- for (const entry of entries) {
54
- yield {
55
- name: entry.name,
56
- isFile: entry.isFile(),
57
- isDirectory: entry.isDirectory(),
58
- isSymlink: entry.isSymbolicLink(),
59
- };
60
- }
61
- }
62
-
63
- function writeSync(stream: NodeJS.WriteStream, data: Uint8Array): number {
64
- stream.write(data);
65
- return data.byteLength;
66
- }
67
-
68
- export const runtime = {
69
- args: process.argv.slice(2),
70
- cwd: () => process.cwd(),
71
- exit: (code = 0): never => process.exit(code),
72
- stat,
73
- readFile,
74
- readTextFile,
75
- readDir,
76
- stdout: { writeSync: (data: Uint8Array) => writeSync(process.stdout, data) },
77
- stderr: { writeSync: (data: Uint8Array) => writeSync(process.stderr, data) },
78
- errors: { NotFound: NotFoundError },
79
- } as const;
@@ -1,33 +0,0 @@
1
- ---
2
- name: devflow
3
- description: Guidance for using DevFlow task lifecycle prompts and artifacts.
4
- ---
5
-
6
- # DevFlow lifecycle prompts
7
-
8
- DevFlow manages project-local task state and generates the current coding prompt. It does not launch or control a coding agent.
9
-
10
- ## Workflow
11
-
12
- 1. Open the project in the Chrome extension and create a task.
13
- 2. Copy the current prompt into the coding agent of your choice.
14
- 3. Save only the artifact editable in the current state.
15
- 4. Submit and approve requirements and plan artifacts through the UI.
16
- 5. Use the TDD and implementation prompts manually.
17
- 6. Run fast checks only during TDD or implementation.
18
- 7. Run full validation only after entering `VALIDATION`.
19
- 8. Save the final report and complete the task.
20
-
21
- ## Artifact locking
22
-
23
- - `requirements.md` is editable only in `REQUIREMENTS`.
24
- - `plan.md` is editable only in `PLAN`.
25
- - `report.md`, `follow-ups.md`, and `learning.md` are editable only in `REPORT`.
26
- - `validation.json` is controller-owned and read-only.
27
- - Approval locks requirements or plan content. Rejection reopens the relevant artifact.
28
-
29
- Task workspaces are stored under `tasks/<task-id>/`. They are temporary but intentionally versioned while active. Keep lifecycle artifacts, metadata, event history, prompt overrides, follow-ups, learning notes, structured evidence, and useful Markdown notes. Raw files under `logs/` are local-only runtime output.
30
-
31
- Do not discard useful midpoint evidence merely because the workflow advanced. During report, write future improvements to `follow-ups.md`, reusable session learning to `learning.md`, and evidence summaries under `evidence/`. During documentation and completion, move durable knowledge into permanent project docs, decisions, rules, lessons, improvements, or testing gaps. Delete the task folder only after the task is completed and that transfer is recorded.
32
-
33
- Project validation commands are allowlisted in `.devflow.json` as argument arrays. Do not bypass approval gates, edit `state.json` manually, call the controller's `state-write` command directly, or treat generated prompts as ordinary saved prompts.
@@ -1,10 +0,0 @@
1
- {
2
- "schemaVersion": 1,
3
- "rulesFiles": [
4
- "AGENTS.md"
5
- ],
6
- "checks": {
7
- "fast": [],
8
- "full": []
9
- }
10
- }
@@ -1,35 +0,0 @@
1
- {
2
- "id": "devflow",
3
- "kind": "module",
4
- "version": "1.2.0",
5
- "artifacts": [
6
- {
7
- "kind": "managed-file",
8
- "path": ".agents/skills/devflow/SKILL.md",
9
- "source": ".agents/skills/devflow/SKILL.md"
10
- },
11
- {
12
- "kind": "scaffold",
13
- "path": ".devflow.json",
14
- "source": ".devflow.json"
15
- },
16
- {
17
- "kind": "shared-line",
18
- "path": ".gitignore",
19
- "line": "/tasks/*/logs/"
20
- },
21
- {
22
- "kind": "shared-markdown-section",
23
- "path": "AGENTS.md",
24
- "heading": "## DevFlow task lifecycle",
25
- "body": "Use `.agents/skills/devflow/SKILL.md` for DevFlow-managed tasks. Respect lifecycle states and approval gates. Keep task evidence versioned while active, ignore only raw `tasks/*/logs/`, promote durable knowledge before completion, and configure project validation in `.devflow.json`."
26
- }
27
- ],
28
- "obsolete": [
29
- {
30
- "kind": "shared-line",
31
- "path": ".gitignore",
32
- "line": "/tasks/"
33
- }
34
- ]
35
- }
@@ -1,85 +0,0 @@
1
- # E2E Playwright
2
-
3
- Use this skill when creating or maintaining generic Playwright E2E scenarios for a local web application.
4
-
5
- ## Goal
6
-
7
- Turn a rough user flow into a deterministic, repeatable Playwright test using project-owned seed data and named UI steps.
8
-
9
- ## Workflow
10
-
11
- ```txt
12
- 1. Create one active scenario.
13
- 2. Confirm the target app URL is local-only.
14
- 3. Fill intent.md with the business flow.
15
- 4. Implement seed.mjs with deterministic project-owned data setup.
16
- 5. Implement flow.script.ts with named Playwright steps.
17
- 6. Run authoring mode with --until or --pause-after.
18
- 7. Fix one step at a time.
19
- 8. Verify from seed and step 0.
20
- 9. Complete the scenario when stable.
21
- ```
22
-
23
- ## Commands
24
-
25
- ```bash
26
- nps "e2e.playwright.0CreateActiveScenario -- <scenario-id>"
27
- nps e2e.playwright.1CheckLocal
28
- nps e2e.playwright.2SeedActiveScenario
29
- nps e2e.playwright.5RunAuthoring
30
- nps "e2e.playwright.5RunAuthoring -- --until <step-name>"
31
- nps "e2e.playwright.5RunAuthoring -- --pause-after <step-name>"
32
- nps e2e.playwright.3RunActiveScenario
33
- nps "e2e.playwright.4CompleteActiveScenario -- <scenario-id>"
34
- ```
35
-
36
- Direct npm-script aliases may exist in projects without NPS/package-scripts.
37
-
38
- ## Scenario folders
39
-
40
- Active:
41
-
42
- ```txt
43
- tests/e2e/_active/<scenario-id>/
44
- ```
45
-
46
- Completed:
47
-
48
- ```txt
49
- tests/e2e/scenarios/<scenario-id>/
50
- ```
51
-
52
- Only one active scenario is allowed at a time.
53
-
54
- ## Local-only safety
55
-
56
- This skill must only use local app URLs:
57
-
58
- ```txt
59
- http://127.0.0.1:5173
60
- http://localhost:5173
61
- http://[::1]:5173
62
- ```
63
-
64
- Override with `E2E_BASE_URL`. The guard refuses non-local hosts and production `APP_ENV` / `NODE_ENV`.
65
-
66
- ## Seed rules
67
-
68
- - `seed.mjs` is project-owned and may call project seed scripts or local DB tools.
69
- - Keep seed deterministic and idempotent.
70
- - Delete/reset only scenario-owned data.
71
- - Do not connect to production services.
72
- - Export `verifySeed(context)` when the seed needs a pre-browser assertion.
73
-
74
- ## Flow script rules
75
-
76
- - `flow.script.ts` is the action recipe.
77
- - Use accessible locators first: role, label, placeholder, text.
78
- - Keep steps small and named.
79
- - Step names are used by `--until` and `--pause-after`.
80
- - Scope selectors to avoid strict-mode ambiguity.
81
- - Remove exploratory pauses before completing the scenario.
82
-
83
- ## Agent/controller boundary
84
-
85
- Agents may edit scenario files, inspect code, and reason about failures. Do not start long-running app servers or Playwright browser runs from tooling/controller unless the user explicitly accepts that execution boundary. Prefer user terminal for app servers and final browser verification.
@@ -1,130 +0,0 @@
1
- import { existsSync } from "node:fs";
2
- import { mkdir, readdir, readFile, rename, writeFile } from "node:fs/promises";
3
- import path from "node:path";
4
- import { fileURLToPath } from "node:url";
5
-
6
- export const repoRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "../../../..");
7
- export const e2eRoot = path.join(repoRoot, "tests", "e2e");
8
- export const activeScenariosRoot = path.join(e2eRoot, "_active");
9
- export const completedScenariosRoot = path.join(e2eRoot, "scenarios");
10
- export const defaultStartPath = "/";
11
-
12
- export function toRepoRelative(absolutePath) {
13
- return path.relative(repoRoot, absolutePath);
14
- }
15
-
16
- export function getCliArg(index = 0) {
17
- const args = process.argv.slice(2).filter((arg) => arg !== "--");
18
- return args[index];
19
- }
20
-
21
- export function toScenarioId(input) {
22
- const id = input
23
- .trim()
24
- .replace(/([a-z0-9])([A-Z])/g, "$1-$2")
25
- .toLowerCase()
26
- .replace(/[^a-z0-9]+/g, "-")
27
- .replace(/^-+|-+$/g, "");
28
-
29
- assertScenarioId(id);
30
- return id;
31
- }
32
-
33
- export function assertScenarioId(id) {
34
- if (!/^[a-z0-9][a-z0-9-]*[a-z0-9]$|^[a-z0-9]$/.test(id)) {
35
- throw new Error(
36
- `Invalid scenario id "${id}". Use lowercase letters, numbers, and dashes only.`,
37
- );
38
- }
39
-
40
- if (id.includes("..")) {
41
- throw new Error(`Invalid scenario id "${id}". Parent directory references are not allowed.`);
42
- }
43
- }
44
-
45
- export function scenarioPaths(id, baseDir = activeScenariosRoot) {
46
- assertScenarioId(id);
47
- const root = path.join(baseDir, id);
48
- const specsDir = path.join(root, "specs");
49
-
50
- return {
51
- id,
52
- root,
53
- intentPath: path.join(root, "intent.md"),
54
- authoringPath: path.join(root, "authoring.md"),
55
- startUrlPath: path.join(root, "start-url.txt"),
56
- seedPath: path.join(root, "seed.mjs"),
57
- flowScriptPath: path.join(root, "flow.script.ts"),
58
- specsDir,
59
- artifactsDir: path.join(root, "artifacts"),
60
- specPath: path.join(specsDir, `${id}.spec.ts`),
61
- };
62
- }
63
-
64
- export async function ensureScenarioRoots() {
65
- await mkdir(activeScenariosRoot, { recursive: true });
66
- await mkdir(completedScenariosRoot, { recursive: true });
67
- }
68
-
69
- export async function listScenarioIds(root) {
70
- if (!existsSync(root)) return [];
71
- const entries = await readdir(root, { withFileTypes: true });
72
- return entries
73
- .filter((entry) => entry.isDirectory() && !entry.name.startsWith("."))
74
- .map((entry) => entry.name)
75
- .sort();
76
- }
77
-
78
- export async function getOptionalActiveScenario() {
79
- await ensureScenarioRoots();
80
- const ids = await listScenarioIds(activeScenariosRoot);
81
- if (ids.length === 0) return null;
82
- if (ids.length > 1) {
83
- throw new Error(
84
- `Expected at most one active E2E scenario, found ${ids.length}: ${ids.join(", ")}`,
85
- );
86
- }
87
- return scenarioPaths(ids[0]);
88
- }
89
-
90
- export async function getRequiredActiveScenario() {
91
- const scenario = await getOptionalActiveScenario();
92
- if (!scenario) {
93
- throw new Error(
94
- "No active E2E scenario found. Create one with `nps e2e.playwright.0CreateActiveScenario -- <scenario-id>`.",
95
- );
96
- }
97
- return scenario;
98
- }
99
-
100
- export async function ensureScenarioDirectories(paths) {
101
- await mkdir(paths.root, { recursive: true });
102
- await mkdir(paths.specsDir, { recursive: true });
103
- await mkdir(paths.artifactsDir, { recursive: true });
104
- }
105
-
106
- export async function writeIfMissing(filePath, content) {
107
- if (existsSync(filePath)) return false;
108
- await mkdir(path.dirname(filePath), { recursive: true });
109
- await writeFile(filePath, content, "utf8");
110
- return true;
111
- }
112
-
113
- export async function readTextIfExists(filePath) {
114
- if (!existsSync(filePath)) return null;
115
- return readFile(filePath, "utf8");
116
- }
117
-
118
- export async function moveActiveScenarioToCompleted(active, completedId) {
119
- const completed = scenarioPaths(completedId, completedScenariosRoot);
120
- if (existsSync(completed.root)) {
121
- throw new Error(`Completed scenario already exists: ${toRepoRelative(completed.root)}`);
122
- }
123
- await mkdir(path.dirname(completed.root), { recursive: true });
124
- await rename(active.root, completed.root);
125
- return completed;
126
- }
127
-
128
- export function requireFile(filePath, message) {
129
- if (!existsSync(filePath)) throw new Error(message);
130
- }
@@ -1,7 +0,0 @@
1
- import { assertLocalEnvironment } from "./localEnvironment.mjs";
2
-
3
- const requireFrontend = process.argv.includes("--frontend") || true;
4
- const config = await assertLocalEnvironment({ requireFrontend });
5
-
6
- console.log("E2E Playwright environment is local-only.");
7
- console.log(`Base URL: ${config.baseUrl}`);
@@ -1,36 +0,0 @@
1
- import { existsSync } from "node:fs";
2
- import { rename } from "node:fs/promises";
3
- import path from "node:path";
4
- import {
5
- getCliArg,
6
- getRequiredActiveScenario,
7
- moveActiveScenarioToCompleted,
8
- requireFile,
9
- toRepoRelative,
10
- toScenarioId,
11
- } from "./activeScenario.mjs";
12
- import { promptText } from "./prompt.mjs";
13
-
14
- const active = await getRequiredActiveScenario();
15
- const rawCompletedId =
16
- getCliArg() ??
17
- process.env.E2E_PLAYWRIGHT_COMPLETED_SCENARIO_ID ??
18
- (await promptText({ label: "Completed E2E scenario id", defaultValue: active.id }));
19
- const completedId = toScenarioId(rawCompletedId);
20
-
21
- requireFile(active.seedPath, `Missing seed: ${toRepoRelative(active.seedPath)}.`);
22
- requireFile(
23
- active.flowScriptPath,
24
- `Missing flow script: ${toRepoRelative(active.flowScriptPath)}.`,
25
- );
26
- requireFile(active.specPath, `Missing spec: ${toRepoRelative(active.specPath)}.`);
27
-
28
- const completed = await moveActiveScenarioToCompleted(active, completedId);
29
-
30
- if (completedId !== active.id) {
31
- const oldSpecPath = path.join(completed.specsDir, `${active.id}.spec.ts`);
32
- const newSpecPath = completed.specPath;
33
- if (existsSync(oldSpecPath) && !existsSync(newSpecPath)) await rename(oldSpecPath, newSpecPath);
34
- }
35
-
36
- console.log(`Completed E2E scenario: ${toRepoRelative(completed.root)}`);
@@ -1,143 +0,0 @@
1
- import { existsSync } from "node:fs";
2
- import {
3
- activeScenariosRoot,
4
- completedScenariosRoot,
5
- defaultStartPath,
6
- ensureScenarioDirectories,
7
- getCliArg,
8
- getOptionalActiveScenario,
9
- scenarioPaths,
10
- toRepoRelative,
11
- toScenarioId,
12
- writeIfMissing,
13
- } from "./activeScenario.mjs";
14
- import { promptText } from "./prompt.mjs";
15
-
16
- const rawScenarioId =
17
- getCliArg() ??
18
- process.env.E2E_PLAYWRIGHT_SCENARIO_ID ??
19
- (await promptText({ label: "Active E2E scenario id", required: true }));
20
-
21
- const existing = await getOptionalActiveScenario();
22
- if (existing) {
23
- console.log(`Active E2E scenario already exists: ${toRepoRelative(existing.root)}`);
24
- console.log("Finish or remove that scenario before creating another one.");
25
- process.exit(0);
26
- }
27
-
28
- const id = toScenarioId(rawScenarioId);
29
- const paths = scenarioPaths(id, activeScenariosRoot);
30
- const completedPath = scenarioPaths(id, completedScenariosRoot).root;
31
-
32
- if (existsSync(completedPath)) {
33
- console.error(`Completed scenario already exists: ${toRepoRelative(completedPath)}`);
34
- process.exit(2);
35
- }
36
-
37
- await ensureScenarioDirectories(paths);
38
-
39
- await writeIfMissing(paths.intentPath, intentTemplate(id));
40
- await writeIfMissing(paths.authoringPath, authoringTemplate(id));
41
- await writeIfMissing(paths.startUrlPath, `${defaultStartPath}\n`);
42
- await writeIfMissing(paths.seedPath, seedTemplate());
43
- await writeIfMissing(paths.flowScriptPath, flowScriptTemplate());
44
- await writeIfMissing(paths.specPath, specTemplate(id));
45
- await writeIfMissing(`${paths.artifactsDir}/.gitkeep`, "");
46
-
47
- console.log(`Created active E2E scenario: ${toRepoRelative(paths.root)}`);
48
- console.log("Next: fill intent.md, seed.mjs, and flow.script.ts, then run authoring mode.");
49
-
50
- function intentTemplate(scenarioId) {
51
- return [
52
- `# ${scenarioId}`,
53
- "",
54
- "## Rough user intent",
55
- "",
56
- "Describe the user-facing behavior this E2E scenario must prove.",
57
- "",
58
- "## Deterministic starting data",
59
- "",
60
- "List the scenario-owned data that seed.mjs must create/reset.",
61
- "",
62
- "## Expected final behavior",
63
- "",
64
- "Describe the visible UI results and any expected data changes.",
65
- "",
66
- ].join("\n");
67
- }
68
-
69
- function authoringTemplate(scenarioId) {
70
- return [
71
- `# ${scenarioId} authoring log`,
72
- "",
73
- "Use this while authoring the flow step by step.",
74
- "",
75
- "## Loop",
76
- "",
77
- "1. Read app code and identify route, labels, and user actions.",
78
- "2. Write or update one/few flow steps.",
79
- "3. Run authoring mode with --until or --pause-after.",
80
- "4. Observe UI state and errors.",
81
- "5. Update flow.script.ts.",
82
- "6. Remove exploratory/noise steps.",
83
- "7. Verify from clean seed and step 0.",
84
- "",
85
- ].join("\n");
86
- }
87
-
88
- function seedTemplate() {
89
- return [
90
- "export async function seedScenario({ projectRoot, scenario, now, executeCommand }) {",
91
- " // Keep this deterministic and idempotent.",
92
- " // Use project-owned local seed scripts or local DB tooling here.",
93
- " // Do not touch production services.",
94
- " //",
95
- " // Example:",
96
- ' // await executeCommand("node", ["scripts/seed-e2e.mjs", scenario.id], { cwd: projectRoot });',
97
- "",
98
- " void projectRoot;",
99
- " void scenario;",
100
- " void now;",
101
- " void executeCommand;",
102
- "}",
103
- "",
104
- "export async function verifySeed({ scenario }) {",
105
- " // Optional: assert seeded records exist before the browser flow starts.",
106
- " void scenario;",
107
- "}",
108
- "",
109
- ].join("\n");
110
- }
111
-
112
- function flowScriptTemplate() {
113
- return [
114
- 'import { expect } from "@playwright/test";',
115
- 'import { step, type E2EPlaywrightFlow } from "../../support/e2ePlaywrightFlow";',
116
- "",
117
- "export const flow = [",
118
- ' step("open start page", async ({ page }) => {',
119
- ` await page.goto("${defaultStartPath}");`,
120
- " }),",
121
- "",
122
- ' step("assert page loaded", async ({ page }) => {',
123
- ' await expect(page.locator("body")).toBeVisible();',
124
- " }),",
125
- "] satisfies E2EPlaywrightFlow;",
126
- "",
127
- ].join("\n");
128
- }
129
-
130
- function specTemplate(scenarioId) {
131
- return [
132
- 'import { test } from "../../../support/fixtures";',
133
- 'import { e2ePlaywrightFlowOptionsFromEnv, runE2EPlaywrightFlow } from "../../../support/e2ePlaywrightFlow";',
134
- 'import { flow } from "../flow.script";',
135
- "",
136
- `test.describe("${scenarioId}", () => {`,
137
- ' test("runs the E2E flow", async ({ context, page }, testInfo) => {',
138
- " await runE2EPlaywrightFlow(flow, { context, page, testInfo }, e2ePlaywrightFlowOptionsFromEnv());",
139
- " });",
140
- "});",
141
- "",
142
- ].join("\n");
143
- }
@@ -1,43 +0,0 @@
1
- export async function assertLocalEnvironment(input = {}) {
2
- if (process.env.APP_ENV === "production") {
3
- throw new Error("Refusing E2E Playwright run with APP_ENV=production.");
4
- }
5
- if (process.env.NODE_ENV === "production") {
6
- throw new Error("Refusing E2E Playwright run with NODE_ENV=production.");
7
- }
8
-
9
- const baseUrl = process.env.E2E_BASE_URL ?? "http://127.0.0.1:5173";
10
- assertLocalUrl(baseUrl, "E2E_BASE_URL");
11
-
12
- if (input.requireFrontend ?? false) await assertReachable(baseUrl, "local frontend");
13
-
14
- return { baseUrl };
15
- }
16
-
17
- export function assertLocalUrl(rawUrl, label) {
18
- const url = new URL(rawUrl, "http://127.0.0.1:5173");
19
- const allowedHosts = new Set(["127.0.0.1", "localhost", "::1", "[::1]"]);
20
- if (!allowedHosts.has(url.hostname)) {
21
- throw new Error(`${label} must be local. Refusing URL: ${url.toString()}`);
22
- }
23
- return url;
24
- }
25
-
26
- async function assertReachable(url, label) {
27
- try {
28
- const response = await fetch(url, { method: "HEAD" });
29
- if (response.status < 500) return;
30
- } catch {
31
- // Some local apps reject HEAD. Retry with GET before failing.
32
- }
33
-
34
- try {
35
- const response = await fetch(url, { method: "GET" });
36
- if (response.status < 500) return;
37
- throw new Error(`HTTP ${response.status}`);
38
- } catch (error) {
39
- throw new Error(
40
- `${label} is not reachable at ${url}. Start the local app and retry. ${error instanceof Error ? error.message : String(error)}`,
41
- );
42
- }
43
- }
@@ -1,25 +0,0 @@
1
- import { stdin as input, stdout as output } from "node:process";
2
- import { createInterface } from "node:readline/promises";
3
-
4
- export async function promptText(inputConfig) {
5
- if (!process.stdin.isTTY) {
6
- if (inputConfig.defaultValue !== undefined) return inputConfig.defaultValue;
7
- if (inputConfig.required) throw new Error(`Missing required input: ${inputConfig.label}`);
8
- return "";
9
- }
10
-
11
- const prompt = inputConfig.defaultValue
12
- ? `${inputConfig.label} [${inputConfig.defaultValue}]: `
13
- : `${inputConfig.label}: `;
14
- const readline = createInterface({ input, output });
15
-
16
- try {
17
- const value = (await readline.question(prompt)).trim();
18
- const resolved = value || inputConfig.defaultValue || "";
19
- if (inputConfig.required && !resolved)
20
- throw new Error(`Missing required input: ${inputConfig.label}`);
21
- return resolved;
22
- } finally {
23
- readline.close();
24
- }
25
- }