@spekn/cli 1.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.
Files changed (159) hide show
  1. package/dist/__tests__/export-cli.test.d.ts +1 -0
  2. package/dist/__tests__/export-cli.test.js +70 -0
  3. package/dist/__tests__/tui-args-policy.test.d.ts +1 -0
  4. package/dist/__tests__/tui-args-policy.test.js +50 -0
  5. package/dist/acp-S2MHZOAD.mjs +23 -0
  6. package/dist/acp-UCCI44JY.mjs +25 -0
  7. package/dist/auth/credentials-store.d.ts +2 -0
  8. package/dist/auth/credentials-store.js +5 -0
  9. package/dist/auth/device-flow.d.ts +36 -0
  10. package/dist/auth/device-flow.js +189 -0
  11. package/dist/auth/jwt.d.ts +1 -0
  12. package/dist/auth/jwt.js +6 -0
  13. package/dist/auth/session.d.ts +67 -0
  14. package/dist/auth/session.js +86 -0
  15. package/dist/auth-login.d.ts +34 -0
  16. package/dist/auth-login.js +202 -0
  17. package/dist/auth-logout.d.ts +25 -0
  18. package/dist/auth-logout.js +115 -0
  19. package/dist/auth-status.d.ts +24 -0
  20. package/dist/auth-status.js +109 -0
  21. package/dist/backlog-generate.d.ts +11 -0
  22. package/dist/backlog-generate.js +308 -0
  23. package/dist/backlog-health.d.ts +11 -0
  24. package/dist/backlog-health.js +287 -0
  25. package/dist/bridge-login.d.ts +40 -0
  26. package/dist/bridge-login.js +277 -0
  27. package/dist/chunk-3PAYRI4G.mjs +2428 -0
  28. package/dist/chunk-M4CS3A25.mjs +2426 -0
  29. package/dist/commands/auth/login.d.ts +30 -0
  30. package/dist/commands/auth/login.js +164 -0
  31. package/dist/commands/auth/logout.d.ts +25 -0
  32. package/dist/commands/auth/logout.js +115 -0
  33. package/dist/commands/auth/status.d.ts +24 -0
  34. package/dist/commands/auth/status.js +109 -0
  35. package/dist/commands/backlog/generate.d.ts +11 -0
  36. package/dist/commands/backlog/generate.js +308 -0
  37. package/dist/commands/backlog/health.d.ts +11 -0
  38. package/dist/commands/backlog/health.js +287 -0
  39. package/dist/commands/bridge/login.d.ts +36 -0
  40. package/dist/commands/bridge/login.js +258 -0
  41. package/dist/commands/export.d.ts +35 -0
  42. package/dist/commands/export.js +485 -0
  43. package/dist/commands/marketplace-export.d.ts +21 -0
  44. package/dist/commands/marketplace-export.js +214 -0
  45. package/dist/commands/project-clean.d.ts +1 -0
  46. package/dist/commands/project-clean.js +126 -0
  47. package/dist/commands/repo/common.d.ts +105 -0
  48. package/dist/commands/repo/common.js +775 -0
  49. package/dist/commands/repo/detach.d.ts +2 -0
  50. package/dist/commands/repo/detach.js +120 -0
  51. package/dist/commands/repo/register.d.ts +21 -0
  52. package/dist/commands/repo/register.js +175 -0
  53. package/dist/commands/repo/sync.d.ts +22 -0
  54. package/dist/commands/repo/sync.js +873 -0
  55. package/dist/commands/skills-import-local.d.ts +16 -0
  56. package/dist/commands/skills-import-local.js +352 -0
  57. package/dist/commands/spec/drift-check.d.ts +3 -0
  58. package/dist/commands/spec/drift-check.js +186 -0
  59. package/dist/commands/spec/frontmatter.d.ts +11 -0
  60. package/dist/commands/spec/frontmatter.js +219 -0
  61. package/dist/commands/spec/lint.d.ts +11 -0
  62. package/dist/commands/spec/lint.js +499 -0
  63. package/dist/commands/spec/parse.d.ts +11 -0
  64. package/dist/commands/spec/parse.js +162 -0
  65. package/dist/export.d.ts +35 -0
  66. package/dist/export.js +485 -0
  67. package/dist/index.d.ts +11 -0
  68. package/dist/index.js +21 -0
  69. package/dist/main.d.ts +1 -0
  70. package/dist/main.js +115280 -0
  71. package/dist/marketplace-export.d.ts +21 -0
  72. package/dist/marketplace-export.js +214 -0
  73. package/dist/project-clean.d.ts +1 -0
  74. package/dist/project-clean.js +126 -0
  75. package/dist/project-context.d.ts +99 -0
  76. package/dist/project-context.js +376 -0
  77. package/dist/repo-common.d.ts +101 -0
  78. package/dist/repo-common.js +671 -0
  79. package/dist/repo-detach.d.ts +2 -0
  80. package/dist/repo-detach.js +102 -0
  81. package/dist/repo-ingest.d.ts +29 -0
  82. package/dist/repo-ingest.js +305 -0
  83. package/dist/repo-register.d.ts +21 -0
  84. package/dist/repo-register.js +175 -0
  85. package/dist/repo-sync.d.ts +16 -0
  86. package/dist/repo-sync.js +152 -0
  87. package/dist/resources/prompt-loader.d.ts +1 -0
  88. package/dist/resources/prompt-loader.js +62 -0
  89. package/dist/resources/prompts/README.md +21 -0
  90. package/dist/resources/prompts/prompts/repo-analysis.prompt.md +126 -0
  91. package/dist/resources/prompts/repo-analysis.prompt.md +151 -0
  92. package/dist/resources/prompts/repo-sync-analysis.prompt.md +85 -0
  93. package/dist/skills-import-local.d.ts +16 -0
  94. package/dist/skills-import-local.js +352 -0
  95. package/dist/spec-drift-check.d.ts +3 -0
  96. package/dist/spec-drift-check.js +186 -0
  97. package/dist/spec-frontmatter.d.ts +11 -0
  98. package/dist/spec-frontmatter.js +219 -0
  99. package/dist/spec-lint.d.ts +11 -0
  100. package/dist/spec-lint.js +499 -0
  101. package/dist/spec-parse.d.ts +11 -0
  102. package/dist/spec-parse.js +162 -0
  103. package/dist/stubs/dotenv.d.ts +5 -0
  104. package/dist/stubs/dotenv.js +6 -0
  105. package/dist/stubs/typeorm.d.ts +22 -0
  106. package/dist/stubs/typeorm.js +28 -0
  107. package/dist/tui/app.d.ts +7 -0
  108. package/dist/tui/app.js +122 -0
  109. package/dist/tui/args.d.ts +8 -0
  110. package/dist/tui/args.js +57 -0
  111. package/dist/tui/capabilities/policy.d.ts +7 -0
  112. package/dist/tui/capabilities/policy.js +64 -0
  113. package/dist/tui/components/frame.d.ts +8 -0
  114. package/dist/tui/components/frame.js +8 -0
  115. package/dist/tui/components/status-bar.d.ts +8 -0
  116. package/dist/tui/components/status-bar.js +8 -0
  117. package/dist/tui/index.d.ts +2 -0
  118. package/dist/tui/index.js +23 -0
  119. package/dist/tui/index.mjs +7563 -0
  120. package/dist/tui/keymap/use-global-keymap.d.ts +19 -0
  121. package/dist/tui/keymap/use-global-keymap.js +82 -0
  122. package/dist/tui/navigation/nav-items.d.ts +3 -0
  123. package/dist/tui/navigation/nav-items.js +18 -0
  124. package/dist/tui/screens/bridge.d.ts +8 -0
  125. package/dist/tui/screens/bridge.js +19 -0
  126. package/dist/tui/screens/decisions.d.ts +5 -0
  127. package/dist/tui/screens/decisions.js +28 -0
  128. package/dist/tui/screens/export.d.ts +5 -0
  129. package/dist/tui/screens/export.js +16 -0
  130. package/dist/tui/screens/home.d.ts +5 -0
  131. package/dist/tui/screens/home.js +33 -0
  132. package/dist/tui/screens/locked.d.ts +5 -0
  133. package/dist/tui/screens/locked.js +9 -0
  134. package/dist/tui/screens/specs.d.ts +5 -0
  135. package/dist/tui/screens/specs.js +31 -0
  136. package/dist/tui/services/client.d.ts +1 -0
  137. package/dist/tui/services/client.js +18 -0
  138. package/dist/tui/services/context-service.d.ts +19 -0
  139. package/dist/tui/services/context-service.js +246 -0
  140. package/dist/tui/shared-enums.d.ts +16 -0
  141. package/dist/tui/shared-enums.js +19 -0
  142. package/dist/tui/state/use-app-state.d.ts +35 -0
  143. package/dist/tui/state/use-app-state.js +177 -0
  144. package/dist/tui/types.d.ts +77 -0
  145. package/dist/tui/types.js +2 -0
  146. package/dist/tui-bundle.d.ts +1 -0
  147. package/dist/tui-bundle.js +5 -0
  148. package/dist/tui-entry.mjs +1407 -0
  149. package/dist/utils/cli-runtime.d.ts +5 -0
  150. package/dist/utils/cli-runtime.js +22 -0
  151. package/dist/utils/help-error.d.ts +7 -0
  152. package/dist/utils/help-error.js +14 -0
  153. package/dist/utils/interaction.d.ts +19 -0
  154. package/dist/utils/interaction.js +93 -0
  155. package/dist/utils/structured-log.d.ts +7 -0
  156. package/dist/utils/structured-log.js +112 -0
  157. package/dist/utils/trpc-url.d.ts +4 -0
  158. package/dist/utils/trpc-url.js +15 -0
  159. package/package.json +59 -0
