@pugi/cli 0.1.0-alpha.18 → 0.1.0-alpha.19
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.
- package/README.md +33 -0
- package/dist/commands/deploy.js +439 -0
- package/dist/core/edits/dispatch.js +185 -0
- package/dist/core/edits/index.js +15 -0
- package/dist/core/edits/layer-a-apply.js +217 -0
- package/dist/core/edits/layer-b-apply.js +211 -0
- package/dist/core/edits/layer-c-apply.js +160 -0
- package/dist/core/edits/layer-d-ast.js +29 -0
- package/dist/core/edits/marker-parser.js +401 -0
- package/dist/core/edits/security-gate.js +223 -0
- package/dist/core/repl/cancellation.js +98 -0
- package/dist/core/repl/dispatch-fsm.js +204 -0
- package/dist/core/repl/privacy-banner.js +4 -4
- package/dist/core/repl/session.js +90 -0
- package/dist/core/repl/slash-commands.js +12 -3
- package/dist/runtime/cli.js +193 -1
- package/dist/runtime/commands/config.js +136 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -94,12 +94,45 @@ pugi review --triple --remote
|
|
|
94
94
|
pugi handoff --web # hand the session off to the cabinet
|
|
95
95
|
pugi sessions # list sessions from .pugi/index.json
|
|
96
96
|
pugi sessions --rebuild # rebuild the index from events.jsonl
|
|
97
|
+
pugi deploy --target vercel my-vercel-project --project proj_42
|
|
98
|
+
# trigger a Vercel deploy from the bound Git source
|
|
99
|
+
pugi deploy --status dep_42 # vendor-agnostic status snapshot
|
|
100
|
+
pugi deploy --logs dep_42 --tail
|
|
101
|
+
# build-log tail; --tail polls until terminal
|
|
97
102
|
pugi doctor --json # environment diagnostic
|
|
98
103
|
pugi version # CLI version
|
|
99
104
|
```
|
|
100
105
|
|
|
101
106
|
Run `pugi --help` for the full list.
|
|
102
107
|
|
|
108
|
+
### Deploy
|
|
109
|
+
|
|
110
|
+
`pugi deploy` triggers a deployment for the project bound to your Vercel or
|
|
111
|
+
Render integration. Source is resolved from the existing `ProjectGitBinding`
|
|
112
|
+
row on the admin-api side — the CLI never reads local files.
|
|
113
|
+
|
|
114
|
+
```bash
|
|
115
|
+
# Vercel — production (default)
|
|
116
|
+
pugi deploy --target vercel my-vercel-project --project proj_42
|
|
117
|
+
|
|
118
|
+
# Vercel — preview from a feature branch
|
|
119
|
+
pugi deploy --target vercel my-vercel-project --project proj_42 \
|
|
120
|
+
--target-env preview --ref feat/landing-tweaks
|
|
121
|
+
|
|
122
|
+
# Render (Sprint 2 — endpoint returns 501 today)
|
|
123
|
+
pugi deploy --target render my-render-svc --project proj_42
|
|
124
|
+
|
|
125
|
+
# Query existing deploys
|
|
126
|
+
pugi deploy --status dep_42
|
|
127
|
+
pugi deploy --logs dep_42 --tail
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
Exit codes:
|
|
131
|
+
|
|
132
|
+
- `0` success (queued, ready, building)
|
|
133
|
+
- `1` failed (status=error, refused, not authenticated)
|
|
134
|
+
- `2` transient (rate-limited, runtime down, retry-safe)
|
|
135
|
+
|
|
103
136
|
## Privacy
|
|
104
137
|
|
|
105
138
|
Pugi defaults to `local-only` — no upload happens without an explicit flag.
|
|
@@ -0,0 +1,439 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `pugi deploy` command surface — Wave 3 P2 (Task #34, 2026-05-25).
|
|
3
|
+
*
|
|
4
|
+
* Subcommands:
|
|
5
|
+
* pugi deploy --target vercel <vercelProject> [--project <id>] [--ref <ref>] [--target-env production|preview] [--integration <id>]
|
|
6
|
+
* pugi deploy --target render <renderService> [--project <id>] [--ref <ref>]
|
|
7
|
+
* pugi deploy --status <deployment-id>
|
|
8
|
+
* pugi deploy --logs <deployment-id> [--tail]
|
|
9
|
+
*
|
|
10
|
+
* Exit codes (per task spec):
|
|
11
|
+
* 0 success (trigger queued, status terminal=ready, logs printed)
|
|
12
|
+
* 1 deployment failed (status=error or trigger refused)
|
|
13
|
+
* 2 transient (rate-limited, runtime down, retry-safe)
|
|
14
|
+
*
|
|
15
|
+
* Project resolution:
|
|
16
|
+
* `--project <id>` is required for trigger commands because the CLI's
|
|
17
|
+
* credential store is tenant-scoped but not project-scoped. A future
|
|
18
|
+
* sprint (Wave 4) auto-detects the project from `.pugi/settings.json`
|
|
19
|
+
* bound to the workspace; until then the operator passes it explicitly.
|
|
20
|
+
*
|
|
21
|
+
* Local-first invariant (ADR-0037):
|
|
22
|
+
* `pugi deploy` does NOT read repository files. The Vercel deploy
|
|
23
|
+
* resolves source from the existing ProjectGitBinding row on the
|
|
24
|
+
* admin-api side — the CLI is only a request initiator + status poller.
|
|
25
|
+
*/
|
|
26
|
+
import { fetchDeployStatus, fetchDeployLogs, submitDeployTrigger, } from '@pugi/sdk';
|
|
27
|
+
/**
|
|
28
|
+
* Parse `pugi deploy ...` flags + positionals into a structured shape.
|
|
29
|
+
* Exported so tests can exercise the parser in isolation.
|
|
30
|
+
*/
|
|
31
|
+
export function parseDeployArgs(args) {
|
|
32
|
+
const flags = {};
|
|
33
|
+
const positional = [];
|
|
34
|
+
for (let i = 0; i < args.length; i++) {
|
|
35
|
+
const arg = args[i] ?? '';
|
|
36
|
+
if (arg === '--json') {
|
|
37
|
+
flags.json = true;
|
|
38
|
+
}
|
|
39
|
+
else if (arg === '--target') {
|
|
40
|
+
const next = args[i + 1];
|
|
41
|
+
if (!next)
|
|
42
|
+
return { flags, positional, error: '--target requires a value (vercel|render)' };
|
|
43
|
+
if (next !== 'vercel' && next !== 'render') {
|
|
44
|
+
return { flags, positional, error: `--target must be vercel or render, got "${next}"` };
|
|
45
|
+
}
|
|
46
|
+
flags.target = next;
|
|
47
|
+
i += 1;
|
|
48
|
+
}
|
|
49
|
+
else if (arg.startsWith('--target=')) {
|
|
50
|
+
const value = arg.slice('--target='.length);
|
|
51
|
+
if (value !== 'vercel' && value !== 'render') {
|
|
52
|
+
return { flags, positional, error: `--target must be vercel or render, got "${value}"` };
|
|
53
|
+
}
|
|
54
|
+
flags.target = value;
|
|
55
|
+
}
|
|
56
|
+
else if (arg === '--project') {
|
|
57
|
+
const next = args[i + 1];
|
|
58
|
+
if (!next)
|
|
59
|
+
return { flags, positional, error: '--project requires a value' };
|
|
60
|
+
flags.project = next;
|
|
61
|
+
i += 1;
|
|
62
|
+
}
|
|
63
|
+
else if (arg.startsWith('--project=')) {
|
|
64
|
+
flags.project = arg.slice('--project='.length);
|
|
65
|
+
}
|
|
66
|
+
else if (arg === '--ref') {
|
|
67
|
+
const next = args[i + 1];
|
|
68
|
+
if (!next)
|
|
69
|
+
return { flags, positional, error: '--ref requires a value' };
|
|
70
|
+
flags.ref = next;
|
|
71
|
+
i += 1;
|
|
72
|
+
}
|
|
73
|
+
else if (arg.startsWith('--ref=')) {
|
|
74
|
+
flags.ref = arg.slice('--ref='.length);
|
|
75
|
+
}
|
|
76
|
+
else if (arg === '--target-env') {
|
|
77
|
+
const next = args[i + 1];
|
|
78
|
+
if (!next)
|
|
79
|
+
return { flags, positional, error: '--target-env requires a value' };
|
|
80
|
+
if (next !== 'production' && next !== 'preview') {
|
|
81
|
+
return {
|
|
82
|
+
flags,
|
|
83
|
+
positional,
|
|
84
|
+
error: `--target-env must be production or preview, got "${next}"`,
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
flags.targetEnv = next;
|
|
88
|
+
i += 1;
|
|
89
|
+
}
|
|
90
|
+
else if (arg.startsWith('--target-env=')) {
|
|
91
|
+
const value = arg.slice('--target-env='.length);
|
|
92
|
+
if (value !== 'production' && value !== 'preview') {
|
|
93
|
+
return {
|
|
94
|
+
flags,
|
|
95
|
+
positional,
|
|
96
|
+
error: `--target-env must be production or preview, got "${value}"`,
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
flags.targetEnv = value;
|
|
100
|
+
}
|
|
101
|
+
else if (arg === '--integration') {
|
|
102
|
+
const next = args[i + 1];
|
|
103
|
+
if (!next)
|
|
104
|
+
return { flags, positional, error: '--integration requires a value' };
|
|
105
|
+
flags.integration = next;
|
|
106
|
+
i += 1;
|
|
107
|
+
}
|
|
108
|
+
else if (arg.startsWith('--integration=')) {
|
|
109
|
+
flags.integration = arg.slice('--integration='.length);
|
|
110
|
+
}
|
|
111
|
+
else if (arg === '--status') {
|
|
112
|
+
const next = args[i + 1];
|
|
113
|
+
if (!next)
|
|
114
|
+
return { flags, positional, error: '--status requires a deployment id' };
|
|
115
|
+
flags.status = next;
|
|
116
|
+
i += 1;
|
|
117
|
+
}
|
|
118
|
+
else if (arg.startsWith('--status=')) {
|
|
119
|
+
flags.status = arg.slice('--status='.length);
|
|
120
|
+
}
|
|
121
|
+
else if (arg === '--logs') {
|
|
122
|
+
const next = args[i + 1];
|
|
123
|
+
if (!next)
|
|
124
|
+
return { flags, positional, error: '--logs requires a deployment id' };
|
|
125
|
+
flags.logs = next;
|
|
126
|
+
i += 1;
|
|
127
|
+
}
|
|
128
|
+
else if (arg.startsWith('--logs=')) {
|
|
129
|
+
flags.logs = arg.slice('--logs='.length);
|
|
130
|
+
}
|
|
131
|
+
else if (arg === '--tail') {
|
|
132
|
+
flags.tail = true;
|
|
133
|
+
}
|
|
134
|
+
else if (arg.startsWith('--')) {
|
|
135
|
+
return { flags, positional, error: `unknown flag: ${arg}` };
|
|
136
|
+
}
|
|
137
|
+
else {
|
|
138
|
+
positional.push(arg);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
return { flags, positional };
|
|
142
|
+
}
|
|
143
|
+
export function usage() {
|
|
144
|
+
return [
|
|
145
|
+
'Usage:',
|
|
146
|
+
' pugi deploy --target vercel <vercelProject> --project <id> [--target-env production|preview] [--ref <git-ref>] [--integration <id>]',
|
|
147
|
+
' pugi deploy --target render <renderService> --project <id> [--ref <git-ref>]',
|
|
148
|
+
' pugi deploy --status <deployment-id>',
|
|
149
|
+
' pugi deploy --logs <deployment-id> [--tail]',
|
|
150
|
+
'',
|
|
151
|
+
'Flags:',
|
|
152
|
+
' --target vercel|render Provider to deploy to.',
|
|
153
|
+
' --project <id> Pugi project id (required for trigger).',
|
|
154
|
+
' --ref <git-ref> Optional Git ref. Defaults to the binding default branch.',
|
|
155
|
+
' --target-env production|preview',
|
|
156
|
+
' Vercel deploy environment. Defaults to production.',
|
|
157
|
+
' --integration <id> Disambiguate when multiple integrations are active.',
|
|
158
|
+
' --status <id> Show the current status for a deployment.',
|
|
159
|
+
' --logs <id> [--tail] Fetch log tail. With --tail, polls until terminal.',
|
|
160
|
+
' --json Emit machine-readable JSON envelopes.',
|
|
161
|
+
'',
|
|
162
|
+
'Exit codes:',
|
|
163
|
+
' 0 success',
|
|
164
|
+
' 1 deployment failed / refused',
|
|
165
|
+
' 2 transient (rate-limited, runtime down, retry-safe)',
|
|
166
|
+
].join('\n');
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Main entry point. Returns the exit code; the CLI shim sets
|
|
170
|
+
* `process.exitCode = result` so tests can drive this without a child
|
|
171
|
+
* process and the REPL can poll the value.
|
|
172
|
+
*/
|
|
173
|
+
export async function runDeployCommand(args, io, deps) {
|
|
174
|
+
const parsed = parseDeployArgs(args);
|
|
175
|
+
if (parsed.error) {
|
|
176
|
+
if (parsed.flags.json) {
|
|
177
|
+
io.write(`${JSON.stringify({ command: 'deploy', ok: false, error: parsed.error }, null, 2)}\n`);
|
|
178
|
+
}
|
|
179
|
+
else {
|
|
180
|
+
io.writeError(parsed.error);
|
|
181
|
+
io.writeError(usage());
|
|
182
|
+
}
|
|
183
|
+
return 2;
|
|
184
|
+
}
|
|
185
|
+
const { flags, positional } = parsed;
|
|
186
|
+
// Branch 1: --status <id>
|
|
187
|
+
if (flags.status) {
|
|
188
|
+
return runStatus(flags.status, flags, io, deps);
|
|
189
|
+
}
|
|
190
|
+
// Branch 2: --logs <id>
|
|
191
|
+
if (flags.logs) {
|
|
192
|
+
return runLogs(flags.logs, flags, io, deps);
|
|
193
|
+
}
|
|
194
|
+
// Branch 3: trigger via --target <vercel|render>
|
|
195
|
+
if (!flags.target) {
|
|
196
|
+
if (flags.json) {
|
|
197
|
+
io.write(`${JSON.stringify({
|
|
198
|
+
command: 'deploy',
|
|
199
|
+
ok: false,
|
|
200
|
+
error: 'No --target specified. Use --target vercel|render, or --status / --logs to query existing deploys.',
|
|
201
|
+
}, null, 2)}\n`);
|
|
202
|
+
}
|
|
203
|
+
else {
|
|
204
|
+
io.writeError('No --target specified. Use --target vercel|render, or --status / --logs to query existing deploys.');
|
|
205
|
+
io.writeError(usage());
|
|
206
|
+
}
|
|
207
|
+
return 2;
|
|
208
|
+
}
|
|
209
|
+
const projectKey = positional[0];
|
|
210
|
+
if (!projectKey) {
|
|
211
|
+
const msg = flags.target === 'vercel'
|
|
212
|
+
? 'pugi deploy --target vercel requires a Vercel project name as the positional argument'
|
|
213
|
+
: 'pugi deploy --target render requires a Render service name as the positional argument';
|
|
214
|
+
if (flags.json) {
|
|
215
|
+
io.write(`${JSON.stringify({ command: 'deploy', ok: false, error: msg }, null, 2)}\n`);
|
|
216
|
+
}
|
|
217
|
+
else {
|
|
218
|
+
io.writeError(msg);
|
|
219
|
+
io.writeError(usage());
|
|
220
|
+
}
|
|
221
|
+
return 2;
|
|
222
|
+
}
|
|
223
|
+
if (!flags.project) {
|
|
224
|
+
const msg = 'pugi deploy trigger requires --project <pugi-project-id>';
|
|
225
|
+
if (flags.json) {
|
|
226
|
+
io.write(`${JSON.stringify({ command: 'deploy', ok: false, error: msg }, null, 2)}\n`);
|
|
227
|
+
}
|
|
228
|
+
else {
|
|
229
|
+
io.writeError(msg);
|
|
230
|
+
io.writeError(usage());
|
|
231
|
+
}
|
|
232
|
+
return 2;
|
|
233
|
+
}
|
|
234
|
+
const config = deps.resolveConfig();
|
|
235
|
+
if (!config) {
|
|
236
|
+
const msg = 'Not authenticated. Run `pugi login` first.';
|
|
237
|
+
if (flags.json) {
|
|
238
|
+
io.write(`${JSON.stringify({ command: 'deploy', ok: false, error: msg }, null, 2)}\n`);
|
|
239
|
+
}
|
|
240
|
+
else {
|
|
241
|
+
io.writeError(msg);
|
|
242
|
+
}
|
|
243
|
+
return 1;
|
|
244
|
+
}
|
|
245
|
+
let result;
|
|
246
|
+
if (flags.target === 'vercel') {
|
|
247
|
+
result = await submitDeployTrigger(config, 'vercel', {
|
|
248
|
+
schema: 1,
|
|
249
|
+
projectId: flags.project,
|
|
250
|
+
vercelProject: projectKey,
|
|
251
|
+
...(flags.integration ? { integrationId: flags.integration } : {}),
|
|
252
|
+
...(flags.targetEnv ? { target: flags.targetEnv } : {}),
|
|
253
|
+
...(flags.ref ? { ref: flags.ref } : {}),
|
|
254
|
+
});
|
|
255
|
+
}
|
|
256
|
+
else {
|
|
257
|
+
result = await submitDeployTrigger(config, 'render', {
|
|
258
|
+
schema: 1,
|
|
259
|
+
projectId: flags.project,
|
|
260
|
+
renderService: projectKey,
|
|
261
|
+
...(flags.ref ? { ref: flags.ref } : {}),
|
|
262
|
+
});
|
|
263
|
+
}
|
|
264
|
+
return emitTriggerResult(result, flags, io);
|
|
265
|
+
}
|
|
266
|
+
function emitTriggerResult(result, flags, io) {
|
|
267
|
+
if (result.status === 'ok') {
|
|
268
|
+
if (flags.json) {
|
|
269
|
+
io.write(`${JSON.stringify({ command: 'deploy.trigger', ok: true, deployment: result.response }, null, 2)}\n`);
|
|
270
|
+
}
|
|
271
|
+
else {
|
|
272
|
+
io.write(renderStatusTable(result.response, 'queued'));
|
|
273
|
+
}
|
|
274
|
+
return 0;
|
|
275
|
+
}
|
|
276
|
+
return emitDeployFailure('deploy.trigger', result, flags, io);
|
|
277
|
+
}
|
|
278
|
+
async function runStatus(deploymentId, flags, io, deps) {
|
|
279
|
+
const config = deps.resolveConfig();
|
|
280
|
+
if (!config) {
|
|
281
|
+
const msg = 'Not authenticated. Run `pugi login` first.';
|
|
282
|
+
if (flags.json) {
|
|
283
|
+
io.write(`${JSON.stringify({ command: 'deploy.status', ok: false, error: msg }, null, 2)}\n`);
|
|
284
|
+
}
|
|
285
|
+
else {
|
|
286
|
+
io.writeError(msg);
|
|
287
|
+
}
|
|
288
|
+
return 1;
|
|
289
|
+
}
|
|
290
|
+
const result = await fetchDeployStatus(config, deploymentId);
|
|
291
|
+
if (result.status === 'ok') {
|
|
292
|
+
if (flags.json) {
|
|
293
|
+
io.write(`${JSON.stringify({ command: 'deploy.status', ok: true, deployment: result.response }, null, 2)}\n`);
|
|
294
|
+
}
|
|
295
|
+
else {
|
|
296
|
+
io.write(renderStatusTable(result.response, 'current'));
|
|
297
|
+
}
|
|
298
|
+
return statusToExitCode(result.response.status);
|
|
299
|
+
}
|
|
300
|
+
return emitDeployFailure('deploy.status', result, flags, io);
|
|
301
|
+
}
|
|
302
|
+
async function runLogs(deploymentId, flags, io, deps) {
|
|
303
|
+
const config = deps.resolveConfig();
|
|
304
|
+
if (!config) {
|
|
305
|
+
const msg = 'Not authenticated. Run `pugi login` first.';
|
|
306
|
+
if (flags.json) {
|
|
307
|
+
io.write(`${JSON.stringify({ command: 'deploy.logs', ok: false, error: msg }, null, 2)}\n`);
|
|
308
|
+
}
|
|
309
|
+
else {
|
|
310
|
+
io.writeError(msg);
|
|
311
|
+
}
|
|
312
|
+
return 1;
|
|
313
|
+
}
|
|
314
|
+
const sleep = deps.sleep ?? ((ms) => new Promise((resolve) => setTimeout(resolve, ms)));
|
|
315
|
+
let lastTerminal = false;
|
|
316
|
+
let lastStatus = 'queued';
|
|
317
|
+
let lastLogs = '';
|
|
318
|
+
// Single-shot vs --tail. The tail loop is bounded by the 10-minute hard
|
|
319
|
+
// ceiling so a runaway runtime doesn't keep a CI job pinned forever.
|
|
320
|
+
const startedAt = Date.now();
|
|
321
|
+
const maxMs = 10 * 60 * 1000;
|
|
322
|
+
const pollIntervalMs = 3_000;
|
|
323
|
+
while (true) {
|
|
324
|
+
const result = await fetchDeployLogs(config, deploymentId);
|
|
325
|
+
if (result.status !== 'ok') {
|
|
326
|
+
return emitDeployFailure('deploy.logs', result, flags, io);
|
|
327
|
+
}
|
|
328
|
+
const { response } = result;
|
|
329
|
+
lastTerminal = response.terminal;
|
|
330
|
+
lastStatus = response.status;
|
|
331
|
+
lastLogs = response.logs;
|
|
332
|
+
if (flags.json) {
|
|
333
|
+
io.write(`${JSON.stringify({ command: 'deploy.logs', ok: true, snapshot: response }, null, 2)}\n`);
|
|
334
|
+
}
|
|
335
|
+
else {
|
|
336
|
+
io.write(response.logs.endsWith('\n') ? response.logs : `${response.logs}\n`);
|
|
337
|
+
}
|
|
338
|
+
if (!flags.tail)
|
|
339
|
+
break;
|
|
340
|
+
if (response.terminal)
|
|
341
|
+
break;
|
|
342
|
+
if (Date.now() - startedAt > maxMs) {
|
|
343
|
+
io.writeError(`--tail timed out after ${Math.floor(maxMs / 60_000)} minutes; deployment still ${response.status}. Re-run with --status to confirm.`);
|
|
344
|
+
return 2;
|
|
345
|
+
}
|
|
346
|
+
await sleep(pollIntervalMs);
|
|
347
|
+
}
|
|
348
|
+
// Suppress unused-warning safe-guards in single-shot path.
|
|
349
|
+
void lastTerminal;
|
|
350
|
+
void lastLogs;
|
|
351
|
+
return statusToExitCode(lastStatus);
|
|
352
|
+
}
|
|
353
|
+
function emitDeployFailure(command, result, flags, io) {
|
|
354
|
+
if (result.status === 'ok')
|
|
355
|
+
return 0;
|
|
356
|
+
if (flags.json) {
|
|
357
|
+
io.write(`${JSON.stringify({ command, ok: false, ...result }, null, 2)}\n`);
|
|
358
|
+
}
|
|
359
|
+
switch (result.status) {
|
|
360
|
+
case 'unauthenticated':
|
|
361
|
+
if (!flags.json) {
|
|
362
|
+
io.writeError('Runtime rejected credentials. Re-run `pugi login` or refresh your API key.');
|
|
363
|
+
}
|
|
364
|
+
return 1;
|
|
365
|
+
case 'endpoint_missing':
|
|
366
|
+
if (!flags.json) {
|
|
367
|
+
io.writeError('Deploy endpoint not deployed on this runtime. Update your runtime or set PUGI_API_URL to a runtime that supports /api/pugi/deploy/*.');
|
|
368
|
+
}
|
|
369
|
+
return 2;
|
|
370
|
+
case 'not_configured':
|
|
371
|
+
if (!flags.json) {
|
|
372
|
+
io.writeError('Provider not configured on this runtime. Try `pugi deploy --target vercel` until Render ships in Sprint 2.');
|
|
373
|
+
}
|
|
374
|
+
return 2;
|
|
375
|
+
case 'not_found':
|
|
376
|
+
if (!flags.json) {
|
|
377
|
+
io.writeError('Deployment not found for this tenant.');
|
|
378
|
+
}
|
|
379
|
+
return 1;
|
|
380
|
+
case 'rate_limited':
|
|
381
|
+
if (!flags.json) {
|
|
382
|
+
const retrySec = Math.max(1, Math.ceil(result.retryAfterMs / 1000));
|
|
383
|
+
io.writeError(`Runtime rate-limited. Retry in ${retrySec}s. (Vercel Hobby cap is the common cause.)`);
|
|
384
|
+
}
|
|
385
|
+
return 2;
|
|
386
|
+
case 'failed':
|
|
387
|
+
if (!flags.json) {
|
|
388
|
+
io.writeError(`Deploy call failed: ${result.message}`);
|
|
389
|
+
}
|
|
390
|
+
// Network / 5xx → transient. Schema validation / 4xx → permanent.
|
|
391
|
+
// We cannot perfectly disambiguate here, so map HTTP < 500 to 1
|
|
392
|
+
// (caller error, fix and retry) and the rest to 2 (transient).
|
|
393
|
+
return result.code >= 500 || result.code === 0 ? 2 : 1;
|
|
394
|
+
default:
|
|
395
|
+
// Exhaustiveness: TS catches new variants at compile time. Runtime
|
|
396
|
+
// fall-through keeps the CLI from hanging if a future SDK version
|
|
397
|
+
// adds a status the CLI doesn't yet know about.
|
|
398
|
+
if (!flags.json) {
|
|
399
|
+
io.writeError(`Unknown deploy result.`);
|
|
400
|
+
}
|
|
401
|
+
return 2;
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
function statusToExitCode(status) {
|
|
405
|
+
switch (status) {
|
|
406
|
+
case 'ready':
|
|
407
|
+
case 'queued':
|
|
408
|
+
case 'building':
|
|
409
|
+
return 0;
|
|
410
|
+
case 'error':
|
|
411
|
+
return 1;
|
|
412
|
+
case 'canceled':
|
|
413
|
+
return 1;
|
|
414
|
+
default:
|
|
415
|
+
return 0;
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
function renderStatusTable(response, context) {
|
|
419
|
+
const lines = [];
|
|
420
|
+
lines.push(context === 'queued' ? 'Deployment queued.' : 'Deployment status:');
|
|
421
|
+
lines.push(` id: ${response.id}`);
|
|
422
|
+
lines.push(` provider: ${response.provider}`);
|
|
423
|
+
lines.push(` project: ${response.projectId}`);
|
|
424
|
+
lines.push(` status: ${response.status}`);
|
|
425
|
+
if (response.url)
|
|
426
|
+
lines.push(` url: ${response.url}`);
|
|
427
|
+
if (response.providerDeploymentId)
|
|
428
|
+
lines.push(` providerDeploymentId: ${response.providerDeploymentId}`);
|
|
429
|
+
lines.push(` createdAt: ${response.createdAt}`);
|
|
430
|
+
lines.push(` updatedAt: ${response.updatedAt}`);
|
|
431
|
+
if (response.error) {
|
|
432
|
+
lines.push('');
|
|
433
|
+
lines.push('--- build error tail ---');
|
|
434
|
+
lines.push(response.error);
|
|
435
|
+
}
|
|
436
|
+
lines.push('');
|
|
437
|
+
return lines.join('\n');
|
|
438
|
+
}
|
|
439
|
+
//# sourceMappingURL=deploy.js.map
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Diff dispatch — α6.6 escalation Phase 1.
|
|
3
|
+
*
|
|
4
|
+
* Reads a raw model response containing one or more SEARCH/REPLACE
|
|
5
|
+
* envelopes, normalises them through `marker-parser`, and routes each
|
|
6
|
+
* parsed edit to the correct applicator:
|
|
7
|
+
*
|
|
8
|
+
* - `layer-a` → applyLayerA
|
|
9
|
+
* - `layer-b` → applyLayerB
|
|
10
|
+
* - `layer-c` → applyLayerC
|
|
11
|
+
* - `layer-d` → throws LayerDDeferredError, surfaced as a clean
|
|
12
|
+
* dispatch failure (Layer D ships in α6.6b)
|
|
13
|
+
*
|
|
14
|
+
* Per-edit results are aggregated into `DispatchResult[]` so callers
|
|
15
|
+
* can render the full apply transcript even when some edits failed.
|
|
16
|
+
* Order is preserved across the response.
|
|
17
|
+
*
|
|
18
|
+
* Crash recovery hook: when a SessionStore-style appendEvent callback
|
|
19
|
+
* is supplied, the dispatcher records the INTENT (parsed edit) BEFORE
|
|
20
|
+
* calling the applicator. The matching `applied` event lands AFTER
|
|
21
|
+
* the writeFile. A crash between the two leaves a recoverable trail —
|
|
22
|
+
* the operator (or `pugi resume`) sees the intent and can re-attempt.
|
|
23
|
+
*
|
|
24
|
+
* The dispatcher is intentionally side-effect-light: no logging, no
|
|
25
|
+
* stdout writes, no exit-code mutation. The CLI integration layer in
|
|
26
|
+
* `cli.ts` owns operator-facing rendering; the dispatcher returns
|
|
27
|
+
* structured data and lets the caller decide UX.
|
|
28
|
+
*/
|
|
29
|
+
import { LayerDDeferredError, applyLayerD } from './layer-d-ast.js';
|
|
30
|
+
import { applyLayerA } from './layer-a-apply.js';
|
|
31
|
+
import { applyLayerB } from './layer-b-apply.js';
|
|
32
|
+
import { applyLayerC } from './layer-c-apply.js';
|
|
33
|
+
import { MarkerParseError, parseMarkers, } from './marker-parser.js';
|
|
34
|
+
/**
|
|
35
|
+
* Parse `raw` into edits and apply each in order. Aggregate results,
|
|
36
|
+
* preserving order. Never throws — parse failures surface as a single
|
|
37
|
+
* synthetic DispatchResult with `ok: false, layer: 'layer-a', reason:
|
|
38
|
+
* 'marker_parse_error'`. Applicator failures are recorded per-edit.
|
|
39
|
+
*/
|
|
40
|
+
export async function dispatchEdit(raw, opts) {
|
|
41
|
+
const family = resolveFamily(opts.modelTag);
|
|
42
|
+
let parsed;
|
|
43
|
+
try {
|
|
44
|
+
parsed = parseMarkers(raw, family);
|
|
45
|
+
}
|
|
46
|
+
catch (error) {
|
|
47
|
+
if (error instanceof MarkerParseError) {
|
|
48
|
+
const result = {
|
|
49
|
+
layer: 'layer-a',
|
|
50
|
+
file: '',
|
|
51
|
+
ok: false,
|
|
52
|
+
bytesWritten: 0,
|
|
53
|
+
reason: 'marker_parse_error',
|
|
54
|
+
detail: `${error.message}${error.atLine ? ` (line ${error.atLine})` : ''} — modelHint=${error.modelHint}`,
|
|
55
|
+
};
|
|
56
|
+
opts.onResult?.(result);
|
|
57
|
+
return [result];
|
|
58
|
+
}
|
|
59
|
+
throw error;
|
|
60
|
+
}
|
|
61
|
+
if (parsed.length === 0) {
|
|
62
|
+
// Empty parse but no error == no markers in the payload. This is
|
|
63
|
+
// not necessarily a failure (the model may have answered with
|
|
64
|
+
// prose only); surface a single neutral result so the caller can
|
|
65
|
+
// render "no edits proposed".
|
|
66
|
+
return [];
|
|
67
|
+
}
|
|
68
|
+
const out = [];
|
|
69
|
+
for (const edit of parsed) {
|
|
70
|
+
const intent = makeIntent(edit);
|
|
71
|
+
opts.onIntent?.(intent);
|
|
72
|
+
const result = await applyOne(edit, opts);
|
|
73
|
+
out.push(result);
|
|
74
|
+
opts.onResult?.(result);
|
|
75
|
+
}
|
|
76
|
+
return out;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Public helper exposed for the marker parser tests + CLI surface that
|
|
80
|
+
* may want to know the resolved family without re-running the auto
|
|
81
|
+
* detector.
|
|
82
|
+
*/
|
|
83
|
+
export function resolveFamily(modelTag) {
|
|
84
|
+
if (!modelTag)
|
|
85
|
+
return 'auto';
|
|
86
|
+
const tag = modelTag.toLowerCase();
|
|
87
|
+
if (tag.startsWith('claude') || tag.startsWith('anthropic/'))
|
|
88
|
+
return 'anthropic';
|
|
89
|
+
if (tag.startsWith('gemini') || tag.startsWith('xai/') || tag.startsWith('grok'))
|
|
90
|
+
return 'gemini';
|
|
91
|
+
if (tag.startsWith('gpt') || tag.startsWith('o1') || tag.startsWith('openai/'))
|
|
92
|
+
return 'openai';
|
|
93
|
+
return 'auto';
|
|
94
|
+
}
|
|
95
|
+
function makeIntent(edit) {
|
|
96
|
+
switch (edit.kind) {
|
|
97
|
+
case 'layer-a':
|
|
98
|
+
return {
|
|
99
|
+
layer: 'layer-a',
|
|
100
|
+
file: edit.edit.file,
|
|
101
|
+
intentSummary: `Layer A: ${edit.edit.file} (oldString ${edit.edit.oldString.length} bytes)`,
|
|
102
|
+
};
|
|
103
|
+
case 'layer-b':
|
|
104
|
+
return {
|
|
105
|
+
layer: 'layer-b',
|
|
106
|
+
file: edit.edit.file,
|
|
107
|
+
intentSummary: `Layer B: ${edit.edit.file} (${edit.edit.edits.length} sub-edits)`,
|
|
108
|
+
};
|
|
109
|
+
case 'layer-c':
|
|
110
|
+
return {
|
|
111
|
+
layer: 'layer-c',
|
|
112
|
+
file: edit.edit.file,
|
|
113
|
+
intentSummary: `Layer C: ${edit.edit.file} (rewrite, ${edit.edit.newContents.length} bytes, baseSha ${edit.edit.baseSha256.slice(0, 12)})`,
|
|
114
|
+
};
|
|
115
|
+
case 'layer-d':
|
|
116
|
+
return {
|
|
117
|
+
layer: 'layer-d',
|
|
118
|
+
file: edit.edit.file,
|
|
119
|
+
intentSummary: `Layer D: ${edit.edit.file} op=${edit.edit.operation}`,
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
async function applyOne(edit, opts) {
|
|
124
|
+
const applyOpts = { cwd: opts.cwd, dryRun: opts.dryRun };
|
|
125
|
+
switch (edit.kind) {
|
|
126
|
+
case 'layer-a': {
|
|
127
|
+
const r = await applyLayerA(edit.edit, applyOpts);
|
|
128
|
+
return toResult('layer-a', edit.edit.file, r);
|
|
129
|
+
}
|
|
130
|
+
case 'layer-b': {
|
|
131
|
+
const r = await applyLayerB(edit.edit, applyOpts);
|
|
132
|
+
return {
|
|
133
|
+
...toResult('layer-b', edit.edit.file, r),
|
|
134
|
+
appliedCount: r.appliedCount,
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
case 'layer-c': {
|
|
138
|
+
const r = await applyLayerC(edit.edit, applyOpts);
|
|
139
|
+
return {
|
|
140
|
+
...toResult('layer-c', edit.edit.file, r),
|
|
141
|
+
expectedSha256: r.expectedSha256,
|
|
142
|
+
actualSha256: r.actualSha256,
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
case 'layer-d': {
|
|
146
|
+
try {
|
|
147
|
+
const r = await applyLayerD(edit.edit, applyOpts);
|
|
148
|
+
return toResult('layer-d', edit.edit.file, r);
|
|
149
|
+
}
|
|
150
|
+
catch (error) {
|
|
151
|
+
if (error instanceof LayerDDeferredError) {
|
|
152
|
+
return {
|
|
153
|
+
layer: 'layer-d',
|
|
154
|
+
file: edit.edit.file,
|
|
155
|
+
ok: false,
|
|
156
|
+
bytesWritten: 0,
|
|
157
|
+
reason: 'layer_d_deferred',
|
|
158
|
+
detail: error.message,
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
return {
|
|
162
|
+
layer: 'layer-d',
|
|
163
|
+
file: edit.edit.file,
|
|
164
|
+
ok: false,
|
|
165
|
+
bytesWritten: 0,
|
|
166
|
+
reason: 'apply_error',
|
|
167
|
+
detail: error instanceof Error ? error.message : String(error),
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
function toResult(layer, file, r) {
|
|
174
|
+
return {
|
|
175
|
+
layer,
|
|
176
|
+
file,
|
|
177
|
+
ok: r.ok,
|
|
178
|
+
bytesWritten: r.bytesWritten,
|
|
179
|
+
reason: r.reason,
|
|
180
|
+
detail: r.detail,
|
|
181
|
+
matchCount: r.matchCount,
|
|
182
|
+
absPath: r.absPath,
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
//# sourceMappingURL=dispatch.js.map
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* α6.6 diff escalation — public barrel.
|
|
3
|
+
*
|
|
4
|
+
* Surface for callers (CLI integration, future engine adapters, tests).
|
|
5
|
+
* Keeps the per-layer module path stable so β-tier additions (Layer D
|
|
6
|
+
* implementation, conflict resolution UI, unified-diff `git apply`
|
|
7
|
+
* fallback) can land without churn at the import sites.
|
|
8
|
+
*/
|
|
9
|
+
export { applyLayerA, countOccurrences, } from './layer-a-apply.js';
|
|
10
|
+
export { applyLayerB, } from './layer-b-apply.js';
|
|
11
|
+
export { applyLayerC, sha256OfUtf8, } from './layer-c-apply.js';
|
|
12
|
+
export { applyLayerD, LayerDDeferredError, } from './layer-d-ast.js';
|
|
13
|
+
export { MarkerParseError, detectFamily, parseMarkers, } from './marker-parser.js';
|
|
14
|
+
export { dispatchEdit, resolveFamily, } from './dispatch.js';
|
|
15
|
+
//# sourceMappingURL=index.js.map
|