peaks-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 (143) hide show
  1. package/LICENSE +52 -0
  2. package/README.md +417 -0
  3. package/bin/peaks.js +2 -0
  4. package/dist/src/cli/cli-helpers.d.ts +25 -0
  5. package/dist/src/cli/cli-helpers.js +78 -0
  6. package/dist/src/cli/commands/capability-commands.d.ts +5 -0
  7. package/dist/src/cli/commands/capability-commands.js +46 -0
  8. package/dist/src/cli/commands/capability-worker-config-sc-commands.d.ts +3 -0
  9. package/dist/src/cli/commands/capability-worker-config-sc-commands.js +10 -0
  10. package/dist/src/cli/commands/config-commands.d.ts +3 -0
  11. package/dist/src/cli/commands/config-commands.js +212 -0
  12. package/dist/src/cli/commands/core-artifact-commands.d.ts +3 -0
  13. package/dist/src/cli/commands/core-artifact-commands.js +200 -0
  14. package/dist/src/cli/commands/sc-commands.d.ts +3 -0
  15. package/dist/src/cli/commands/sc-commands.js +37 -0
  16. package/dist/src/cli/commands/worker-commands.d.ts +3 -0
  17. package/dist/src/cli/commands/worker-commands.js +52 -0
  18. package/dist/src/cli/commands/workflow-commands.d.ts +3 -0
  19. package/dist/src/cli/commands/workflow-commands.js +257 -0
  20. package/dist/src/cli/index.d.ts +1 -0
  21. package/dist/src/cli/index.js +14 -0
  22. package/dist/src/cli/program.d.ts +4 -0
  23. package/dist/src/cli/program.js +13 -0
  24. package/dist/src/services/artifacts/artifact-service.d.ts +43 -0
  25. package/dist/src/services/artifacts/artifact-service.js +97 -0
  26. package/dist/src/services/artifacts/workspace-service.d.ts +33 -0
  27. package/dist/src/services/artifacts/workspace-service.js +254 -0
  28. package/dist/src/services/config/config-service.d.ts +29 -0
  29. package/dist/src/services/config/config-service.js +501 -0
  30. package/dist/src/services/config/config-types.d.ts +63 -0
  31. package/dist/src/services/config/config-types.js +16 -0
  32. package/dist/src/services/config/model-routing.d.ts +4 -0
  33. package/dist/src/services/config/model-routing.js +15 -0
  34. package/dist/src/services/doctor/doctor-service.d.ts +18 -0
  35. package/dist/src/services/doctor/doctor-service.js +68 -0
  36. package/dist/src/services/memory/project-memory-service.d.ts +79 -0
  37. package/dist/src/services/memory/project-memory-service.js +306 -0
  38. package/dist/src/services/profiles/profile-service.d.ts +6 -0
  39. package/dist/src/services/profiles/profile-service.js +19 -0
  40. package/dist/src/services/providers/minimax-provider-service.d.ts +24 -0
  41. package/dist/src/services/providers/minimax-provider-service.js +143 -0
  42. package/dist/src/services/providers/minimax-worker-service.d.ts +21 -0
  43. package/dist/src/services/providers/minimax-worker-service.js +80 -0
  44. package/dist/src/services/proxy/proxy-service.d.ts +7 -0
  45. package/dist/src/services/proxy/proxy-service.js +31 -0
  46. package/dist/src/services/rd/rd-service.d.ts +88 -0
  47. package/dist/src/services/rd/rd-service.js +370 -0
  48. package/dist/src/services/recommendations/capability-availability.d.ts +5 -0
  49. package/dist/src/services/recommendations/capability-availability.js +40 -0
  50. package/dist/src/services/recommendations/capability-map-service.d.ts +7 -0
  51. package/dist/src/services/recommendations/capability-map-service.js +131 -0
  52. package/dist/src/services/recommendations/capability-seed-items.d.ts +2 -0
  53. package/dist/src/services/recommendations/capability-seed-items.js +131 -0
  54. package/dist/src/services/recommendations/capability-seed-mappings.d.ts +2 -0
  55. package/dist/src/services/recommendations/capability-seed-mappings.js +42 -0
  56. package/dist/src/services/recommendations/capability-seed-sources.d.ts +2 -0
  57. package/dist/src/services/recommendations/capability-seed-sources.js +35 -0
  58. package/dist/src/services/recommendations/recommendation-service.d.ts +8 -0
  59. package/dist/src/services/recommendations/recommendation-service.js +106 -0
  60. package/dist/src/services/recommendations/recommendation-types.d.ts +129 -0
  61. package/dist/src/services/recommendations/recommendation-types.js +1 -0
  62. package/dist/src/services/recommendations/seed-capability-catalog.d.ts +3 -0
  63. package/dist/src/services/recommendations/seed-capability-catalog.js +3 -0
  64. package/dist/src/services/refactor/refactor-service.d.ts +9 -0
  65. package/dist/src/services/refactor/refactor-service.js +33 -0
  66. package/dist/src/services/sc/index.d.ts +1 -0
  67. package/dist/src/services/sc/index.js +1 -0
  68. package/dist/src/services/sc/sc-service.d.ts +79 -0
  69. package/dist/src/services/sc/sc-service.js +223 -0
  70. package/dist/src/services/skills/skill-registry.d.ts +17 -0
  71. package/dist/src/services/skills/skill-registry.js +40 -0
  72. package/dist/src/services/standards/project-standards-service.d.ts +82 -0
  73. package/dist/src/services/standards/project-standards-service.js +383 -0
  74. package/dist/src/services/tech/tech-service.d.ts +69 -0
  75. package/dist/src/services/tech/tech-service.js +236 -0
  76. package/dist/src/services/workflow/workflow-autonomous-service.d.ts +99 -0
  77. package/dist/src/services/workflow/workflow-autonomous-service.js +526 -0
  78. package/dist/src/services/workflow/workflow-router-service.d.ts +85 -0
  79. package/dist/src/services/workflow/workflow-router-service.js +213 -0
  80. package/dist/src/shared/change-id.d.ts +15 -0
  81. package/dist/src/shared/change-id.js +76 -0
  82. package/dist/src/shared/frontmatter.d.ts +6 -0
  83. package/dist/src/shared/frontmatter.js +47 -0
  84. package/dist/src/shared/fs-utils.d.ts +4 -0
  85. package/dist/src/shared/fs-utils.js +16 -0
  86. package/dist/src/shared/fs.d.ts +4 -0
  87. package/dist/src/shared/fs.js +26 -0
  88. package/dist/src/shared/path-utils.d.ts +13 -0
  89. package/dist/src/shared/path-utils.js +56 -0
  90. package/dist/src/shared/paths.d.ts +6 -0
  91. package/dist/src/shared/paths.js +40 -0
  92. package/dist/src/shared/planner-response.d.ts +21 -0
  93. package/dist/src/shared/planner-response.js +26 -0
  94. package/dist/src/shared/platform.d.ts +6 -0
  95. package/dist/src/shared/platform.js +11 -0
  96. package/dist/src/shared/process.d.ts +5 -0
  97. package/dist/src/shared/process.js +12 -0
  98. package/dist/src/shared/result.d.ts +13 -0
  99. package/dist/src/shared/result.js +32 -0
  100. package/package.json +49 -0
  101. package/schemas/approval-record.schema.json +14 -0
  102. package/schemas/artifact-manifest.schema.json +16 -0
  103. package/schemas/artifact-retention-report.schema.json +17 -0
  104. package/schemas/artifact-workspace.schema.json +22 -0
  105. package/schemas/capability-availability.schema.json +36 -0
  106. package/schemas/capability-item.schema.json +37 -0
  107. package/schemas/capability-source.schema.json +30 -0
  108. package/schemas/change-impact.schema.json +15 -0
  109. package/schemas/context-capsule.schema.json +16 -0
  110. package/schemas/recommendation-plan.schema.json +37 -0
  111. package/schemas/refactor-slice-spec.schema.json +19 -0
  112. package/scripts/clean-dist.mjs +8 -0
  113. package/scripts/install-skills.mjs +76 -0
  114. package/scripts/watch.mjs +389 -0
  115. package/skills/peaks-prd/SKILL.md +42 -0
  116. package/skills/peaks-prd/references/artifact-contracts.md +3 -0
  117. package/skills/peaks-prd/references/command-migration.md +3 -0
  118. package/skills/peaks-prd/references/workflow.md +11 -0
  119. package/skills/peaks-qa/SKILL.md +45 -0
  120. package/skills/peaks-qa/references/artifact-contracts.md +3 -0
  121. package/skills/peaks-qa/references/command-migration.md +3 -0
  122. package/skills/peaks-qa/references/regression-gates.md +16 -0
  123. package/skills/peaks-rd/SKILL.md +56 -0
  124. package/skills/peaks-rd/references/artifact-contracts.md +3 -0
  125. package/skills/peaks-rd/references/command-migration.md +3 -0
  126. package/skills/peaks-rd/references/refactor-workflow.md +31 -0
  127. package/skills/peaks-sc/SKILL.md +30 -0
  128. package/skills/peaks-sc/references/artifact-contracts.md +3 -0
  129. package/skills/peaks-sc/references/artifact-retention.md +14 -0
  130. package/skills/peaks-sc/references/command-migration.md +3 -0
  131. package/skills/peaks-solo/SKILL.md +63 -0
  132. package/skills/peaks-solo/references/artifact-contracts.md +3 -0
  133. package/skills/peaks-solo/references/command-migration.md +3 -0
  134. package/skills/peaks-solo/references/refactor-mode.md +22 -0
  135. package/skills/peaks-solo/references/workflow.md +14 -0
  136. package/skills/peaks-txt/SKILL.md +48 -0
  137. package/skills/peaks-txt/references/artifact-contracts.md +3 -0
  138. package/skills/peaks-txt/references/command-migration.md +3 -0
  139. package/skills/peaks-txt/references/context-capsule.md +20 -0
  140. package/skills/peaks-ui/SKILL.md +35 -0
  141. package/skills/peaks-ui/references/artifact-contracts.md +3 -0
  142. package/skills/peaks-ui/references/command-migration.md +3 -0
  143. package/skills/peaks-ui/references/workflow.md +11 -0