@@ -0,0 +1,5 @@
1
+ export declare function hasHelpFlag(args: string[]): boolean;
2
+ export declare function errorMessage(error: unknown): string;
3
+ export declare function runCliMain(main: (argv?: string[]) => Promise<number> | number, options?: {
4
+ errorPrefix?: string;
5
+ }): Promise<void>;
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.hasHelpFlag = hasHelpFlag;
4
+ exports.errorMessage = errorMessage;
5
+ exports.runCliMain = runCliMain;
6
+ function hasHelpFlag(args) {
7
+ return args.includes("--help") || args.includes("-h");
8
+ }
9
+ function errorMessage(error) {
10
+ return error instanceof Error ? error.message : String(error);
11
+ }
12
+ async function runCliMain(main, options) {
13
+ try {
14
+ const exitCode = await main(process.argv.slice(2));
15
+ process.exit(exitCode);
16
+ }
17
+ catch (error) {
18
+ const prefix = options?.errorPrefix ? `${options.errorPrefix}: ` : "";
19
+ console.error(`${prefix}${errorMessage(error)}`);
20
+ process.exit(1);
21
+ }
22
+ }
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Thrown when the user requests --help. Caught in the CLI main function
3
+ * to display usage information and exit cleanly.
4
+ */
5
+ export declare class HelpRequestedError extends Error {
6
+ constructor();
7
+ }
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.HelpRequestedError = void 0;
4
+ /**
5
+ * Thrown when the user requests --help. Caught in the CLI main function
6
+ * to display usage information and exit cleanly.
7
+ */
8
+ class HelpRequestedError extends Error {
9
+ constructor() {
10
+ super("__HELP__");
11
+ this.name = "HelpRequestedError";
12
+ }
13
+ }
14
+ exports.HelpRequestedError = HelpRequestedError;
@@ -0,0 +1,19 @@
1
+ export interface InteractionSelectOption {
2
+ value: string;
3
+ label: string;
4
+ }
5
+ interface InteractionSelectRequest {
6
+ title: string;
7
+ message: string;
8
+ options: InteractionSelectOption[];
9
+ allowSkip?: boolean;
10
+ timeoutMs?: number;
11
+ }
12
+ /**
13
+ * Request a selection from an external automation controller over stdio.
14
+ * Protocol:
15
+ * - emits a single line to stderr prefixed with "[spekn-interaction] "
16
+ * - expects one JSON line on stdin: {"id":"...","value":"..."} or {"id":"...","skip":true}
17
+ */
18
+ export declare function requestSelectionFromController(req: InteractionSelectRequest): Promise<string | "skip" | null>;
19
+ export {};
@@ -0,0 +1,93 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.requestSelectionFromController = requestSelectionFromController;
4
+ function isJsonStdioMode() {
5
+ return process.env.SPEKN_INTERACTION_MODE === "json-stdio";
6
+ }
7
+ function readSingleLine(timeoutMs) {
8
+ return new Promise((resolve) => {
9
+ if (!process.stdin || process.stdin.destroyed) {
10
+ resolve(null);
11
+ return;
12
+ }
13
+ // In subprocess/pipe mode, use direct buffered reads to avoid readline
14
+ // edge-cases where line events can be dropped on fast close/EOF.
15
+ process.stdin.resume();
16
+ let buffer = "";
17
+ let settled = false;
18
+ const cleanup = () => {
19
+ process.stdin.off("data", onData);
20
+ process.stdin.off("end", onEnd);
21
+ process.stdin.off("error", onError);
22
+ };
23
+ const settle = (value) => {
24
+ if (settled)
25
+ return;
26
+ settled = true;
27
+ clearTimeout(timer);
28
+ cleanup();
29
+ resolve(value);
30
+ };
31
+ const onData = (chunk) => {
32
+ buffer += String(chunk);
33
+ const newlineIndex = buffer.search(/\r?\n|\r/);
34
+ if (newlineIndex >= 0) {
35
+ const line = buffer.slice(0, newlineIndex).trim();
36
+ settle(line);
37
+ }
38
+ };
39
+ const onEnd = () => settle(null);
40
+ const onError = () => settle(null);
41
+ const timer = setTimeout(() => settle(null), timeoutMs);
42
+ process.stdin.on("data", onData);
43
+ process.stdin.once("end", onEnd);
44
+ process.stdin.once("error", onError);
45
+ });
46
+ }
47
+ /**
48
+ * Request a selection from an external automation controller over stdio.
49
+ * Protocol:
50
+ * - emits a single line to stderr prefixed with "[spekn-interaction] "
51
+ * - expects one JSON line on stdin: {"id":"...","value":"..."} or {"id":"...","skip":true}
52
+ */
53
+ async function requestSelectionFromController(req) {
54
+ if (!isJsonStdioMode()) {
55
+ return null;
56
+ }
57
+ const id = `select-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;
58
+ const timeoutMs = req.timeoutMs ?? 120000;
59
+ const payload = {
60
+ type: "spekn.interaction.request",
61
+ id,
62
+ kind: "select",
63
+ title: req.title,
64
+ message: req.message,
65
+ options: req.options,
66
+ allowSkip: req.allowSkip === true,
67
+ };
68
+ process.stderr.write(`[spekn-interaction] ${JSON.stringify(payload)}\n`);
69
+ const line = await readSingleLine(timeoutMs);
70
+ if (!line) {
71
+ return null;
72
+ }
73
+ let parsed = null;
74
+ try {
75
+ parsed = JSON.parse(line);
76
+ }
77
+ catch {
78
+ return null;
79
+ }
80
+ if (!parsed || parsed.id !== id) {
81
+ return null;
82
+ }
83
+ if (parsed.skip === true && req.allowSkip) {
84
+ return "skip";
85
+ }
86
+ if (typeof parsed.value === "string") {
87
+ const allowed = new Set(req.options.map((option) => option.value));
88
+ if (allowed.has(parsed.value)) {
89
+ return parsed.value;
90
+ }
91
+ }
92
+ return null;
93
+ }
@@ -0,0 +1,7 @@
1
+ export type StructuredLogLevel = "debug" | "info" | "warn" | "error";
2
+ export declare function appendCliStructuredLog(input: {
3
+ source: string;
4
+ level: StructuredLogLevel;
5
+ message: string;
6
+ details?: Record<string, unknown>;
7
+ }): void;
@@ -0,0 +1,112 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.appendCliStructuredLog = appendCliStructuredLog;
37
+ const fs = __importStar(require("node:fs"));
38
+ const os = __importStar(require("node:os"));
39
+ const path = __importStar(require("node:path"));
40
+ const GLOBAL_CONFIG_PATH = path.join(os.homedir(), ".spekn", "config.json");
41
+ const DEFAULT_GLOBAL_CONFIG = {
42
+ logging: {
43
+ enabled: false,
44
+ path: "~/.spekn/error.log",
45
+ level: "info",
46
+ },
47
+ };
48
+ const LOG_LEVEL_RANK = {
49
+ debug: 10,
50
+ info: 20,
51
+ warn: 30,
52
+ error: 40,
53
+ };
54
+ function expandHomePath(filePath) {
55
+ if (filePath === "~")
56
+ return os.homedir();
57
+ if (filePath.startsWith("~/"))
58
+ return path.join(os.homedir(), filePath.slice(2));
59
+ return filePath;
60
+ }
61
+ function loadGlobalContextConfig() {
62
+ try {
63
+ const raw = fs.readFileSync(GLOBAL_CONFIG_PATH, "utf-8");
64
+ const parsed = JSON.parse(raw);
65
+ const levelCandidate = parsed?.logging?.level;
66
+ const level = levelCandidate === "debug" ||
67
+ levelCandidate === "info" ||
68
+ levelCandidate === "warn" ||
69
+ levelCandidate === "error"
70
+ ? levelCandidate
71
+ : DEFAULT_GLOBAL_CONFIG.logging.level;
72
+ return {
73
+ logging: {
74
+ enabled: typeof parsed?.logging?.enabled === "boolean"
75
+ ? parsed.logging.enabled
76
+ : DEFAULT_GLOBAL_CONFIG.logging.enabled,
77
+ path: typeof parsed?.logging?.path === "string" && parsed.logging.path.trim().length > 0
78
+ ? parsed.logging.path
79
+ : DEFAULT_GLOBAL_CONFIG.logging.path,
80
+ level,
81
+ },
82
+ };
83
+ }
84
+ catch {
85
+ return DEFAULT_GLOBAL_CONFIG;
86
+ }
87
+ }
88
+ function appendCliStructuredLog(input) {
89
+ try {
90
+ const config = loadGlobalContextConfig();
91
+ if (!config.logging.enabled)
92
+ return;
93
+ if (LOG_LEVEL_RANK[input.level] < LOG_LEVEL_RANK[config.logging.level])
94
+ return;
95
+ const logPath = path.resolve(expandHomePath(config.logging.path));
96
+ fs.mkdirSync(path.dirname(logPath), { recursive: true, mode: 0o700 });
97
+ const payload = {
98
+ timestamp: new Date().toISOString(),
99
+ source: input.source,
100
+ level: input.level,
101
+ message: input.message,
102
+ details: input.details ?? {},
103
+ };
104
+ fs.appendFileSync(logPath, `${JSON.stringify(payload)}\n`, {
105
+ encoding: "utf-8",
106
+ mode: 0o600,
107
+ });
108
+ }
109
+ catch {
110
+ // best effort logging only
111
+ }
112
+ }
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Shared utility for normalizing tRPC API URLs.
3
+ */
4
+ export declare function normalizeTrpcUrl(apiUrl: string): string;
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.normalizeTrpcUrl = normalizeTrpcUrl;
4
+ /**
5
+ * Shared utility for normalizing tRPC API URLs.
6
+ */
7
+ function normalizeTrpcUrl(apiUrl) {
8
+ if (apiUrl.endsWith("/trpc")) {
9
+ return apiUrl;
10
+ }
11
+ if (apiUrl.endsWith("/")) {
12
+ return `${apiUrl}trpc`;
13
+ }
14
+ return `${apiUrl}/trpc`;
15
+ }
package/package.json ADDED
@@ -0,0 +1,59 @@
1
+ {
2
+ "name": "@spekn/cli",
3
+ "version": "1.0.0",
4
+ "description": "Spekn CLI — Spec-Driven Development toolchain",
5
+ "license": "MIT",
6
+ "main": "dist/index.js",
7
+ "types": "dist/index.d.ts",
8
+ "bin": {
9
+ "spekn": "dist/main.js"
10
+ },
11
+ "files": [
12
+ "dist"
13
+ ],
14
+ "engines": {
15
+ "node": ">=22",
16
+ "npm": ">=10"
17
+ },
18
+ "repository": {
19
+ "type": "git",
20
+ "url": "https://github.com/spekn/spekn.git",
21
+ "directory": "packages/cli"
22
+ },
23
+ "keywords": [
24
+ "spekn",
25
+ "sdd",
26
+ "spec-driven-development",
27
+ "cli",
28
+ "specifications",
29
+ "ai-agents"
30
+ ],
31
+ "scripts": {
32
+ "build": "npm -w @spekn/tui run build && tsc --build && tsup && mkdir -p dist/tui && cp ../tui/dist/index.mjs dist/tui/index.mjs && mkdir -p dist/resources/prompts && cp -R src/resources/prompts/. dist/resources/prompts/",
33
+ "dev": "tsc --build --watch",
34
+ "clean": "rm -rf dist",
35
+ "project-delete": "ts-node src/commands/project-clean.ts"
36
+ },
37
+ "dependencies": {
38
+ "@inkjs/ui": "^2.0.0",
39
+ "@trpc/client": "^10.45.4",
40
+ "commander": "^14.0.3",
41
+ "ink": "^6.8.0",
42
+ "js-yaml": "^4.1.0",
43
+ "open": "^10.2.0",
44
+ "pg": "^8.18.0",
45
+ "react": "^19.2.0",
46
+ "typeorm": "^0.3.28",
47
+ "zustand": "^5.0.8",
48
+ "zod": "^4.3.6"
49
+ },
50
+ "devDependencies": {
51
+ "@spekn/agents": "*",
52
+ "@spekn/bridge": "*",
53
+ "@spekn/check": "*",
54
+ "@spekn/shared": "*",
55
+ "@spekn/tui": "*",
56
+ "tsup": "^8.5.1",
57
+ "typescript": "^5.9.3"
58
+ }
59
+ }