@specdest/devkit 0.2.2 → 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 +65 -6
  10. package/src/remote-installer.js +462 -0
  11. package/src/sync-core.js +20 -7
  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 -29
  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,107 +0,0 @@
1
- import type { BrowserContext, Locator, Page, TestInfo } from "@playwright/test";
2
-
3
- export type E2EPlaywrightFlowContext = {
4
- readonly context: BrowserContext;
5
- readonly page: Page;
6
- readonly testInfo?: TestInfo;
7
- };
8
-
9
- export type E2EPlaywrightFlowStep = {
10
- readonly name: string;
11
- readonly run: (context: E2EPlaywrightFlowContext) => Promise<void>;
12
- };
13
-
14
- export type E2EPlaywrightFlow = readonly E2EPlaywrightFlowStep[];
15
-
16
- export type E2EPlaywrightFlowRunOptions = {
17
- readonly until?: string;
18
- readonly pauseAfter?: string;
19
- readonly trace?: boolean;
20
- };
21
-
22
- export function step(
23
- name: string,
24
- run: (context: E2EPlaywrightFlowContext) => Promise<void>,
25
- ): E2EPlaywrightFlowStep {
26
- return { name, run };
27
- }
28
-
29
- export function e2ePlaywrightFlowOptionsFromEnv(
30
- env: Record<string, string | undefined> = process.env,
31
- ): E2EPlaywrightFlowRunOptions {
32
- const options: E2EPlaywrightFlowRunOptions = {
33
- trace: env["E2E_PLAYWRIGHT_TRACE_STEPS"] !== "0",
34
- };
35
- const until = nonEmpty(env["E2E_PLAYWRIGHT_UNTIL_STEP"]);
36
- const pauseAfter = nonEmpty(env["E2E_PLAYWRIGHT_PAUSE_AFTER_STEP"]);
37
- if (until) return { ...options, until };
38
- if (pauseAfter) return { ...options, pauseAfter };
39
- return options;
40
- }
41
-
42
- export async function runE2EPlaywrightFlow(
43
- flow: E2EPlaywrightFlow,
44
- context: E2EPlaywrightFlowContext,
45
- options: E2EPlaywrightFlowRunOptions = {},
46
- ): Promise<void> {
47
- assertKnownStepName(flow, options.until, "until");
48
- assertKnownStepName(flow, options.pauseAfter, "pause-after");
49
-
50
- for (const [index, flowStep] of flow.entries()) {
51
- const stepNumber = index + 1;
52
- const prefix = `[e2e-playwright] step ${stepNumber}/${flow.length}: ${flowStep.name}`;
53
-
54
- if (options.trace ?? true) console.log(`${prefix} start`);
55
-
56
- try {
57
- await flowStep.run(context);
58
- } catch (error) {
59
- throw new Error(
60
- [`${prefix} failed`, error instanceof Error ? error.message : String(error)].join("\n"),
61
- { cause: error },
62
- );
63
- }
64
-
65
- if (options.trace ?? true) console.log(`${prefix} done`);
66
-
67
- if (options.pauseAfter === flowStep.name) {
68
- console.log(`${prefix} pausing after step`);
69
- await context.page.pause();
70
- }
71
-
72
- if (options.until === flowStep.name) {
73
- console.log(`${prefix} stopping because --until matched`);
74
- return;
75
- }
76
- }
77
- }
78
-
79
- export async function readNumberFromText(locator: Locator): Promise<number> {
80
- const text = await locator.textContent();
81
- const normalized = (text ?? "").replace(/[^0-9.-]/g, "");
82
- const value = Number(normalized);
83
- if (!Number.isFinite(value)) throw new Error(`Could not read number from text: ${text ?? ""}`);
84
- return value;
85
- }
86
-
87
- function assertKnownStepName(
88
- flow: E2EPlaywrightFlow,
89
- stepName: string | undefined,
90
- label: string,
91
- ): void {
92
- if (!stepName) return;
93
- if (flow.some((flowStep) => flowStep.name === stepName)) return;
94
-
95
- throw new Error(
96
- [
97
- `Unknown E2E Playwright ${label} step: ${stepName}`,
98
- "Available steps:",
99
- ...flow.map((flowStep) => `- ${flowStep.name}`),
100
- ].join("\n"),
101
- );
102
- }
103
-
104
- function nonEmpty(value: string | undefined): string | undefined {
105
- const trimmed = value?.trim();
106
- return trimmed ? trimmed : undefined;
107
- }
@@ -1,27 +0,0 @@
1
- import { expect, test as base } from "@playwright/test";
2
-
3
- export const test = base.extend<{ readonly collectBrowserDiagnostics: void }>({
4
- collectBrowserDiagnostics: [
5
- async ({ page }, use, testInfo) => {
6
- const messages: string[] = [];
7
- page.on("console", (message) => {
8
- messages.push(`[console:${message.type()}] ${message.text()}`);
9
- });
10
- page.on("pageerror", (error) => {
11
- messages.push(`[pageerror] ${error.message}`);
12
- });
13
-
14
- await use();
15
-
16
- if (testInfo.status !== testInfo.expectedStatus && messages.length > 0) {
17
- await testInfo.attach("browser-diagnostics.txt", {
18
- body: messages.join("\n"),
19
- contentType: "text/plain",
20
- });
21
- }
22
- },
23
- { auto: true },
24
- ],
25
- });
26
-
27
- export { expect };
@@ -1,13 +0,0 @@
1
- # Local log debugging instructions
2
-
3
- When the user reports an error, inspect `tmp/logs/activity-*.jsonl` before guessing.
4
-
5
- Use:
6
-
7
- ```bash
8
- node tools/local-log/local-log.mjs tail 200
9
- ```
10
-
11
- Correlate `.start`, `.success`, and `.error` events by `requestId`. Check `source`, `event`, `durationMs`, `details`, `result`, and `error`. Search the codebase for the event name and failing operation. Sensitive fields should appear as `[REDACTED]`.
12
-
13
- Do not delete logs until the issue is understood. Do not remove logging as part of a fix. Add structured context when the existing records are insufficient. See `docs/features/local-logging/README.md` and `tools/local-log/README.md`.
@@ -1,70 +0,0 @@
1
- # Local diagnostic logging
2
-
3
- This feature provides a dependency-free Node.js logger and maintenance CLI. It writes local newline-delimited JSON files that developers and coding agents can inspect when diagnosing errors.
4
-
5
- ## Installed components
6
-
7
- ```text
8
- tools/local-log/local-log.mjs
9
- tools/local-log/README.md
10
- tmp/logs/.gitignore
11
- AGENTS.local-log.md
12
- ```
13
-
14
- ## Log location
15
-
16
- ```text
17
- tmp/logs/activity-YYYY-MM-DD.jsonl
18
- ```
19
-
20
- Set `LOCAL_LOG_ROOT` to use a different absolute directory. Set `LOCAL_LOG_SOURCE` to identify the process writing through the CLI.
21
-
22
- ## Application API
23
-
24
- ```js
25
- import { createLocalLogger, traceOperation } from "./tools/local-log/local-log.mjs";
26
-
27
- const log = createLocalLogger({ source: "worker" });
28
-
29
- await log.write({
30
- event: "worker.started",
31
- requestId: crypto.randomUUID(),
32
- details: { queue: "default" },
33
- });
34
- ```
35
-
36
- Use `traceOperation()` to record start, success, error, duration, and a shared request ID around an asynchronous operation.
37
-
38
- ## Commands
39
-
40
- ```bash
41
- node tools/local-log/local-log.mjs write user.click '{"control":"save"}'
42
- node tools/local-log/local-log.mjs tail 200
43
- node tools/local-log/local-log.mjs clear-old 7
44
- node tools/local-log/local-log.mjs clear-all
45
- node tools/local-log/local-log.mjs path
46
- ```
47
-
48
- ## Data behavior
49
-
50
- - sensitive key names are written as `[REDACTED]`;
51
- - large strings, arrays, objects, and nesting are bounded;
52
- - circular references are converted to `[Circular]`;
53
- - log files are local and ignored by Git;
54
- - the logger does not transmit data.
55
-
56
- ## Browser and process boundaries
57
-
58
- Browser code cannot write repository files directly. Forward browser activity to a trusted local process, then call this logger there. Use the same `requestId` on both sides of the boundary.
59
-
60
- ## Debugging workflow
61
-
62
- 1. Read `AGENTS.local-log.md`.
63
- 2. Run `node tools/local-log/local-log.mjs tail 200`.
64
- 3. Find error events or records where `level` is `error`.
65
- 4. Correlate related operations using `requestId`.
66
- 5. Search the codebase for the event name.
67
- 6. Reproduce and fix the underlying operation.
68
- 7. Preserve or improve structured logging.
69
-
70
- Additional API examples are in `tools/local-log/README.md`.
@@ -1,39 +0,0 @@
1
- {
2
- "id": "local-log",
3
- "kind": "module",
4
- "version": "1.1.0",
5
- "artifacts": [
6
- {
7
- "kind": "managed-file",
8
- "path": "AGENTS.local-log.md",
9
- "source": "AGENTS.local-log.md"
10
- },
11
- {
12
- "kind": "managed-file",
13
- "path": "docs/features/local-logging/README.md",
14
- "source": "docs/features/local-logging/README.md"
15
- },
16
- {
17
- "kind": "managed-file",
18
- "path": "tmp/logs/.gitignore",
19
- "source": "tmp/logs/.gitignore"
20
- },
21
- {
22
- "kind": "managed-file",
23
- "path": "tools/local-log/README.md",
24
- "source": "tools/local-log/README.md"
25
- },
26
- {
27
- "kind": "managed-file",
28
- "path": "tools/local-log/local-log.mjs",
29
- "source": "tools/local-log/local-log.mjs"
30
- },
31
- {
32
- "kind": "shared-markdown-section",
33
- "path": "AGENTS.md",
34
- "heading": "## Local diagnostic logging",
35
- "body": "When diagnosing an error, inspect project-local logs before guessing. Run `node tools/local-log/local-log.mjs tail 200`, correlate records by `requestId`, keep sensitive fields redacted, and see `AGENTS.local-log.md` plus `docs/features/local-logging/README.md`."
36
- }
37
- ],
38
- "obsolete": []
39
- }
@@ -1,2 +0,0 @@
1
- *
2
- !.gitignore
@@ -1,47 +0,0 @@
1
- # Local diagnostic logging
2
-
3
- This directory contains a dependency-free Node.js logger that writes newline-delimited JSON into `tmp/logs/`.
4
-
5
- ## Application API
6
-
7
- ```js
8
- import { createLocalLogger, traceOperation } from "./tools/local-log/local-log.mjs";
9
-
10
- const log = createLocalLogger({ source: "api" });
11
-
12
- await log.write({
13
- event: "user.click",
14
- requestId: crypto.randomUUID(),
15
- details: { control: "save-project" },
16
- });
17
-
18
- const result = await traceOperation(
19
- log,
20
- {
21
- event: "native.message",
22
- requestId: crypto.randomUUID(),
23
- details: { type: "project.save" },
24
- },
25
- () => sendMessage(),
26
- );
27
- ```
28
-
29
- Use the same `requestId` on both sides of a process boundary.
30
-
31
- A browser cannot write directly to the local filesystem. Forward browser events to a trusted local server or native process, then call this logger there.
32
-
33
- ## CLI
34
-
35
- ```bash
36
- node tools/local-log/local-log.mjs write user.click '{"control":"save"}'
37
- node tools/local-log/local-log.mjs tail 200
38
- node tools/local-log/local-log.mjs clear-old 7
39
- node tools/local-log/local-log.mjs clear-all
40
- node tools/local-log/local-log.mjs path
41
- ```
42
-
43
- Set `LOCAL_LOG_ROOT` to override `tmp/logs` and `LOCAL_LOG_SOURCE` to identify a process.
44
-
45
- ## Data handling
46
-
47
- Keys containing token, password, secret, authorization, cookie, API key, or private key are replaced with `[REDACTED]`. Large and deeply nested values are truncated.
@@ -1,241 +0,0 @@
1
- #!/usr/bin/env node
2
- import { realpathSync } from "node:fs";
3
- import { appendFile, mkdir, readFile, readdir, rm, stat } from "node:fs/promises";
4
- import path from "node:path";
5
- import { fileURLToPath } from "node:url";
6
-
7
- const LOG_FILE_PATTERN = /^activity-\d{4}-\d{2}-\d{2}\.jsonl$/;
8
- const SENSITIVE_KEY_PATTERN =
9
- /token|password|secret|authorization|cookie|api[-_]?key|private[-_]?key/i;
10
- const MAX_STRING_LENGTH = 4000;
11
- const MAX_ARRAY_LENGTH = 50;
12
- const MAX_OBJECT_KEYS = 100;
13
- const MAX_DEPTH = 6;
14
-
15
- function truncate(value) {
16
- const text = String(value);
17
- if (text.length <= MAX_STRING_LENGTH) return text;
18
- return `${text.slice(0, MAX_STRING_LENGTH)}…[truncated ${text.length - MAX_STRING_LENGTH} chars]`;
19
- }
20
-
21
- export function sanitizeForLog(value, depth = 0, seen = new WeakSet()) {
22
- if (value === null || value === undefined) return value;
23
- if (typeof value === "string") return truncate(value);
24
- if (["number", "boolean"].includes(typeof value)) return value;
25
- if (typeof value === "bigint") return String(value);
26
- if (typeof value === "function") return `[Function ${value.name || "anonymous"}]`;
27
- if (value instanceof Error) {
28
- const error = /** @type {Error & { code?: unknown, details?: unknown }} */ (value);
29
- return {
30
- name: error.name,
31
- message: truncate(error.message || String(error)),
32
- stack: error.stack ? truncate(error.stack) : undefined,
33
- code: error.code,
34
- details: sanitizeForLog(error.details, depth + 1, seen),
35
- };
36
- }
37
- if (typeof value !== "object") return truncate(value);
38
- if (depth >= MAX_DEPTH) return "[Max depth reached]";
39
- if (seen.has(value)) return "[Circular]";
40
- seen.add(value);
41
-
42
- if (Array.isArray(value)) {
43
- const items = value
44
- .slice(0, MAX_ARRAY_LENGTH)
45
- .map((item) => sanitizeForLog(item, depth + 1, seen));
46
- if (value.length > MAX_ARRAY_LENGTH)
47
- items.push(`[${value.length - MAX_ARRAY_LENGTH} more items]`);
48
- return items;
49
- }
50
-
51
- const result = {};
52
- const entries = Object.entries(value).slice(0, MAX_OBJECT_KEYS);
53
- for (const [key, item] of entries) {
54
- result[key] = SENSITIVE_KEY_PATTERN.test(key)
55
- ? "[REDACTED]"
56
- : sanitizeForLog(item, depth + 1, seen);
57
- }
58
- if (Object.keys(value).length > MAX_OBJECT_KEYS) {
59
- result.__truncatedKeys = Object.keys(value).length - MAX_OBJECT_KEYS;
60
- }
61
- return result;
62
- }
63
-
64
- function positiveInteger(value, fallback, maximum) {
65
- const parsed = Number.parseInt(String(value), 10);
66
- if (!Number.isFinite(parsed) || parsed < 1) return fallback;
67
- return Math.min(parsed, maximum);
68
- }
69
-
70
- export class LocalLogger {
71
- /** @param {{ rootDir?: string, logRoot?: string, source?: string, now?: () => Date }} [options] */
72
- constructor({
73
- rootDir = process.cwd(),
74
- logRoot,
75
- source = "application",
76
- now = () => new Date(),
77
- } = {}) {
78
- this.rootDir = path.resolve(rootDir);
79
- this.logRoot = path.resolve(
80
- logRoot || process.env.LOCAL_LOG_ROOT || path.join(this.rootDir, "tmp", "logs"),
81
- );
82
- this.source = source;
83
- this.now = now;
84
- }
85
-
86
- currentLogPath(date = this.now()) {
87
- return path.join(this.logRoot, `activity-${date.toISOString().slice(0, 10)}.jsonl`);
88
- }
89
-
90
- async write(entry) {
91
- const date = this.now();
92
- const file = this.currentLogPath(date);
93
- const record = sanitizeForLog({
94
- timestamp: date.toISOString(),
95
- level: "info",
96
- source: this.source,
97
- ...entry,
98
- });
99
- await mkdir(this.logRoot, { recursive: true });
100
- await appendFile(file, `${JSON.stringify(record)}\n`, "utf8");
101
- return { path: this.logRoot, file, record };
102
- }
103
-
104
- async tail(lines = 200) {
105
- const limit = positiveInteger(lines, 200, 5000);
106
- const files = await this.listFiles();
107
- const output = [];
108
- for (let index = files.length - 1; index >= 0 && output.length < limit; index -= 1) {
109
- const source = await readFile(path.join(this.logRoot, files[index]), "utf8");
110
- const fileLines = source.split("\n").filter(Boolean);
111
- output.unshift(...fileLines.slice(-(limit - output.length)));
112
- }
113
- return { path: this.logRoot, lines: output.length, content: output.join("\n") };
114
- }
115
-
116
- async clearAll() {
117
- const files = await this.listFiles();
118
- await Promise.all(files.map((name) => rm(path.join(this.logRoot, name), { force: true })));
119
- return { path: this.logRoot, removed: files.length };
120
- }
121
-
122
- async clearOlderThan(days = 7) {
123
- const ageDays = positiveInteger(days, 7, 3650);
124
- const cutoff = this.now().getTime() - ageDays * 24 * 60 * 60 * 1000;
125
- const removed = [];
126
- for (const name of await this.listFiles()) {
127
- const file = path.join(this.logRoot, name);
128
- if ((await stat(file)).mtimeMs < cutoff) {
129
- await rm(file, { force: true });
130
- removed.push(name);
131
- }
132
- }
133
- return { path: this.logRoot, days: ageDays, removed: removed.length, files: removed };
134
- }
135
-
136
- async listFiles() {
137
- try {
138
- return (await readdir(this.logRoot, { withFileTypes: true }))
139
- .filter((entry) => entry.isFile() && LOG_FILE_PATTERN.test(entry.name))
140
- .map((entry) => entry.name)
141
- .sort();
142
- } catch (error) {
143
- const fsError = /** @type {NodeJS.ErrnoException} */ (error);
144
- if (fsError.code === "ENOENT") return [];
145
- throw error;
146
- }
147
- }
148
- }
149
-
150
- export function createLocalLogger(options = {}) {
151
- return new LocalLogger(options);
152
- }
153
-
154
- export async function traceOperation(
155
- logger,
156
- { event, requestId = crypto.randomUUID(), details = {} },
157
- operation,
158
- ) {
159
- const startedAt = Date.now();
160
- await logger.write({ level: "info", event: `${event}.start`, requestId, details });
161
- try {
162
- const result = await operation();
163
- await logger.write({
164
- level: "info",
165
- event: `${event}.success`,
166
- requestId,
167
- durationMs: Date.now() - startedAt,
168
- result,
169
- });
170
- return result;
171
- } catch (error) {
172
- await logger.write({
173
- level: "error",
174
- event: `${event}.error`,
175
- requestId,
176
- durationMs: Date.now() - startedAt,
177
- error,
178
- });
179
- throw error;
180
- }
181
- }
182
-
183
- function usage() {
184
- return [
185
- "Local diagnostic logger",
186
- "",
187
- "Commands:",
188
- " write <event> [details-json] Append one structured event",
189
- " tail [lines] Print the newest log lines",
190
- " clear-old [days] Delete daily files older than N days",
191
- " clear-all Delete all daily log files",
192
- " path Print the log directory",
193
- "",
194
- "Environment:",
195
- " LOCAL_LOG_ROOT Override tmp/logs",
196
- " LOCAL_LOG_SOURCE Set the default source name",
197
- ].join("\n");
198
- }
199
-
200
- async function runCli(argv) {
201
- const [command, ...args] = argv;
202
- const logger = createLocalLogger({ source: process.env.LOCAL_LOG_SOURCE || "cli" });
203
-
204
- if (command === "write") {
205
- const event = String(args[0] || "").trim();
206
- if (!event) throw new Error("write requires an event name");
207
- const details = args[1] ? JSON.parse(args[1]) : {};
208
- console.log(JSON.stringify(await logger.write({ event, details })));
209
- return;
210
- }
211
- if (command === "tail") {
212
- const result = await logger.tail(args[0]);
213
- if (result.content) process.stdout.write(`${result.content}\n`);
214
- return;
215
- }
216
- if (command === "clear-old") {
217
- console.log(JSON.stringify(await logger.clearOlderThan(args[0])));
218
- return;
219
- }
220
- if (command === "clear-all") {
221
- console.log(JSON.stringify(await logger.clearAll()));
222
- return;
223
- }
224
- if (command === "path") {
225
- console.log(logger.logRoot);
226
- return;
227
- }
228
- console.log(usage());
229
- if (command) process.exitCode = 1;
230
- }
231
-
232
- const isMain = Boolean(
233
- process.argv[1] &&
234
- realpathSync(fileURLToPath(import.meta.url)) === realpathSync(path.resolve(process.argv[1])),
235
- );
236
- if (isMain) {
237
- runCli(process.argv.slice(2)).catch((error) => {
238
- process.stderr.write(`${error?.stack || error?.message || String(error)}\n`);
239
- process.exitCode = 1;
240
- });
241
- }
@@ -1,16 +0,0 @@
1
- {
2
- "id": "stack-common-vite",
3
- "kind": "module",
4
- "version": "1.0.0",
5
- "requires": [
6
- "design-rules",
7
- "e2e-test-rules",
8
- "error-handling-rules",
9
- "nearby-contracts",
10
- "public-api-export-barrels",
11
- "route-tree-fresh",
12
- "strict-typescript"
13
- ],
14
- "artifacts": [],
15
- "obsolete": []
16
- }
@@ -1,31 +0,0 @@
1
- {
2
- "id": "stack-expo-convex",
3
- "kind": "module",
4
- "version": "1.1.0",
5
- "requires": [
6
- "backend-convex-expo"
7
- ],
8
- "setupRequirements": [
9
- {
10
- "kind": "env",
11
- "name": "EXPO_PUBLIC_CONVEX_URL",
12
- "required": true,
13
- "exampleFile": ".env.example",
14
- "description": "Required runtime configuration for stack-expo-convex."
15
- }
16
- ],
17
- "artifacts": [
18
- {
19
- "kind": "shared-key-value",
20
- "path": ".env.example",
21
- "key": "EXPO_PUBLIC_CONVEX_URL",
22
- "value": ""
23
- },
24
- {
25
- "kind": "shared-line",
26
- "path": ".gitignore",
27
- "line": "!.env.example"
28
- }
29
- ],
30
- "obsolete": []
31
- }
@@ -1,44 +0,0 @@
1
- {
2
- "id": "stack-expo-supabase",
3
- "kind": "module",
4
- "version": "1.1.0",
5
- "requires": [
6
- "backend-supabase-expo"
7
- ],
8
- "setupRequirements": [
9
- {
10
- "kind": "env",
11
- "name": "EXPO_PUBLIC_SUPABASE_URL",
12
- "required": true,
13
- "exampleFile": ".env.example",
14
- "description": "Required runtime configuration for stack-expo-supabase."
15
- },
16
- {
17
- "kind": "env",
18
- "name": "EXPO_PUBLIC_SUPABASE_ANON_KEY",
19
- "required": true,
20
- "exampleFile": ".env.example",
21
- "description": "Required runtime configuration for stack-expo-supabase."
22
- }
23
- ],
24
- "artifacts": [
25
- {
26
- "kind": "shared-key-value",
27
- "path": ".env.example",
28
- "key": "EXPO_PUBLIC_SUPABASE_URL",
29
- "value": ""
30
- },
31
- {
32
- "kind": "shared-key-value",
33
- "path": ".env.example",
34
- "key": "EXPO_PUBLIC_SUPABASE_ANON_KEY",
35
- "value": ""
36
- },
37
- {
38
- "kind": "shared-line",
39
- "path": ".gitignore",
40
- "line": "!.env.example"
41
- }
42
- ],
43
- "obsolete": []
44
- }
@@ -1,32 +0,0 @@
1
- {
2
- "id": "stack-vite-convex",
3
- "kind": "module",
4
- "version": "1.2.0",
5
- "requires": [
6
- "backend-convex",
7
- "stack-common-vite"
8
- ],
9
- "setupRequirements": [
10
- {
11
- "kind": "env",
12
- "name": "VITE_CONVEX_URL",
13
- "required": true,
14
- "exampleFile": ".env.example",
15
- "description": "Required runtime configuration for stack-vite-convex."
16
- }
17
- ],
18
- "artifacts": [
19
- {
20
- "kind": "shared-key-value",
21
- "path": ".env.example",
22
- "key": "VITE_CONVEX_URL",
23
- "value": ""
24
- },
25
- {
26
- "kind": "shared-line",
27
- "path": ".gitignore",
28
- "line": "!.env.example"
29
- }
30
- ],
31
- "obsolete": []
32
- }