@@ -0,0 +1,254 @@
1
+ import { existsSync } from 'node:fs';
2
+ import { Buffer } from 'node:buffer';
3
+ import { basename, dirname, resolve } from 'node:path';
4
+ import { isInsidePath, stablePath } from '../../shared/path-utils.js';
5
+ import { readConfig, getCurrentWorkspaceConfig } from '../config/config-service.js';
6
+ import { pathExists } from '../../shared/fs.js';
7
+ import { execCommand } from '../../shared/process.js';
8
+ function canonicalPath(path) {
9
+ return stablePath(path);
10
+ }
11
+ function canonicalChildPath(parentPath, ...segments) {
12
+ return stablePath(resolve(parentPath, ...segments));
13
+ }
14
+ export function getLocalArtifactPath(workspace) {
15
+ const rootPath = resolve(workspace.rootPath);
16
+ return resolve(dirname(rootPath), `${basename(rootPath)}.peaks-artifacts`);
17
+ }
18
+ export function isArtifactWorkspaceOutsideTarget(workspace, artifactWorkspacePath = getLocalArtifactPath(workspace)) {
19
+ const targetRoot = canonicalPath(workspace.rootPath);
20
+ const artifactRoot = canonicalPath(artifactWorkspacePath);
21
+ return !isInsidePath(artifactRoot, targetRoot);
22
+ }
23
+ export function hasValidArtifactWorkspace(workspace, artifactWorkspacePath = getLocalArtifactPath(workspace)) {
24
+ if (!isArtifactWorkspaceOutsideTarget(workspace, artifactWorkspacePath))
25
+ return false;
26
+ const artifactRoot = canonicalPath(artifactWorkspacePath);
27
+ const peaksRoot = canonicalChildPath(artifactWorkspacePath, '.peaks');
28
+ const changesRoot = canonicalChildPath(artifactWorkspacePath, '.peaks', 'changes');
29
+ const configPath = canonicalChildPath(artifactWorkspacePath, '.peaks', 'config.json');
30
+ const targetRoot = canonicalPath(workspace.rootPath);
31
+ if (!existsSync(resolve(artifactWorkspacePath, '.peaks', 'config.json')))
32
+ return false;
33
+ if (!isInsidePath(peaksRoot, artifactRoot))
34
+ return false;
35
+ if (!isInsidePath(changesRoot, artifactRoot))
36
+ return false;
37
+ if (!isInsidePath(configPath, artifactRoot))
38
+ return false;
39
+ if (isInsidePath(peaksRoot, targetRoot))
40
+ return false;
41
+ if (isInsidePath(changesRoot, targetRoot))
42
+ return false;
43
+ if (isInsidePath(configPath, targetRoot))
44
+ return false;
45
+ return true;
46
+ }
47
+ function getPublicRemoteUrl(artifactRepo) {
48
+ if (!artifactRepo)
49
+ return null;
50
+ return artifactRepo.provider === 'github'
51
+ ? `https://github.com/${artifactRepo.owner}/${artifactRepo.name}.git`
52
+ : `https://gitlab.com/${artifactRepo.owner}/${artifactRepo.name}.git`;
53
+ }
54
+ function getGitAuthEnv(artifactRepo) {
55
+ if (!artifactRepo || artifactRepo.provider !== 'github')
56
+ return undefined;
57
+ const token = process.env.GH_TOKEN;
58
+ if (!token)
59
+ return undefined;
60
+ const authValue = Buffer.from(`x-access-token:${token}`, 'utf-8').toString('base64');
61
+ return {
62
+ ...process.env,
63
+ GIT_CONFIG_COUNT: '1',
64
+ GIT_CONFIG_KEY_0: 'http.https://github.com/.extraheader',
65
+ GIT_CONFIG_VALUE_0: `AUTHORIZATION: basic ${authValue}`
66
+ };
67
+ }
68
+ function redactSecrets(message) {
69
+ const token = process.env.GH_TOKEN;
70
+ const urlRedacted = message.replace(/https:\/\/x-access-token:[^@]+@/g, 'https://x-access-token:***@');
71
+ const headerRedacted = urlRedacted.replace(/AUTHORIZATION:\s*basic\s+[A-Za-z0-9+/=]+/gi, 'AUTHORIZATION: basic ***');
72
+ if (!token)
73
+ return headerRedacted;
74
+ const encoded = Buffer.from(`x-access-token:${token}`, 'utf-8').toString('base64');
75
+ return headerRedacted.replaceAll(token, '***').replaceAll(encoded, '***');
76
+ }
77
+ export async function executeArtifactSync(workspaceId) {
78
+ const workspace = workspaceId
79
+ ? readConfig().workspaces.find((w) => w.workspaceId === workspaceId) ?? null
80
+ : getCurrentWorkspaceConfig();
81
+ if (!workspace || !workspace.artifactRepo) {
82
+ return {
83
+ workspaceId: workspaceId ?? 'unknown',
84
+ success: false,
85
+ localPath: '.peaks-artifacts',
86
+ remoteUrl: null,
87
+ commands: [],
88
+ output: [],
89
+ error: 'No artifact repository configured for this workspace'
90
+ };
91
+ }
92
+ const localPath = getLocalArtifactPath(workspace);
93
+ if (!isArtifactWorkspaceOutsideTarget(workspace, localPath)) {
94
+ return {
95
+ workspaceId: workspace.workspaceId,
96
+ success: false,
97
+ localPath,
98
+ remoteUrl: null,
99
+ commands: [],
100
+ output: [],
101
+ error: 'Artifact workspace must be outside the target repository'
102
+ };
103
+ }
104
+ const remoteUrl = getPublicRemoteUrl(workspace.artifactRepo);
105
+ const gitAuthEnv = getGitAuthEnv(workspace.artifactRepo);
106
+ if (!remoteUrl) {
107
+ return {
108
+ workspaceId: workspace.workspaceId,
109
+ success: false,
110
+ localPath,
111
+ remoteUrl: null,
112
+ commands: [],
113
+ output: [],
114
+ error: 'Invalid artifact repository configuration'
115
+ };
116
+ }
117
+ const commands = [];
118
+ const output = [];
119
+ const hasLocalDir = await pathExists(localPath);
120
+ if (!hasLocalDir) {
121
+ commands.push(`git clone ${remoteUrl} "${localPath}"`);
122
+ try {
123
+ await execCommand('git', ['clone', remoteUrl, localPath], { env: gitAuthEnv });
124
+ output.push(`Cloned artifact repository to ${localPath}`);
125
+ }
126
+ catch (err) {
127
+ return {
128
+ workspaceId: workspace.workspaceId,
129
+ success: false,
130
+ localPath,
131
+ remoteUrl,
132
+ commands,
133
+ output,
134
+ error: `Clone failed: ${redactSecrets(err instanceof Error ? err.message : String(err))}`
135
+ };
136
+ }
137
+ }
138
+ else {
139
+ commands.push(`cd "${localPath}" && git fetch origin`);
140
+ commands.push(`cd "${localPath}" && git pull origin main`);
141
+ try {
142
+ await execCommand('git', ['fetch', 'origin'], { cwd: localPath, env: gitAuthEnv });
143
+ output.push('Fetched latest from remote');
144
+ await execCommand('git', ['pull', 'origin', 'main'], { cwd: localPath, env: gitAuthEnv });
145
+ output.push('Pulled latest changes');
146
+ }
147
+ catch (err) {
148
+ return {
149
+ workspaceId: workspace.workspaceId,
150
+ success: false,
151
+ localPath,
152
+ remoteUrl,
153
+ commands,
154
+ output,
155
+ error: `Sync failed: ${redactSecrets(err instanceof Error ? err.message : String(err))}`
156
+ };
157
+ }
158
+ }
159
+ return {
160
+ workspaceId: workspace.workspaceId,
161
+ success: true,
162
+ localPath,
163
+ remoteUrl,
164
+ commands,
165
+ output
166
+ };
167
+ }
168
+ export function getArtifactWorkspaceStatus(workspaceId) {
169
+ const workspace = workspaceId
170
+ ? readConfig().workspaces.find((w) => w.workspaceId === workspaceId) ?? null
171
+ : getCurrentWorkspaceConfig();
172
+ if (!workspace) {
173
+ return {
174
+ workspaceId: workspaceId ?? 'unknown',
175
+ localPath: '.peaks-artifacts',
176
+ configured: false,
177
+ syncStatus: 'unknown',
178
+ lastSync: null,
179
+ hasLocalChanges: false,
180
+ artifactRepo: null,
181
+ nextActions: ['Add a workspace with: peaks config workspace add --id <id> --name <name> --path <path>']
182
+ };
183
+ }
184
+ const localPath = getLocalArtifactPath(workspace);
185
+ const hasLocalDir = existsSync(localPath);
186
+ const hasArtifactRepo = !!workspace.artifactRepo;
187
+ const hasSafeBoundary = isArtifactWorkspaceOutsideTarget(workspace, localPath);
188
+ const syncStatus = !hasArtifactRepo || !hasSafeBoundary
189
+ ? 'unknown'
190
+ : !hasLocalDir
191
+ ? 'pending'
192
+ : 'synced';
193
+ return {
194
+ workspaceId: workspace.workspaceId,
195
+ localPath,
196
+ configured: hasArtifactRepo && hasSafeBoundary,
197
+ syncStatus,
198
+ lastSync: null,
199
+ hasLocalChanges: false,
200
+ artifactRepo: workspace.artifactRepo ?? null,
201
+ nextActions: !hasSafeBoundary
202
+ ? ['Configure artifact workspace outside the target repository.']
203
+ : hasArtifactRepo
204
+ ? [`Run peaks artifacts sync --workspace ${workspace.workspaceId} --dry-run`]
205
+ : [`Configure artifact repo: peaks config workspace add --id ${workspace.workspaceId} --provider github --repo-owner <owner> --repo-name <name>`]
206
+ };
207
+ }
208
+ export function planArtifactSync(workspaceId, dryRun = true) {
209
+ const workspace = workspaceId
210
+ ? readConfig().workspaces.find((w) => w.workspaceId === workspaceId) ?? null
211
+ : getCurrentWorkspaceConfig();
212
+ if (!workspace || !workspace.artifactRepo) {
213
+ return {
214
+ workspaceId: workspaceId ?? 'unknown',
215
+ dryRun,
216
+ localPath: '.peaks-artifacts',
217
+ remoteUrl: null,
218
+ plannedCommands: ['No artifact repo configured — add one with peaks config workspace add --provider github --repo-owner <owner> --repo-name <name>']
219
+ };
220
+ }
221
+ const localPath = getLocalArtifactPath(workspace);
222
+ if (!isArtifactWorkspaceOutsideTarget(workspace, localPath)) {
223
+ return {
224
+ workspaceId: workspace.workspaceId,
225
+ dryRun,
226
+ localPath,
227
+ remoteUrl: null,
228
+ plannedCommands: ['Artifact workspace must be outside the target repository']
229
+ };
230
+ }
231
+ const remoteUrl = workspace.artifactRepo.provider === 'github'
232
+ ? `https://github.com/${workspace.artifactRepo.owner}/${workspace.artifactRepo.name}.git`
233
+ : `https://gitlab.com/${workspace.artifactRepo.owner}/${workspace.artifactRepo.name}.git`;
234
+ const plannedCommands = dryRun
235
+ ? [
236
+ `# Sync plan for workspace ${workspace.workspaceId}`,
237
+ `# Local: ${localPath}`,
238
+ `# Remote: ${remoteUrl}`,
239
+ '# peaks artifacts sync --workspace ' + workspace.workspaceId,
240
+ '# (dry-run only — no changes made)'
241
+ ]
242
+ : [
243
+ `# Sync execution for workspace ${workspace.workspaceId}`,
244
+ `# Confirm: will sync ${localPath} with ${remoteUrl}`,
245
+ '# Exit 1 if not confirmed'
246
+ ];
247
+ return {
248
+ workspaceId: workspace.workspaceId,
249
+ dryRun,
250
+ localPath,
251
+ remoteUrl,
252
+ plannedCommands
253
+ };
254
+ }
@@ -0,0 +1,29 @@
1
+ import type { ConfigGetOptions, ConfigLayer, ConfigSetOptions, MiniMaxProviderConfig, PeaksConfig, TokenRef, WorkspaceConfig } from './config-types.js';
2
+ export declare function isConfigLayer(value: string): value is ConfigLayer;
3
+ export declare function isSensitiveConfigPath(path: string): boolean;
4
+ export declare function containsSensitiveConfigValue(value: unknown): boolean;
5
+ export type RedactedConfigValue = string | number | boolean | null | RedactedConfigValue[] | {
6
+ [key: string]: RedactedConfigValue;
7
+ };
8
+ export declare function redactConfigSecrets(value: unknown, path?: string): RedactedConfigValue;
9
+ export type MiniMaxProviderStatus = {
10
+ provider: 'minimax';
11
+ configured: boolean;
12
+ baseUrlConfigured: boolean;
13
+ apiKeyConfigured: boolean;
14
+ storage: 'user-plaintext-v1';
15
+ nextActions: string[];
16
+ };
17
+ export declare function getMiniMaxProviderConfig(): MiniMaxProviderConfig;
18
+ export declare function getMiniMaxProviderStatus(): MiniMaxProviderStatus;
19
+ export declare function setMiniMaxProviderConfig(input: MiniMaxProviderConfig): MiniMaxProviderStatus;
20
+ export declare function readConfig(projectRoot?: string | null): PeaksConfig;
21
+ export declare function writeConfig(partial: Partial<PeaksConfig>, layer?: ConfigLayer): void;
22
+ export declare function getConfig(options?: ConfigGetOptions): unknown;
23
+ export declare function setConfig(options: ConfigSetOptions): void;
24
+ export declare function getWorkspaceConfig(workspaceId: string, projectRoot?: string | null): WorkspaceConfig | null;
25
+ export declare function addWorkspace(workspace: WorkspaceConfig, layer?: ConfigLayer): void;
26
+ export declare function removeWorkspace(workspaceId: string, layer?: ConfigLayer): boolean;
27
+ export declare function setCurrentWorkspace(workspaceId: string, layer?: ConfigLayer): boolean;
28
+ export declare function getCurrentWorkspaceConfig(): WorkspaceConfig | null;
29
+ export type { TokenRef, WorkspaceConfig, PeaksConfig, ConfigLayer };