vigthoria-cli 1.13.20 → 1.13.23

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 (187) hide show
  1. package/completions/_vigthoria +49 -0
  2. package/completions/vigthoria.bash +6 -0
  3. package/completions/vigthoria.fish +41 -0
  4. package/dist/commands/auth.d.ts +1 -0
  5. package/dist/commands/auth.js +63 -128
  6. package/dist/commands/background.d.ts +0 -2
  7. package/dist/commands/background.js +26 -34
  8. package/dist/commands/bridge.js +45 -41
  9. package/dist/commands/cancel.d.ts +1 -0
  10. package/dist/commands/cancel.js +22 -16
  11. package/dist/commands/chat.d.ts +3 -42
  12. package/dist/commands/chat.js +378 -1123
  13. package/dist/commands/coding-registration.d.ts +4 -0
  14. package/dist/commands/coding-registration.js +24 -0
  15. package/dist/commands/config.js +23 -29
  16. package/dist/commands/conversation-registration.d.ts +4 -0
  17. package/dist/commands/conversation-registration.js +122 -0
  18. package/dist/commands/deploy.d.ts +8 -2
  19. package/dist/commands/deploy.js +92 -90
  20. package/dist/commands/device.d.ts +1 -2
  21. package/dist/commands/device.js +37 -21
  22. package/dist/commands/doctor-registration.d.ts +4 -0
  23. package/dist/commands/doctor-registration.js +207 -0
  24. package/dist/commands/edit.js +22 -33
  25. package/dist/commands/explain.js +7 -10
  26. package/dist/commands/fork.d.ts +1 -2
  27. package/dist/commands/fork.js +72 -22
  28. package/dist/commands/game.d.ts +1 -1
  29. package/dist/commands/game.js +17 -6
  30. package/dist/commands/generate.js +7 -9
  31. package/dist/commands/history.js +11 -7
  32. package/dist/commands/hub.d.ts +2 -2
  33. package/dist/commands/hub.js +34 -35
  34. package/dist/commands/legion.d.ts +0 -1
  35. package/dist/commands/legion.js +62 -79
  36. package/dist/commands/music.d.ts +1 -2
  37. package/dist/commands/music.js +62 -27
  38. package/dist/commands/platform-registration.d.ts +4 -0
  39. package/dist/commands/platform-registration.js +45 -0
  40. package/dist/commands/preview.d.ts +0 -1
  41. package/dist/commands/preview.js +82 -35
  42. package/dist/commands/product-run-registration.d.ts +4 -0
  43. package/dist/commands/product-run-registration.js +490 -0
  44. package/dist/commands/replay.d.ts +1 -2
  45. package/dist/commands/replay.js +15 -11
  46. package/dist/commands/repo.d.ts +14 -7
  47. package/dist/commands/repo.js +244 -198
  48. package/dist/commands/review.js +9 -12
  49. package/dist/commands/security.d.ts +1 -2
  50. package/dist/commands/security.js +12 -6
  51. package/dist/commands/update-registration.d.ts +3 -0
  52. package/dist/commands/update-registration.js +368 -0
  53. package/dist/commands/v4-registration.d.ts +4 -0
  54. package/dist/commands/v4-registration.js +24 -0
  55. package/dist/commands/v4.d.ts +1 -1
  56. package/dist/commands/v4.js +46 -8
  57. package/dist/commands/wallet.d.ts +1 -3
  58. package/dist/commands/wallet.js +18 -45
  59. package/dist/commands/workflow.d.ts +2 -0
  60. package/dist/commands/workflow.js +52 -39
  61. package/dist/index.js +124 -1589
  62. package/dist/utils/agent-stream-state.d.ts +27 -0
  63. package/dist/utils/agent-stream-state.js +93 -0
  64. package/dist/utils/agentRoute.d.ts +2 -1
  65. package/dist/utils/agentRoute.js +22 -9
  66. package/dist/utils/agentRunOutcome.d.ts +16 -0
  67. package/dist/utils/agentRunOutcome.js +37 -2
  68. package/dist/utils/api-client-factory.d.ts +8 -0
  69. package/dist/utils/api-client-factory.js +8 -0
  70. package/dist/utils/api.d.ts +44 -266
  71. package/dist/utils/api.js +647 -3180
  72. package/dist/utils/auth-session.d.ts +41 -0
  73. package/dist/utils/auth-session.js +224 -0
  74. package/dist/utils/brain-hub-client.d.ts +0 -4
  75. package/dist/utils/brain-hub-client.js +6 -3
  76. package/dist/utils/bridge-client.js +2 -0
  77. package/dist/utils/capability-health-service.d.ts +48 -0
  78. package/dist/utils/capability-health-service.js +64 -0
  79. package/dist/utils/chat-prompt-policy.d.ts +18 -0
  80. package/dist/utils/chat-prompt-policy.js +61 -0
  81. package/dist/utils/chat-tool-call-parser.d.ts +11 -0
  82. package/dist/utils/chat-tool-call-parser.js +71 -0
  83. package/dist/utils/cli-state.d.ts +22 -4
  84. package/dist/utils/cli-state.js +105 -47
  85. package/dist/utils/code-operations-service.d.ts +104 -0
  86. package/dist/utils/code-operations-service.js +837 -0
  87. package/dist/utils/codebase-indexer.d.ts +1 -0
  88. package/dist/utils/codebase-indexer.js +28 -8
  89. package/dist/utils/command-contract.d.ts +61 -0
  90. package/dist/utils/command-contract.js +149 -0
  91. package/dist/utils/command-policy.d.ts +10 -0
  92. package/dist/utils/command-policy.js +54 -0
  93. package/dist/utils/config.d.ts +13 -5
  94. package/dist/utils/config.js +220 -94
  95. package/dist/utils/context-ranker.js +11 -2
  96. package/dist/utils/context-state.d.ts +39 -0
  97. package/dist/utils/context-state.js +52 -0
  98. package/dist/utils/deckEvents.d.ts +0 -5
  99. package/dist/utils/deckEvents.js +3 -2
  100. package/dist/utils/desktop-bridge-client.js +2 -0
  101. package/dist/utils/direct-output-policy.d.ts +3 -0
  102. package/dist/utils/direct-output-policy.js +76 -0
  103. package/dist/utils/durable-json.d.ts +57 -0
  104. package/dist/utils/durable-json.js +319 -0
  105. package/dist/utils/fastAgentRouter.d.ts +5 -6
  106. package/dist/utils/fastAgentRouter.js +17 -25
  107. package/dist/utils/files.js +21 -13
  108. package/dist/utils/frontend-preview-service.d.ts +76 -0
  109. package/dist/utils/frontend-preview-service.js +482 -0
  110. package/dist/utils/goaEvents.d.ts +0 -4
  111. package/dist/utils/goaEvents.js +5 -2
  112. package/dist/utils/logger.d.ts +2 -1
  113. package/dist/utils/logger.js +27 -20
  114. package/dist/utils/mcp-context-client.d.ts +24 -0
  115. package/dist/utils/mcp-context-client.js +58 -0
  116. package/dist/utils/model-governance.d.ts +18 -0
  117. package/dist/utils/model-governance.js +75 -0
  118. package/dist/utils/model-transport-service.d.ts +44 -0
  119. package/dist/utils/model-transport-service.js +111 -0
  120. package/dist/utils/mutation-journal.d.ts +42 -0
  121. package/dist/utils/mutation-journal.js +387 -0
  122. package/dist/utils/network-policy.d.ts +24 -0
  123. package/dist/utils/network-policy.js +202 -0
  124. package/dist/utils/operator-client.d.ts +45 -0
  125. package/dist/utils/operator-client.js +159 -0
  126. package/dist/utils/post-write-validator.js +7 -9
  127. package/dist/utils/preview-screenshot-adapter.d.ts +15 -0
  128. package/dist/utils/preview-screenshot-adapter.js +51 -0
  129. package/dist/utils/process-policy.d.ts +23 -0
  130. package/dist/utils/process-policy.js +284 -0
  131. package/dist/utils/project-memory.d.ts +13 -3
  132. package/dist/utils/project-memory.js +70 -17
  133. package/dist/utils/prompt-workspace-resolver.d.ts +14 -0
  134. package/dist/utils/prompt-workspace-resolver.js +64 -0
  135. package/dist/utils/release-install.d.ts +11 -0
  136. package/dist/utils/release-install.js +155 -0
  137. package/dist/utils/release-policy.d.ts +64 -0
  138. package/dist/utils/release-policy.js +293 -0
  139. package/dist/utils/requestIntent.js +22 -3
  140. package/dist/utils/runtime-capability.d.ts +8 -0
  141. package/dist/utils/runtime-capability.js +16 -0
  142. package/dist/utils/runtime-temp.d.ts +76 -0
  143. package/dist/utils/runtime-temp.js +492 -0
  144. package/dist/utils/secret-policy.d.ts +20 -0
  145. package/dist/utils/secret-policy.js +160 -0
  146. package/dist/utils/session.d.ts +17 -3
  147. package/dist/utils/session.js +354 -110
  148. package/dist/utils/tool-approval-service.d.ts +17 -0
  149. package/dist/utils/tool-approval-service.js +78 -0
  150. package/dist/utils/tool-capability-providers.d.ts +57 -0
  151. package/dist/utils/tool-capability-providers.js +57 -0
  152. package/dist/utils/tools.d.ts +2 -23
  153. package/dist/utils/tools.js +226 -512
  154. package/dist/utils/update-policy.d.ts +18 -0
  155. package/dist/utils/update-policy.js +137 -0
  156. package/dist/utils/v3-agent-client.d.ts +40 -0
  157. package/dist/utils/v3-agent-client.js +165 -0
  158. package/dist/utils/v3-workspace-service.d.ts +28 -0
  159. package/dist/utils/v3-workspace-service.js +279 -0
  160. package/dist/utils/vigflow-client.d.ts +95 -0
  161. package/dist/utils/vigflow-client.js +105 -0
  162. package/dist/utils/workspace-boundary.d.ts +45 -0
  163. package/dist/utils/workspace-boundary.js +377 -0
  164. package/dist/utils/workspace-brain-service.d.ts +2 -0
  165. package/dist/utils/workspace-brain-service.js +11 -1
  166. package/dist/utils/workspace-cache.js +37 -15
  167. package/dist/utils/workspace-stream.js +35 -10
  168. package/install.ps1 +115 -142
  169. package/install.sh +112 -81
  170. package/package.json +43 -9
  171. package/release-policy.json +43 -0
  172. package/scripts/release/LOCAL_MACHINE_USER_VERIFICATION.md +1 -1
  173. package/scripts/release/generate-completions.mjs +24 -0
  174. package/scripts/release/install-release.mjs +10 -0
  175. package/scripts/release/publish-cli-release.mjs +116 -0
  176. package/scripts/release/publish-cli-release.sh +2 -70
  177. package/scripts/release/resolve-release-manifest.mjs +26 -0
  178. package/scripts/release/test-balanced-model-live.sh +45 -0
  179. package/scripts/release/validate-live-service-gates.sh +93 -0
  180. package/scripts/release/validate-no-go-gates.sh +145 -174
  181. package/scripts/release/verify-runtime-consistency.mjs +4 -1
  182. package/dist/commands/index.d.ts +0 -12
  183. package/dist/commands/index.js +0 -194
  184. package/dist/commands/update.d.ts +0 -9
  185. package/dist/commands/update.js +0 -301
  186. package/dist/utils/templateInstantPath.d.ts +0 -18
  187. package/dist/utils/templateInstantPath.js +0 -228
