@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,258 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ /**
4
+ * bridge login CLI command
5
+ *
6
+ * Authenticates the CLI user via the Keycloak Device Authorization Grant,
7
+ * then registers the bridge device with the Spekn SaaS API. This combines
8
+ * `auth login` (credentials) with bridge device registration in a single step.
9
+ *
10
+ * Usage: spekn bridge login [--name <device-name>] [--api-url <url>] [--force]
11
+ */
12
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
13
+ if (k2 === undefined) k2 = k;
14
+ var desc = Object.getOwnPropertyDescriptor(m, k);
15
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
16
+ desc = { enumerable: true, get: function() { return m[k]; } };
17
+ }
18
+ Object.defineProperty(o, k2, desc);
19
+ }) : (function(o, m, k, k2) {
20
+ if (k2 === undefined) k2 = k;
21
+ o[k2] = m[k];
22
+ }));
23
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
24
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
25
+ }) : function(o, v) {
26
+ o["default"] = v;
27
+ });
28
+ var __importStar = (this && this.__importStar) || (function () {
29
+ var ownKeys = function(o) {
30
+ ownKeys = Object.getOwnPropertyNames || function (o) {
31
+ var ar = [];
32
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
33
+ return ar;
34
+ };
35
+ return ownKeys(o);
36
+ };
37
+ return function (mod) {
38
+ if (mod && mod.__esModule) return mod;
39
+ var result = {};
40
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
41
+ __setModuleDefault(result, mod);
42
+ return result;
43
+ };
44
+ })();
45
+ Object.defineProperty(exports, "__esModule", { value: true });
46
+ exports.decodeJwtPayload = void 0;
47
+ exports.runBridgeLoginCli = runBridgeLoginCli;
48
+ exports.main = main;
49
+ exports.parseArgs = parseArgs;
50
+ const os = __importStar(require("node:os"));
51
+ const client_1 = require("@trpc/client");
52
+ const device_flow_js_1 = require("../../auth/device-flow.js");
53
+ const credentials_store_js_1 = require("../../auth/credentials-store.js");
54
+ const session_js_1 = require("../../auth/session.js");
55
+ const bridge_1 = require("@spekn/bridge");
56
+ const trpc_url_1 = require("../../utils/trpc-url");
57
+ const help_error_1 = require("../../utils/help-error");
58
+ const structured_log_1 = require("../../utils/structured-log");
59
+ const defaultDeps = {
60
+ stdout: process.stdout,
61
+ stderr: process.stderr,
62
+ performDeviceFlow: device_flow_js_1.performDeviceFlow,
63
+ credentialsStore: new credentials_store_js_1.CredentialsStore(),
64
+ bridgeConfigStore: new bridge_1.BridgeConfigStore(),
65
+ };
66
+ function resolveDeps(deps) {
67
+ return {
68
+ stdout: deps?.stdout ?? defaultDeps.stdout,
69
+ stderr: deps?.stderr ?? defaultDeps.stderr,
70
+ performDeviceFlow: deps?.performDeviceFlow ?? defaultDeps.performDeviceFlow,
71
+ credentialsStore: deps?.credentialsStore ?? defaultDeps.credentialsStore,
72
+ bridgeConfigStore: deps?.bridgeConfigStore ?? defaultDeps.bridgeConfigStore,
73
+ };
74
+ }
75
+ function printHelp(stderr) {
76
+ stderr.write(`
77
+ bridge login - Authenticate and register the bridge with Spekn SaaS
78
+
79
+ USAGE:
80
+ spekn bridge login [options]
81
+
82
+ OPTIONS:
83
+ --name <name> Device name (default: system hostname)
84
+ --api-url <url> API base URL (default: SPEKN_API_URL or https://app.spekn.com)
85
+ --keycloak-url <url> Keycloak base URL (default: KEYCLOAK_URL or https://auth.spekn.com)
86
+ --realm <realm> Keycloak realm name (default: KEYCLOAK_REALM or spekn)
87
+ --force Re-register even if bridge is already paired
88
+ --help Show this help message
89
+
90
+ ENVIRONMENT:
91
+ SPEKN_API_URL API base URL
92
+ KEYCLOAK_URL Keycloak base URL
93
+ KEYCLOAK_REALM Keycloak realm name
94
+
95
+ EXAMPLES:
96
+ spekn bridge login
97
+ spekn bridge login --name my-dev-machine
98
+ spekn bridge login --api-url https://api.spekn.dev --force
99
+ `);
100
+ }
101
+ function parseArgs(args) {
102
+ let deviceName = os.hostname();
103
+ let apiUrl = process.env["SPEKN_API_URL"] ?? "https://app.spekn.com";
104
+ let keycloakUrl = process.env["KEYCLOAK_URL"] ?? "https://auth.spekn.com";
105
+ let realm = process.env["KEYCLOAK_REALM"] ?? "spekn";
106
+ let force = false;
107
+ for (let index = 0; index < args.length; index++) {
108
+ const arg = args[index];
109
+ if (arg === "--help" || arg === "-h") {
110
+ throw new help_error_1.HelpRequestedError();
111
+ }
112
+ if (arg === "--name" && args[index + 1]) {
113
+ deviceName = args[++index];
114
+ continue;
115
+ }
116
+ if (arg?.startsWith("--name=")) {
117
+ deviceName = arg.slice("--name=".length);
118
+ continue;
119
+ }
120
+ if (arg === "--api-url" && args[index + 1]) {
121
+ apiUrl = args[++index];
122
+ continue;
123
+ }
124
+ if (arg?.startsWith("--api-url=")) {
125
+ apiUrl = arg.slice("--api-url=".length);
126
+ continue;
127
+ }
128
+ if (arg === "--keycloak-url" && args[index + 1]) {
129
+ keycloakUrl = args[++index];
130
+ continue;
131
+ }
132
+ if (arg?.startsWith("--keycloak-url=")) {
133
+ keycloakUrl = arg.slice("--keycloak-url=".length);
134
+ continue;
135
+ }
136
+ if (arg === "--realm" && args[index + 1]) {
137
+ realm = args[++index];
138
+ continue;
139
+ }
140
+ if (arg?.startsWith("--realm=")) {
141
+ realm = arg.slice("--realm=".length);
142
+ continue;
143
+ }
144
+ if (arg === "--force") {
145
+ force = true;
146
+ continue;
147
+ }
148
+ }
149
+ return { deviceName, apiUrl, keycloakUrl, realm, force };
150
+ }
151
+ async function runBridgeLoginCli(args, deps) {
152
+ const resolved = resolveDeps(deps);
153
+ try {
154
+ const options = parseArgs(args);
155
+ (0, structured_log_1.appendCliStructuredLog)({
156
+ source: "cli.bridge.login",
157
+ level: "info",
158
+ message: "Starting bridge login",
159
+ details: { deviceName: options.deviceName, apiUrl: options.apiUrl, force: options.force },
160
+ });
161
+ // Load bridge config
162
+ resolved.bridgeConfigStore.load();
163
+ // Check if already paired — require --force to re-register
164
+ if (resolved.bridgeConfigStore.isPaired() && !options.force) {
165
+ resolved.stderr.write("Bridge is already registered. Use --force to re-register.\n");
166
+ return 1;
167
+ }
168
+ const auth = await (0, session_js_1.ensureAuthenticated)({
169
+ keycloakUrl: options.keycloakUrl,
170
+ realm: options.realm,
171
+ credentialsStore: resolved.credentialsStore,
172
+ performDeviceFlow: resolved.performDeviceFlow,
173
+ stdout: resolved.stdout,
174
+ stderr: resolved.stderr,
175
+ forceDeviceFlow: false,
176
+ });
177
+ if (auth.source === "existing") {
178
+ resolved.stdout.write(`Using existing credentials (${auth.user.email})\n`);
179
+ }
180
+ else {
181
+ resolved.stdout.write(`Authenticated as ${auth.user.email}\n`);
182
+ }
183
+ // Step 3: Resolve organization context
184
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
185
+ const client = (0, client_1.createTRPCProxyClient)({
186
+ links: [
187
+ (0, client_1.httpBatchLink)({
188
+ url: (0, trpc_url_1.normalizeTrpcUrl)(options.apiUrl),
189
+ headers: {
190
+ authorization: `Bearer ${auth.accessToken}`,
191
+ },
192
+ }),
193
+ ],
194
+ });
195
+ const organizationId = await (0, session_js_1.resolveOrganizationId)({
196
+ existingOrganizationId: auth.credentials.organizationId,
197
+ envOrganizationId: process.env.SPEKN_ORGANIZATION_ID,
198
+ fetchOrganizations: async () => (await client.organization.list.query()),
199
+ stdout: resolved.stdout,
200
+ });
201
+ // Step 4: POST to bridge.registerWithToken
202
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
203
+ const clientWithOrg = (0, client_1.createTRPCProxyClient)({
204
+ links: [
205
+ (0, client_1.httpBatchLink)({
206
+ url: (0, trpc_url_1.normalizeTrpcUrl)(options.apiUrl),
207
+ headers: {
208
+ authorization: `Bearer ${auth.accessToken}`,
209
+ "x-organization-id": organizationId ?? "",
210
+ },
211
+ }),
212
+ ],
213
+ });
214
+ const result = await clientWithOrg.bridge.registerWithToken.mutate({
215
+ deviceName: options.deviceName,
216
+ });
217
+ // Step 4: Save result to BridgeConfigStore
218
+ resolved.bridgeConfigStore.setPairing({
219
+ deviceId: result.deviceId,
220
+ deviceName: options.deviceName,
221
+ credential: result.credential,
222
+ pairedAt: new Date().toISOString(),
223
+ saasOrigin: result.saasOrigin,
224
+ });
225
+ resolved.bridgeConfigStore.update({ saasWsUrl: result.saasWsUrl });
226
+ resolved.stdout.write(`\nBridge registered as '${options.deviceName}'. Run: spekn bridge start\n`);
227
+ (0, structured_log_1.appendCliStructuredLog)({
228
+ source: "cli.bridge.login",
229
+ level: "info",
230
+ message: "Bridge login completed",
231
+ details: { deviceId: result.deviceId, organizationId: result.organizationId },
232
+ });
233
+ return 0;
234
+ }
235
+ catch (error) {
236
+ if (error instanceof help_error_1.HelpRequestedError) {
237
+ printHelp(resolved.stderr);
238
+ return 0;
239
+ }
240
+ const message = error instanceof Error ? error.message : String(error);
241
+ resolved.stderr.write(`Error: ${message}\n`);
242
+ (0, structured_log_1.appendCliStructuredLog)({
243
+ source: "cli.bridge.login",
244
+ level: "error",
245
+ message,
246
+ });
247
+ return 1;
248
+ }
249
+ }
250
+ async function main() {
251
+ const exitCode = await runBridgeLoginCli(process.argv.slice(2));
252
+ process.exit(exitCode);
253
+ }
254
+ if (require.main === module) {
255
+ void main();
256
+ }
257
+ var jwt_js_1 = require("../../auth/jwt.js");
258
+ Object.defineProperty(exports, "decodeJwtPayload", { enumerable: true, get: function () { return jwt_js_1.decodeJwtPayload; } });
@@ -0,0 +1,35 @@
1
+ #!/usr/bin/env node
2
+ import { CredentialsStore } from '../auth/credentials-store';
3
+ type ExportFormat = 'agents-md' | 'claude-md' | 'cursorrules' | 'gemini-md';
4
+ type ExportMode = 'global' | 'scoped';
5
+ type ExportDeliveryMode = 'download' | 'copy' | 'commit' | 'pr';
6
+ type ExportCommand = 'generate' | 'status' | 'discover' | 'preview';
7
+ interface CLIOptions {
8
+ command: ExportCommand;
9
+ projectId?: string;
10
+ format?: ExportFormat;
11
+ output?: string;
12
+ anchors?: string[];
13
+ mode: ExportMode;
14
+ scope?: string;
15
+ delivery: ExportDeliveryMode;
16
+ json: boolean;
17
+ branch?: string;
18
+ baseBranch?: string;
19
+ commitMessage?: string;
20
+ prTitle?: string;
21
+ prBody?: string;
22
+ apiUrl: string;
23
+ }
24
+ interface Deps {
25
+ createClient: (apiUrl: string, organizationId: string, authToken?: string) => any;
26
+ writeFile: (filePath: string, content: string) => void;
27
+ stdout: (content: string) => void;
28
+ stderr: (content: string) => void;
29
+ credentialsStore: CredentialsStore;
30
+ }
31
+ declare function normalizeTrpcUrl(apiUrl: string): string;
32
+ declare function parseArgs(args: string[]): CLIOptions;
33
+ export declare function runExportCli(args: string[], deps?: Deps): Promise<number>;
34
+ declare function main(): Promise<void>;
35
+ export { main, parseArgs, normalizeTrpcUrl };