@opvs-ai/cli 0.27.7 → 0.27.8
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/dist/.build-stamp.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"stamp_version": 1,
|
|
3
3
|
"package": "@opvs-ai/cli",
|
|
4
|
-
"version": "0.27.
|
|
5
|
-
"source_digest": "
|
|
6
|
-
"source_files":
|
|
7
|
-
"built_at": "2026-10-
|
|
4
|
+
"version": "0.27.8",
|
|
5
|
+
"source_digest": "c5736038e34c5632093ba03eea1d055c671bc9dde3fd3c20834b7a87e71eba82",
|
|
6
|
+
"source_files": 62,
|
|
7
|
+
"built_at": "2026-10-26T12:41:58.686Z",
|
|
8
8
|
"node": "v22.23.3"
|
|
9
9
|
}
|
package/dist/commands/builds.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { createClient } from "@opvs-ai/core";
|
|
2
2
|
import { printJson } from "../lib/format.js";
|
|
3
|
+
import { resolveTaskId } from "../lib/task-refs.js";
|
|
3
4
|
function buildPath(ref, action) {
|
|
4
5
|
return `/api/v1/factory/steer/builds/${encodeURIComponent(ref)}/${action}`;
|
|
5
6
|
}
|
|
@@ -13,6 +14,26 @@ function status(error) {
|
|
|
13
14
|
const value = error?.status;
|
|
14
15
|
return typeof value === "number" ? value : undefined;
|
|
15
16
|
}
|
|
17
|
+
/**
|
|
18
|
+
* The API's 404 body for a card with no running build (OD-1957).
|
|
19
|
+
*
|
|
20
|
+
* The running build is the RESOURCE the read asks for, so "there is none" is
|
|
21
|
+
* a 404 — but the body still carries the same fields as the 200 (the card's
|
|
22
|
+
* planner messages, the ref, and the REASON), so the CLI renders it as the
|
|
23
|
+
* answer it is rather than as an error.
|
|
24
|
+
*/
|
|
25
|
+
function notRunning(error, ref) {
|
|
26
|
+
const body = error?.body;
|
|
27
|
+
return {
|
|
28
|
+
task_id: body?.task_id || ref,
|
|
29
|
+
ref: body?.ref || ref,
|
|
30
|
+
running: false,
|
|
31
|
+
steps: body?.steps || [],
|
|
32
|
+
messages: body?.messages || [],
|
|
33
|
+
reason: body?.reason ||
|
|
34
|
+
`No build is running for ${ref}.`,
|
|
35
|
+
};
|
|
36
|
+
}
|
|
16
37
|
function lastValue(raw) {
|
|
17
38
|
if (!/^\d+$/.test(raw)) {
|
|
18
39
|
throw new Error("--last must be an integer from 1 to 5");
|
|
@@ -35,7 +56,9 @@ function age(seconds) {
|
|
|
35
56
|
function formatRead(data) {
|
|
36
57
|
const ref = data.ref || data.task_id;
|
|
37
58
|
if (!data.running) {
|
|
38
|
-
|
|
59
|
+
// The API names WHY there is no build (OD-1957). Prefer its reason; fall
|
|
60
|
+
// back to the plain sentence so the output never loses the fact itself.
|
|
61
|
+
console.log(data.reason || `No build is running for ${ref}.`);
|
|
39
62
|
}
|
|
40
63
|
else {
|
|
41
64
|
console.log(`Build ${ref}: ${data.state || "running"} on ${data.env_id || "unknown desk"}`);
|
|
@@ -83,7 +106,12 @@ export function registerBuildCommands(program) {
|
|
|
83
106
|
.action(async (ref, message, opts) => {
|
|
84
107
|
await run(async () => {
|
|
85
108
|
const client = createClient(program.opts().workspace);
|
|
86
|
-
|
|
109
|
+
// Resolve the card REF to its task id FIRST, with the same resolver
|
|
110
|
+
// `opvs tasks get` uses (OD-1957). The builds route used to pass the
|
|
111
|
+
// raw string to a UUID-typed parameter and answer 422 for a card that
|
|
112
|
+
// exists.
|
|
113
|
+
const taskId = await resolveTaskId(client, ref);
|
|
114
|
+
const response = await client.post(buildPath(taskId, "tell"), { message });
|
|
87
115
|
const data = (await response.json());
|
|
88
116
|
if (opts.format === "json")
|
|
89
117
|
printJson(data);
|
|
@@ -103,8 +131,31 @@ export function registerBuildCommands(program) {
|
|
|
103
131
|
}
|
|
104
132
|
const last = lastValue(opts.last);
|
|
105
133
|
const client = createClient(program.opts().workspace);
|
|
106
|
-
|
|
107
|
-
|
|
134
|
+
// Resolve the card REF to its task id FIRST, with the same resolver
|
|
135
|
+
// `opvs tasks get` uses (OD-1957).
|
|
136
|
+
const taskId = await resolveTaskId(client, ref);
|
|
137
|
+
// A card with no running build is a 404 (OD-1957): the running build
|
|
138
|
+
// is the RESOURCE, and it does not exist. That is an ANSWER, not a
|
|
139
|
+
// failure — it is printed as "not running" with the API's reason, and
|
|
140
|
+
// the exit code stays 0. Only a card that cannot be found at all, or
|
|
141
|
+
// a real error, is a failure.
|
|
142
|
+
let data;
|
|
143
|
+
try {
|
|
144
|
+
const response = await client.get(`${buildPath(taskId, "read")}?last=${last}`);
|
|
145
|
+
if (response.ok) {
|
|
146
|
+
data = (await response.json());
|
|
147
|
+
}
|
|
148
|
+
else {
|
|
149
|
+
// A client that does not throw on a non-2xx still has to answer
|
|
150
|
+
// the same way a throwing one does.
|
|
151
|
+
data = notRunning({ status: response.status, body: await response.json() }, ref);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
catch (error) {
|
|
155
|
+
if (status(error) !== 404)
|
|
156
|
+
throw error;
|
|
157
|
+
data = notRunning(error, ref);
|
|
158
|
+
}
|
|
108
159
|
if (opts.format === "json")
|
|
109
160
|
printJson(data);
|
|
110
161
|
else
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"builds.js","sourceRoot":"","sources":["../../src/commands/builds.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAC7C,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"builds.js","sourceRoot":"","sources":["../../src/commands/builds.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAC7C,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAgCpD,SAAS,SAAS,CAAC,GAAW,EAAE,MAAuB;IACrD,OAAO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I,GAAG,UAAU,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;YAChC,CAAC;YACD,IAAI,IAAI,CAAC,MAAM,KAAK,MAAM;gBAAE,SAAS,CAAC,IAAI,CAAC,CAAC;;gBACvC,UAAU,CAAC,IAAI,CAAC,CAAC;QACxB,CAAC,EACD,0BAA0B,EAC1B,+JAA+J,CAChK,CAAC;IACJ,CAAC,CAAC,CAAC;AACP,CAAC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Client-side card-ref → task-UUID resolution for the builds surface (OD-1957).
|
|
3
|
+
*
|
|
4
|
+
* 🔴 Why this exists, and why it is not optional.
|
|
5
|
+
*
|
|
6
|
+
* `opvs builds read| tell` take a card REF (`OD-1950`). The route they reach
|
|
7
|
+
* used to hand that string straight to AgentBoard's `GET /api/v1/tasks/{task_id}`,
|
|
8
|
+
* whose parameter is typed `uuid.UUID` — so a perfectly good card REF was a
|
|
9
|
+
* **422**, measured against production by /test-live on 2026-10-26.
|
|
10
|
+
*
|
|
11
|
+
* The resolver for a card REF is the GATEWAY's, and the gateway resolves it on
|
|
12
|
+
* `GET /api/v1/board/tasks/{ref}`. That is the very call `opvs tasks get`
|
|
13
|
+
* makes, so asking for the card here borrows exactly the same resolution —
|
|
14
|
+
* no second set of rules to drift out of step with the board.
|
|
15
|
+
*
|
|
16
|
+
* The API resolves refs too (so a direct API caller is not punished), but the
|
|
17
|
+
* CLI resolving first means the builds route is reached with the id the rest
|
|
18
|
+
* of the CLI already uses, and a bad ref fails with the board's own message
|
|
19
|
+
* instead of a 422 about a UUID.
|
|
20
|
+
*/
|
|
21
|
+
/** True when the value is already a canonical task id needing no lookup. */
|
|
22
|
+
export declare function isTaskUuid(value: string): boolean;
|
|
23
|
+
interface TaskLookupClient {
|
|
24
|
+
get(url: string): Promise<Response>;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Resolve a card REF (or UUID) to the card's task UUID.
|
|
28
|
+
*
|
|
29
|
+
* A value that is already a UUID is returned untouched — no extra request, and
|
|
30
|
+
* no chance of the lookup disagreeing with the id the caller already had.
|
|
31
|
+
*
|
|
32
|
+
* A ref that cannot be resolved is a hard error here. The alternative is
|
|
33
|
+
* forwarding a value that the far side cannot read, and the far side's
|
|
34
|
+
* answer (a 422 about a UUID) says nothing about which card was meant.
|
|
35
|
+
*/
|
|
36
|
+
export declare function resolveTaskId(client: TaskLookupClient, ref: string): Promise<string>;
|
|
37
|
+
export {};
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Client-side card-ref → task-UUID resolution for the builds surface (OD-1957).
|
|
3
|
+
*
|
|
4
|
+
* 🔴 Why this exists, and why it is not optional.
|
|
5
|
+
*
|
|
6
|
+
* `opvs builds read| tell` take a card REF (`OD-1950`). The route they reach
|
|
7
|
+
* used to hand that string straight to AgentBoard's `GET /api/v1/tasks/{task_id}`,
|
|
8
|
+
* whose parameter is typed `uuid.UUID` — so a perfectly good card REF was a
|
|
9
|
+
* **422**, measured against production by /test-live on 2026-10-26.
|
|
10
|
+
*
|
|
11
|
+
* The resolver for a card REF is the GATEWAY's, and the gateway resolves it on
|
|
12
|
+
* `GET /api/v1/board/tasks/{ref}`. That is the very call `opvs tasks get`
|
|
13
|
+
* makes, so asking for the card here borrows exactly the same resolution —
|
|
14
|
+
* no second set of rules to drift out of step with the board.
|
|
15
|
+
*
|
|
16
|
+
* The API resolves refs too (so a direct API caller is not punished), but the
|
|
17
|
+
* CLI resolving first means the builds route is reached with the id the rest
|
|
18
|
+
* of the CLI already uses, and a bad ref fails with the board's own message
|
|
19
|
+
* instead of a 422 about a UUID.
|
|
20
|
+
*/
|
|
21
|
+
const UUID_RE = /^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/;
|
|
22
|
+
/** True when the value is already a canonical task id needing no lookup. */
|
|
23
|
+
export function isTaskUuid(value) {
|
|
24
|
+
return UUID_RE.test(value);
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Resolve a card REF (or UUID) to the card's task UUID.
|
|
28
|
+
*
|
|
29
|
+
* A value that is already a UUID is returned untouched — no extra request, and
|
|
30
|
+
* no chance of the lookup disagreeing with the id the caller already had.
|
|
31
|
+
*
|
|
32
|
+
* A ref that cannot be resolved is a hard error here. The alternative is
|
|
33
|
+
* forwarding a value that the far side cannot read, and the far side's
|
|
34
|
+
* answer (a 422 about a UUID) says nothing about which card was meant.
|
|
35
|
+
*/
|
|
36
|
+
export async function resolveTaskId(client, ref) {
|
|
37
|
+
if (isTaskUuid(ref)) {
|
|
38
|
+
return ref.toLowerCase();
|
|
39
|
+
}
|
|
40
|
+
let id;
|
|
41
|
+
let reason;
|
|
42
|
+
try {
|
|
43
|
+
// Ask for JSON explicitly: the caller's configured format may be yaml/md,
|
|
44
|
+
// and this is a lookup whose single field we have to read, not print.
|
|
45
|
+
const res = await client.get(`/api/v1/board/tasks/${encodeURIComponent(ref)}?format=json`);
|
|
46
|
+
if (res.ok) {
|
|
47
|
+
const data = (await res.json());
|
|
48
|
+
id = typeof data?.id === "string" ? data.id : undefined;
|
|
49
|
+
if (!id)
|
|
50
|
+
reason = "the board's answer carried no task id";
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
reason = `the board answered ${res.status}`;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
catch (error) {
|
|
57
|
+
const message = error?.message;
|
|
58
|
+
reason = message || "the board could not be reached";
|
|
59
|
+
}
|
|
60
|
+
if (!id) {
|
|
61
|
+
console.error(`Error: could not resolve card '${ref}'${reason ? ` (${reason})` : ""}.\n` +
|
|
62
|
+
` Pass a card ref (e.g. OD-1950) or the card's task UUID.`);
|
|
63
|
+
process.exit(1);
|
|
64
|
+
}
|
|
65
|
+
return id;
|
|
66
|
+
}
|
|
67
|
+
//# sourceMappingURL=task-refs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
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