@@ -14,28 +14,50 @@
14
14
  import * as fs from 'fs';
15
15
  import * as os from 'os';
16
16
  import * as path from 'path';
17
+ import { createHash, randomUUID } from 'crypto';
18
+ import { DurableJsonStore } from './durable-json.js';
17
19
  const STATE_DIR = path.join(os.homedir(), '.vigthoria');
18
20
  const STATE_FILE = path.join(STATE_DIR, 'cli-state.json');
19
21
  /** 24h is plenty for an update-check ping. */
20
22
  export const UPDATE_CHECK_TTL_MS = 24 * 60 * 60 * 1000;
21
23
  /** 60s gateway-preflight cache so back-to-back CLI invocations stay fast. */
22
24
  export const GATEWAY_PREFLIGHT_TTL_MS = 60 * 1000;
23
- function readStateUnchecked() {
24
- try {
25
- if (!fs.existsSync(STATE_FILE)) {
26
- return {};
27
- }
28
- const text = fs.readFileSync(STATE_FILE, 'utf8');
29
- if (!text.trim()) {
25
+ function isCliState(value) {
26
+ if (!value || typeof value !== 'object' || Array.isArray(value))
27
+ return false;
28
+ const state = value;
29
+ if (state.updateCheck !== undefined && (!state.updateCheck || typeof state.updateCheck.checkedAt !== 'number' || typeof state.updateCheck.latestVersion !== 'string'))
30
+ return false;
31
+ if (state.lastSeenVersion !== undefined && typeof state.lastSeenVersion !== 'string')
32
+ return false;
33
+ if (state.gatewayPreflight !== undefined && (!state.gatewayPreflight || typeof state.gatewayPreflight !== 'object' || Array.isArray(state.gatewayPreflight)))
34
+ return false;
35
+ return true;
36
+ }
37
+ const stateStore = new DurableJsonStore({
38
+ filePath: STATE_FILE,
39
+ schemaVersion: 2,
40
+ defaultValue: () => ({}),
41
+ validate: isCliState,
42
+ migrate: (value) => {
43
+ if (!value || typeof value !== 'object' || Array.isArray(value))
30
44
  return {};
45
+ const legacy = value;
46
+ // A legacy preflight boolean has no credential, endpoint, or capability
47
+ // audience and is intentionally invalidated during migration.
48
+ const migrated = {};
49
+ if (legacy.updateCheck && typeof legacy.updateCheck === 'object') {
50
+ const entry = legacy.updateCheck;
51
+ if (entry && typeof entry.checkedAt === 'number' && typeof entry.latestVersion === 'string')
52
+ migrated.updateCheck = entry;
31
53
  }
32
- const parsed = JSON.parse(text);
33
- return parsed && typeof parsed === 'object' ? parsed : {};
34
- }
35
- catch {
36
- // Corrupt state file should never crash the CLI — treat as empty.
37
- return {};
38
- }
54
+ if (typeof legacy.lastSeenVersion === 'string')
55
+ migrated.lastSeenVersion = legacy.lastSeenVersion;
56
+ return migrated;
57
+ },
58
+ });
59
+ function readStateUnchecked() {
60
+ return stateStore.read();
39
61
  }
40
62
  export function ensureStateDir() {
41
63
  try {
@@ -74,8 +96,15 @@ export function atomicWriteJson(targetPath, value, mode = 0o600) {
74
96
  fs.mkdirSync(parent, { recursive: true });
75
97
  }
76
98
  catch { /* ignore */ }
77
- const tmpPath = `${targetPath}.${process.pid}.${Date.now()}.tmp`;
78
- fs.writeFileSync(tmpPath, JSON.stringify(value, null, 2), 'utf8');
99
+ const tmpPath = `${targetPath}.${process.pid}.${randomUUID()}.tmp`;
100
+ const descriptor = fs.openSync(tmpPath, 'wx', mode);
101
+ try {
102
+ fs.writeFileSync(descriptor, `${JSON.stringify(value, null, 2)}\n`, 'utf8');
103
+ fs.fsyncSync(descriptor);
104
+ }
105
+ finally {
106
+ fs.closeSync(descriptor);
107
+ }
79
108
  if (process.platform !== 'win32') {
80
109
  try {
81
110
  fs.chmodSync(tmpPath, mode);
@@ -88,7 +117,7 @@ export function loadCliState() {
88
117
  return readStateUnchecked();
89
118
  }
90
119
  export function saveCliState(state) {
91
- atomicWriteJson(STATE_FILE, state);
120
+ stateStore.write(state);
92
121
  }
93
122
  export function getCliStateFile() {
94
123
  return STATE_FILE;
@@ -129,39 +158,73 @@ export function readCachedLatestVersion(maxAgeMs = UPDATE_CHECK_TTL_MS) {
129
158
  return entry.latestVersion;
130
159
  }
131
160
  export function writeCachedLatestVersion(latestVersion, notifiedFor) {
132
- try {
133
- const state = readStateUnchecked();
134
- state.updateCheck = {
161
+ stateStore.update((state) => ({
162
+ ...state,
163
+ updateCheck: {
135
164
  checkedAt: Date.now(),
136
165
  latestVersion,
137
166
  notifiedFor: notifiedFor || state.updateCheck?.notifiedFor,
138
- };
139
- saveCliState(state);
140
- }
141
- catch {
142
- // Caching is a nice-to-have, never block CLI on write failure.
143
- }
167
+ },
168
+ }));
169
+ }
170
+ function normalizeEndpoint(endpoint) {
171
+ const parsed = new URL(String(endpoint));
172
+ parsed.hash = '';
173
+ parsed.search = '';
174
+ parsed.hostname = parsed.hostname.toLowerCase();
175
+ parsed.pathname = parsed.pathname.replace(/\/+$/, '') || '/';
176
+ return parsed.toString().replace(/\/$/, '');
144
177
  }
145
- export function readGatewayPreflightCache(maxAgeMs = GATEWAY_PREFLIGHT_TTL_MS) {
178
+ function fingerprint(value) {
179
+ const serialized = typeof value === 'string' ? value : JSON.stringify(value ?? null);
180
+ return createHash('sha256').update(serialized).digest('hex');
181
+ }
182
+ export function createGatewayPreflightCacheKey(input) {
183
+ const endpoint = normalizeEndpoint(input.endpoint);
184
+ const credentialFingerprint = fingerprint(String(input.credential || ''));
185
+ const capability = String(input.capability || '').trim().toLowerCase();
186
+ if (!capability)
187
+ throw new Error('Gateway preflight capability is required.');
188
+ const configurationFingerprint = fingerprint(input.relevantConfiguration ?? null);
189
+ return {
190
+ id: fingerprint({ endpoint, credentialFingerprint, capability, configurationFingerprint }),
191
+ endpoint,
192
+ credentialFingerprint,
193
+ capability,
194
+ configurationFingerprint,
195
+ };
196
+ }
197
+ export function readGatewayPreflightCache(key, maxAgeMs = GATEWAY_PREFLIGHT_TTL_MS) {
146
198
  const state = readStateUnchecked();
147
- const entry = state.gatewayPreflight;
199
+ const entry = state.gatewayPreflight?.[key.id];
148
200
  if (!entry || typeof entry.checkedAt !== 'number' || typeof entry.valid !== 'boolean') {
149
201
  return null;
150
202
  }
203
+ if (entry.endpoint !== key.endpoint
204
+ || entry.credentialFingerprint !== key.credentialFingerprint
205
+ || entry.capability !== key.capability
206
+ || entry.configurationFingerprint !== key.configurationFingerprint)
207
+ return null;
151
208
  if (Date.now() - entry.checkedAt > maxAgeMs) {
152
209
  return null;
153
210
  }
154
211
  return entry.valid;
155
212
  }
156
- export function writeGatewayPreflightCache(valid) {
157
- try {
158
- const state = readStateUnchecked();
159
- state.gatewayPreflight = { checkedAt: Date.now(), valid };
160
- saveCliState(state);
161
- }
162
- catch {
163
- // Best-effort.
164
- }
213
+ export function writeGatewayPreflightCache(key, valid) {
214
+ stateStore.update((state) => ({
215
+ ...state,
216
+ gatewayPreflight: {
217
+ ...(state.gatewayPreflight || {}),
218
+ [key.id]: {
219
+ checkedAt: Date.now(),
220
+ valid,
221
+ endpoint: key.endpoint,
222
+ credentialFingerprint: key.credentialFingerprint,
223
+ capability: key.capability,
224
+ configurationFingerprint: key.configurationFingerprint,
225
+ },
226
+ },
227
+ }));
165
228
  }
166
229
  /**
167
230
  * Invalidate any cached gateway-preflight result. Must be called on
@@ -170,16 +233,11 @@ export function writeGatewayPreflightCache(valid) {
170
233
  * command run right after a fresh, successful login.
171
234
  */
172
235
  export function clearGatewayPreflightCache() {
173
- try {
174
- const state = readStateUnchecked();
175
- if (state.gatewayPreflight) {
176
- delete state.gatewayPreflight;
177
- saveCliState(state);
178
- }
179
- }
180
- catch {
181
- // Best-effort.
182
- }
236
+ stateStore.update((state) => {
237
+ const next = { ...state };
238
+ delete next.gatewayPreflight;
239
+ return next;
240
+ });
183
241
  }
184
242
  /**
185
243
  * Validate an npm package spec used by `vigthoria update --from <spec>`.
@@ -0,0 +1,104 @@
1
+ export type CodeCompletionPort = (systemPrompt: string, userPrompt: string, model?: string, maxTokens?: number) => Promise<string>;
2
+ export declare class CodeOperationsService {
3
+ private readonly complete;
4
+ constructor(complete: CodeCompletionPort);
5
+ private chatComplete;
6
+ generateCode(prompt: string, language: string, model: string): Promise<string>;
7
+ /**
8
+ * Ensure code has balanced curly braces by appending missing closing braces.
9
+ */
10
+ private ensureBalancedBraces;
11
+ /**
12
+ * Quick JS/TS syntax validation using Node's built-in parser.
13
+ * Returns true if the code parses without errors.
14
+ */
15
+ private validateJsSyntax;
16
+ /**
17
+ * Extract the first complete function/class from code.
18
+ * Used as last-resort when the model keeps over-producing.
19
+ */
20
+ private extractFirstFunction;
21
+ /**
22
+ * Detect if code is excessively over-engineered for a short prompt.
23
+ * E.g. a "multiply function" request producing 20+ lines.
24
+ */
25
+ private codeIsOverEngineered;
26
+ /**
27
+ * Detect if generated code contains DOM/HTML pollution inappropriate
28
+ * for a pure programming language like JavaScript, Python, etc.
29
+ */
30
+ private codeContainsDomPollution;
31
+ /**
32
+ * Strip DOM pollution from generated code, keeping only the pure logic.
33
+ * Used as last-resort fallback when the model repeatedly ignores constraints.
34
+ */
35
+ private stripDomPollution;
36
+ generateProject(prompt: string, projectType: string, model: string): Promise<{
37
+ code: string;
38
+ plan?: any;
39
+ quality?: {
40
+ lineCount: number;
41
+ score: number;
42
+ checks: {
43
+ hasAnimations: boolean;
44
+ hasNeonEffects: boolean;
45
+ hasResponsive: boolean;
46
+ hasFontAwesome: boolean;
47
+ hasGoogleFonts: boolean;
48
+ };
49
+ };
50
+ }>;
51
+ explainCode(code: string, language: string): Promise<string>;
52
+ reviewCode(code: string, language: string): Promise<{
53
+ score: number;
54
+ issues: {
55
+ type: string;
56
+ line: number;
57
+ message: string;
58
+ severity: string;
59
+ }[];
60
+ suggestions: string[];
61
+ }>;
62
+ /**
63
+ * Lightweight client-side heuristic scan: catches common code smells
64
+ * AND logic/arithmetic bugs so review never returns "score 30, no issues".
65
+ */
66
+ heuristicCodeIssues(code: string, _language: string): {
67
+ type: string;
68
+ line: number;
69
+ message: string;
70
+ severity: string;
71
+ }[];
72
+ fixCode(code: string, language: string, fixType: string): Promise<{
73
+ fixed: string;
74
+ changes: {
75
+ line: number;
76
+ before: string;
77
+ after: string;
78
+ reason: string;
79
+ }[];
80
+ }>;
81
+ /**
82
+ * Compute a semantic diff between original and fixed code using
83
+ * Longest Common Subsequence (LCS) to avoid the line-shift inflation
84
+ * bug where inserting one line flags all subsequent lines as changed.
85
+ */
86
+ private computeSemanticDiff;
87
+ /**
88
+ * Lightweight client-side syntax error detection.
89
+ * Returns a human-readable description of obvious errors, or empty string.
90
+ */
91
+ detectSyntaxErrors(code: string, language: string): string;
92
+ /**
93
+ * Strip comment lines that the model added during a fix but were not
94
+ * present in the original code. Used for syntax-only fixes where the
95
+ * model tends to annotate its changes with "// Fixed ..." comments.
96
+ */
97
+ stripInjectedComments(original: string, fixed: string, language: string): string;
98
+ /**
99
+ * Ensure the fixed code hasn't lost closing delimiters relative to the
100
+ * original. Counts {, }, (, ), [, ] outside strings/comments and if
101
+ * the fix has fewer closers than the original, appends the missing ones.
102
+ */
103
+ repairBracketBalance(original: string, fixed: string): string;
104
+ }