@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,202 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ /**
4
+ * auth login CLI command
5
+ *
6
+ * Authenticates the CLI user via the Keycloak Device Authorization Grant
7
+ * (RFC 8628) and persists credentials to ~/.spekn/credentials.json.
8
+ *
9
+ * Usage: spekn auth login [--keycloak-url <url>] [--realm <realm>]
10
+ */
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.runAuthLoginCli = runAuthLoginCli;
13
+ exports.main = main;
14
+ exports.parseArgs = parseArgs;
15
+ exports.decodeJwtPayload = decodeJwtPayload;
16
+ const client_1 = require("@trpc/client");
17
+ const device_flow_js_1 = require("./auth/device-flow.js");
18
+ const credentials_store_js_1 = require("./auth/credentials-store.js");
19
+ const help_error_1 = require("./utils/help-error");
20
+ const trpc_url_1 = require("./utils/trpc-url");
21
+ const structured_log_1 = require("./utils/structured-log");
22
+ const defaultDeps = {
23
+ stdout: process.stdout,
24
+ stderr: process.stderr,
25
+ performDeviceFlow: device_flow_js_1.performDeviceFlow,
26
+ credentialsStore: new credentials_store_js_1.CredentialsStore(),
27
+ };
28
+ function resolveDeps(deps) {
29
+ return {
30
+ stdout: deps?.stdout ?? defaultDeps.stdout,
31
+ stderr: deps?.stderr ?? defaultDeps.stderr,
32
+ performDeviceFlow: deps?.performDeviceFlow ?? defaultDeps.performDeviceFlow,
33
+ credentialsStore: deps?.credentialsStore ?? defaultDeps.credentialsStore,
34
+ };
35
+ }
36
+ function printHelp(stderr) {
37
+ stderr.write(`
38
+ auth login - Authenticate the Spekn CLI via browser-based device flow
39
+
40
+ USAGE:
41
+ spekn auth login [options]
42
+
43
+ OPTIONS:
44
+ --keycloak-url <url> Keycloak base URL (default: KEYCLOAK_URL or https://auth.spekn.com)
45
+ --realm <realm> Keycloak realm name (default: KEYCLOAK_REALM or spekn)
46
+ --help Show this help message
47
+
48
+ ENVIRONMENT:
49
+ KEYCLOAK_URL Keycloak base URL
50
+ KEYCLOAK_REALM Keycloak realm name
51
+
52
+ EXAMPLES:
53
+ spekn auth login
54
+ spekn auth login --keycloak-url https://auth.example.com --realm my-realm
55
+ `);
56
+ }
57
+ function parseArgs(args) {
58
+ const keycloakUrlDefault = process.env["KEYCLOAK_URL"] ?? "https://auth.spekn.com";
59
+ const realmDefault = process.env["KEYCLOAK_REALM"] ?? "spekn";
60
+ let keycloakUrl = keycloakUrlDefault;
61
+ let realm = realmDefault;
62
+ for (let index = 0; index < args.length; index++) {
63
+ const arg = args[index];
64
+ if (arg === "--help" || arg === "-h") {
65
+ throw new help_error_1.HelpRequestedError();
66
+ }
67
+ if (arg === "--keycloak-url" && args[index + 1]) {
68
+ keycloakUrl = args[++index];
69
+ continue;
70
+ }
71
+ if (arg.startsWith("--keycloak-url=")) {
72
+ keycloakUrl = arg.slice("--keycloak-url=".length);
73
+ continue;
74
+ }
75
+ if (arg === "--realm" && args[index + 1]) {
76
+ realm = args[++index];
77
+ continue;
78
+ }
79
+ if (arg.startsWith("--realm=")) {
80
+ realm = arg.slice("--realm=".length);
81
+ continue;
82
+ }
83
+ }
84
+ return { keycloakUrl, realm };
85
+ }
86
+ /**
87
+ * Decode the payload of a JWT access token without verification.
88
+ * Returns the raw claims object, or null if decoding fails.
89
+ */
90
+ function decodeJwtPayload(token) {
91
+ try {
92
+ const parts = token.split(".");
93
+ if (parts.length !== 3) {
94
+ return null;
95
+ }
96
+ // Base64url → standard base64
97
+ const base64 = parts[1]
98
+ .replace(/-/g, "+")
99
+ .replace(/_/g, "/");
100
+ // Pad to a multiple of 4
101
+ const padded = base64.padEnd(base64.length + ((4 - (base64.length % 4)) % 4), "=");
102
+ const json = Buffer.from(padded, "base64").toString("utf-8");
103
+ return JSON.parse(json);
104
+ }
105
+ catch {
106
+ return null;
107
+ }
108
+ }
109
+ async function runAuthLoginCli(args, deps) {
110
+ const resolved = resolveDeps(deps);
111
+ try {
112
+ const options = parseArgs(args);
113
+ (0, structured_log_1.appendCliStructuredLog)({
114
+ source: "cli.auth.login",
115
+ level: "info",
116
+ message: "Starting auth login",
117
+ details: { keycloakUrl: options.keycloakUrl, realm: options.realm },
118
+ });
119
+ const result = await resolved.performDeviceFlow(options.keycloakUrl, options.realm, "spekn-cli", { stdout: resolved.stdout, stderr: resolved.stderr });
120
+ // Decode the JWT payload to extract user identity fields.
121
+ const claims = decodeJwtPayload(result.accessToken);
122
+ const sub = typeof claims?.["sub"] === "string" ? claims["sub"] : "unknown";
123
+ const email = typeof claims?.["email"] === "string" ? claims["email"] : "unknown";
124
+ const name = typeof claims?.["name"] === "string"
125
+ ? claims["name"]
126
+ : typeof claims?.["preferred_username"] === "string"
127
+ ? claims["preferred_username"]
128
+ : undefined;
129
+ // Fetch the user's organizations from the API to resolve organizationId
130
+ const apiUrl = process.env.SPEKN_API_URL ?? "https://app.spekn.com";
131
+ const client = (0, client_1.createTRPCProxyClient)({
132
+ links: [
133
+ (0, client_1.httpBatchLink)({
134
+ url: (0, trpc_url_1.normalizeTrpcUrl)(apiUrl),
135
+ headers: {
136
+ authorization: `Bearer ${result.accessToken}`,
137
+ },
138
+ }),
139
+ ],
140
+ });
141
+ let organizationId;
142
+ try {
143
+ const orgs = await client.organization.list.query();
144
+ if (orgs.length === 1) {
145
+ organizationId = orgs[0].id;
146
+ }
147
+ else if (orgs.length > 1) {
148
+ resolved.stdout.write(`\nYou belong to ${orgs.length} organizations:\n`);
149
+ for (const org of orgs) {
150
+ resolved.stdout.write(` - ${org.name} (${org.id})\n`);
151
+ }
152
+ resolved.stdout.write(`\nAuto-selected first organization. Use SPEKN_ORGANIZATION_ID to override.\n`);
153
+ organizationId = orgs[0].id;
154
+ }
155
+ }
156
+ catch {
157
+ // Non-fatal — user can set SPEKN_ORGANIZATION_ID manually
158
+ }
159
+ const credentials = {
160
+ accessToken: result.accessToken,
161
+ refreshToken: result.refreshToken,
162
+ expiresAt: Date.now() + result.expiresIn * 1000,
163
+ keycloakUrl: options.keycloakUrl,
164
+ realm: options.realm,
165
+ organizationId,
166
+ user: { sub, email, name },
167
+ };
168
+ resolved.credentialsStore.save(credentials);
169
+ resolved.stdout.write(`Logged in as ${email}\n`);
170
+ if (organizationId) {
171
+ resolved.stdout.write(`Organization: ${organizationId}\n`);
172
+ }
173
+ (0, structured_log_1.appendCliStructuredLog)({
174
+ source: "cli.auth.login",
175
+ level: "info",
176
+ message: "Auth login completed",
177
+ details: { email, organizationId },
178
+ });
179
+ return 0;
180
+ }
181
+ catch (error) {
182
+ if (error instanceof help_error_1.HelpRequestedError) {
183
+ printHelp(resolved.stderr);
184
+ return 0;
185
+ }
186
+ const message = error instanceof Error ? error.message : String(error);
187
+ resolved.stderr.write(`Error: ${message}\n`);
188
+ (0, structured_log_1.appendCliStructuredLog)({
189
+ source: "cli.auth.login",
190
+ level: "error",
191
+ message,
192
+ });
193
+ return 1;
194
+ }
195
+ }
196
+ async function main() {
197
+ const exitCode = await runAuthLoginCli(process.argv.slice(2));
198
+ process.exit(exitCode);
199
+ }
200
+ if (require.main === module) {
201
+ void main();
202
+ }
@@ -0,0 +1,25 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * auth logout CLI command
4
+ *
5
+ * Revokes the stored refresh token against Keycloak (best-effort) and then
6
+ * removes the local credentials file at ~/.spekn/credentials.json.
7
+ *
8
+ * Usage: spekn auth logout
9
+ */
10
+ import { CredentialsStore } from "./auth/credentials-store.js";
11
+ interface Deps {
12
+ stdout: {
13
+ write(s: string): void;
14
+ };
15
+ stderr: {
16
+ write(s: string): void;
17
+ };
18
+ credentialsStore: CredentialsStore;
19
+ /** POST to the Keycloak logout endpoint. Injected for testing. */
20
+ revokeToken: (logoutUrl: string, body: URLSearchParams) => Promise<void>;
21
+ }
22
+ declare function parseArgs(args: string[]): void;
23
+ export declare function runAuthLogoutCli(args: string[], deps?: Partial<Deps>): Promise<number>;
24
+ declare function main(): Promise<void>;
25
+ export { main, parseArgs };
@@ -0,0 +1,115 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ /**
4
+ * auth logout CLI command
5
+ *
6
+ * Revokes the stored refresh token against Keycloak (best-effort) and then
7
+ * removes the local credentials file at ~/.spekn/credentials.json.
8
+ *
9
+ * Usage: spekn auth logout
10
+ */
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.runAuthLogoutCli = runAuthLogoutCli;
13
+ exports.main = main;
14
+ exports.parseArgs = parseArgs;
15
+ const credentials_store_js_1 = require("./auth/credentials-store.js");
16
+ const help_error_1 = require("./utils/help-error");
17
+ const structured_log_1 = require("./utils/structured-log");
18
+ /** Default revocation implementation — best-effort, ignores errors. */
19
+ async function defaultRevokeToken(logoutUrl, body) {
20
+ await fetch(logoutUrl, {
21
+ method: "POST",
22
+ headers: { "Content-Type": "application/x-www-form-urlencoded" },
23
+ body: body.toString(),
24
+ });
25
+ }
26
+ const defaultDeps = {
27
+ stdout: process.stdout,
28
+ stderr: process.stderr,
29
+ credentialsStore: new credentials_store_js_1.CredentialsStore(),
30
+ revokeToken: defaultRevokeToken,
31
+ };
32
+ function resolveDeps(deps) {
33
+ return {
34
+ stdout: deps?.stdout ?? defaultDeps.stdout,
35
+ stderr: deps?.stderr ?? defaultDeps.stderr,
36
+ credentialsStore: deps?.credentialsStore ?? defaultDeps.credentialsStore,
37
+ revokeToken: deps?.revokeToken ?? defaultDeps.revokeToken,
38
+ };
39
+ }
40
+ function printHelp(stderr) {
41
+ stderr.write(`
42
+ auth logout - Revoke the current session and remove stored credentials
43
+
44
+ USAGE:
45
+ spekn auth logout
46
+
47
+ OPTIONS:
48
+ --help Show this help message
49
+
50
+ EXAMPLES:
51
+ spekn auth logout
52
+ `);
53
+ }
54
+ function parseArgs(args) {
55
+ for (const arg of args) {
56
+ if (arg === "--help" || arg === "-h") {
57
+ throw new help_error_1.HelpRequestedError();
58
+ }
59
+ }
60
+ }
61
+ async function runAuthLogoutCli(args, deps) {
62
+ const resolved = resolveDeps(deps);
63
+ try {
64
+ parseArgs(args);
65
+ (0, structured_log_1.appendCliStructuredLog)({
66
+ source: "cli.auth.logout",
67
+ level: "info",
68
+ message: "Starting auth logout",
69
+ });
70
+ const credentials = resolved.credentialsStore.load();
71
+ if (credentials !== null && credentials.refreshToken) {
72
+ const logoutUrl = `${credentials.keycloakUrl}/realms/${credentials.realm}/protocol/openid-connect/logout`;
73
+ const body = new URLSearchParams({
74
+ client_id: "spekn-cli",
75
+ refresh_token: credentials.refreshToken,
76
+ });
77
+ try {
78
+ await resolved.revokeToken(logoutUrl, body);
79
+ }
80
+ catch {
81
+ // Best-effort: ignore revocation errors so local credentials are always
82
+ // cleared even when Keycloak is unreachable.
83
+ }
84
+ }
85
+ resolved.credentialsStore.clear();
86
+ resolved.stdout.write("Logged out successfully.\n");
87
+ (0, structured_log_1.appendCliStructuredLog)({
88
+ source: "cli.auth.logout",
89
+ level: "info",
90
+ message: "Auth logout completed",
91
+ });
92
+ return 0;
93
+ }
94
+ catch (error) {
95
+ if (error instanceof help_error_1.HelpRequestedError) {
96
+ printHelp(resolved.stderr);
97
+ return 0;
98
+ }
99
+ const message = error instanceof Error ? error.message : String(error);
100
+ resolved.stderr.write(`Error: ${message}\n`);
101
+ (0, structured_log_1.appendCliStructuredLog)({
102
+ source: "cli.auth.logout",
103
+ level: "error",
104
+ message,
105
+ });
106
+ return 1;
107
+ }
108
+ }
109
+ async function main() {
110
+ const exitCode = await runAuthLogoutCli(process.argv.slice(2));
111
+ process.exit(exitCode);
112
+ }
113
+ if (require.main === module) {
114
+ void main();
115
+ }
@@ -0,0 +1,24 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * auth status CLI command
4
+ *
5
+ * Displays the current authentication state: logged-in user, token expiry,
6
+ * and organization (if set). Attempts a silent token refresh when the stored
7
+ * token is expired but a refresh token is available.
8
+ *
9
+ * Usage: spekn auth status
10
+ */
11
+ import { CredentialsStore } from "./auth/credentials-store.js";
12
+ interface Deps {
13
+ stdout: {
14
+ write(s: string): void;
15
+ };
16
+ stderr: {
17
+ write(s: string): void;
18
+ };
19
+ credentialsStore: CredentialsStore;
20
+ }
21
+ declare function parseArgs(args: string[]): void;
22
+ export declare function runAuthStatusCli(args: string[], deps?: Partial<Deps>): Promise<number>;
23
+ declare function main(): Promise<void>;
24
+ export { main, parseArgs };
@@ -0,0 +1,109 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ /**
4
+ * auth status CLI command
5
+ *
6
+ * Displays the current authentication state: logged-in user, token expiry,
7
+ * and organization (if set). Attempts a silent token refresh when the stored
8
+ * token is expired but a refresh token is available.
9
+ *
10
+ * Usage: spekn auth status
11
+ */
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ exports.runAuthStatusCli = runAuthStatusCli;
14
+ exports.main = main;
15
+ exports.parseArgs = parseArgs;
16
+ const credentials_store_js_1 = require("./auth/credentials-store.js");
17
+ const help_error_1 = require("./utils/help-error");
18
+ const structured_log_1 = require("./utils/structured-log");
19
+ const defaultDeps = {
20
+ stdout: process.stdout,
21
+ stderr: process.stderr,
22
+ credentialsStore: new credentials_store_js_1.CredentialsStore(),
23
+ };
24
+ function resolveDeps(deps) {
25
+ return {
26
+ stdout: deps?.stdout ?? defaultDeps.stdout,
27
+ stderr: deps?.stderr ?? defaultDeps.stderr,
28
+ credentialsStore: deps?.credentialsStore ?? defaultDeps.credentialsStore,
29
+ };
30
+ }
31
+ function printHelp(stderr) {
32
+ stderr.write(`
33
+ auth status - Show the current authentication status
34
+
35
+ USAGE:
36
+ spekn auth status
37
+
38
+ OPTIONS:
39
+ --help Show this help message
40
+
41
+ EXAMPLES:
42
+ spekn auth status
43
+ `);
44
+ }
45
+ function parseArgs(args) {
46
+ for (const arg of args) {
47
+ if (arg === "--help" || arg === "-h") {
48
+ throw new help_error_1.HelpRequestedError();
49
+ }
50
+ }
51
+ }
52
+ async function runAuthStatusCli(args, deps) {
53
+ const resolved = resolveDeps(deps);
54
+ try {
55
+ parseArgs(args);
56
+ (0, structured_log_1.appendCliStructuredLog)({
57
+ source: "cli.auth.status",
58
+ level: "info",
59
+ message: "Checking auth status",
60
+ });
61
+ const credentials = resolved.credentialsStore.load();
62
+ if (credentials === null) {
63
+ resolved.stdout.write("Not logged in. Run `spekn auth login` to authenticate.\n");
64
+ return 1;
65
+ }
66
+ const token = await resolved.credentialsStore.getValidToken();
67
+ if (token === null) {
68
+ resolved.stdout.write("Session expired. Run `spekn auth login` to re-authenticate.\n");
69
+ return 1;
70
+ }
71
+ // Reload credentials after a potential refresh so we report the updated
72
+ // expiry time rather than the stale one.
73
+ const fresh = resolved.credentialsStore.load() ?? credentials;
74
+ const email = fresh.user?.email ?? "unknown";
75
+ const expiresAt = new Date(fresh.expiresAt).toLocaleString();
76
+ const orgId = fresh.organizationId ?? "not set";
77
+ resolved.stdout.write(`Logged in as ${email}\n`);
78
+ resolved.stdout.write(`Token expires: ${expiresAt}\n`);
79
+ resolved.stdout.write(`Organization: ${orgId}\n`);
80
+ (0, structured_log_1.appendCliStructuredLog)({
81
+ source: "cli.auth.status",
82
+ level: "info",
83
+ message: "Auth status available",
84
+ details: { email, organizationId: orgId },
85
+ });
86
+ return 0;
87
+ }
88
+ catch (error) {
89
+ if (error instanceof help_error_1.HelpRequestedError) {
90
+ printHelp(resolved.stderr);
91
+ return 0;
92
+ }
93
+ const message = error instanceof Error ? error.message : String(error);
94
+ resolved.stderr.write(`Error: ${message}\n`);
95
+ (0, structured_log_1.appendCliStructuredLog)({
96
+ source: "cli.auth.status",
97
+ level: "error",
98
+ message,
99
+ });
100
+ return 1;
101
+ }
102
+ }
103
+ async function main() {
104
+ const exitCode = await runAuthStatusCli(process.argv.slice(2));
105
+ process.exit(exitCode);
106
+ }
107
+ if (require.main === module) {
108
+ void main();
109
+ }
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * backlog-generate CLI Tool
4
+ *
5
+ * Auto-generate tasks from specification anchors.
6
+ *
7
+ * Usage: npm run backlog-generate <spec-file-path> [OPTIONS]
8
+ * Example: npm run backlog-generate specs/WORKFLOW.md --project-id=<uuid>
9
+ */
10
+ declare function main(argv?: string[]): Promise<number>;
11
+ export { main };