@stigmer/cli 3.40.1 → 3.41.1-dev.20261003094357.g39d6aa748646
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/commands/config/context.js +3 -3
- package/commands/config/context.js.map +1 -1
- package/commands/resume.d.ts.map +1 -1
- package/commands/resume.js +12 -13
- package/commands/resume.js.map +1 -1
- package/commands/run.js +2 -2
- package/commands/run.js.map +1 -1
- package/config/config.d.ts +1 -1
- package/config/config.d.ts.map +1 -1
- package/config/keys.js +3 -3
- package/config/keys.js.map +1 -1
- package/config/resolve.d.ts +1 -1
- package/config/resolve.js +5 -5
- package/config/resolve.js.map +1 -1
- package/errors/classify.d.ts.map +1 -1
- package/errors/classify.js +24 -1
- package/errors/classify.js.map +1 -1
- package/local/artifact.d.ts +28 -6
- package/local/artifact.d.ts.map +1 -1
- package/local/artifact.js +88 -13
- package/local/artifact.js.map +1 -1
- package/local/bootstrap.js +1 -1
- package/local/bootstrap.js.map +1 -1
- package/local/daemon/components.d.ts.map +1 -1
- package/local/daemon/components.js +6 -1
- package/local/daemon/components.js.map +1 -1
- package/local/net/tcp.js +1 -1
- package/local/net/tcp.js.map +1 -1
- package/local/temporal/download.d.ts +12 -2
- package/local/temporal/download.d.ts.map +1 -1
- package/local/temporal/download.js +6 -2
- package/local/temporal/download.js.map +1 -1
- package/package.json +7 -7
- package/resources/run/prepare.d.ts +1 -1
- package/resources/run/prepare.js +4 -4
- package/resources/run/prepare.js.map +1 -1
- package/resources/run/resume.d.ts +0 -1
- package/resources/run/resume.d.ts.map +1 -1
- package/resources/run/resume.js +7 -4
- package/resources/run/resume.js.map +1 -1
- package/resources/run/workflow-stream.d.ts +9 -0
- package/resources/run/workflow-stream.d.ts.map +1 -1
- package/resources/run/workflow-stream.js +24 -4
- package/resources/run/workflow-stream.js.map +1 -1
- package/resources/stream/headless.d.ts +16 -0
- package/resources/stream/headless.d.ts.map +1 -1
- package/resources/stream/headless.js +33 -5
- package/resources/stream/headless.js.map +1 -1
- package/resources/stream/workflow-event-view.d.ts.map +1 -1
- package/resources/stream/workflow-event-view.js +14 -2
- package/resources/stream/workflow-event-view.js.map +1 -1
- package/resources/stream/workflow-render-ndjson.js +2 -0
- package/resources/stream/workflow-render-ndjson.js.map +1 -1
- package/resources/usage.d.ts +2 -2
- package/resources/usage.d.ts.map +1 -1
- package/resources/usage.js +4 -4
- package/resources/usage.js.map +1 -1
- package/src/commands/config/context.ts +3 -3
- package/src/commands/resume.ts +11 -17
- package/src/commands/run.ts +2 -2
- package/src/config/config.ts +1 -1
- package/src/config/keys.ts +3 -3
- package/src/config/resolve.ts +5 -5
- package/src/errors/classify.ts +27 -1
- package/src/local/artifact.ts +120 -15
- package/src/local/bootstrap.ts +1 -1
- package/src/local/daemon/components.ts +6 -1
- package/src/local/net/tcp.ts +1 -1
- package/src/local/temporal/download.ts +14 -4
- package/src/resources/run/prepare.ts +4 -4
- package/src/resources/run/resume.ts +7 -4
- package/src/resources/run/workflow-stream.ts +23 -3
- package/src/resources/stream/headless.ts +31 -4
- package/src/resources/stream/workflow-event-view.ts +14 -2
- package/src/resources/stream/workflow-render-ndjson.ts +2 -0
- package/src/resources/usage.ts +4 -4
package/src/local/net/tcp.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
// A single short-lived connection attempt tells us whether something is
|
|
5
5
|
// listening; waitForTcp loops that probe until a deadline, failing fast (with a
|
|
6
6
|
// log tail) if the process under watch exits first. This mirrors
|
|
7
|
-
// `test/
|
|
7
|
+
// `test/support/src/temporal.ts` so the CLI and the harnesses share
|
|
8
8
|
// one readiness model.
|
|
9
9
|
|
|
10
10
|
import { connect } from "node:net";
|
|
@@ -12,11 +12,12 @@
|
|
|
12
12
|
// all-in-one image bakes, so one pin and one verification serve every channel.
|
|
13
13
|
|
|
14
14
|
import { existsSync } from "node:fs";
|
|
15
|
-
import { fetchTarballBinary, mapReleaseArch, mapReleaseOs } from "../artifact.js";
|
|
15
|
+
import { fetchTarballBinary, mapReleaseArch, mapReleaseOs, type TarballInstall } from "../artifact.js";
|
|
16
16
|
|
|
17
17
|
// Re-exported so existing consumers (temporal/index.ts, download.test.ts) keep
|
|
18
18
|
// importing the tar reader from here.
|
|
19
19
|
export { extractTarEntry } from "../artifact.js";
|
|
20
|
+
export type { CacheMiss, TarballInstall } from "../artifact.js";
|
|
20
21
|
|
|
21
22
|
/**
|
|
22
23
|
* The Temporal CLI version every channel runs: `stigmer up`, the all-in-one
|
|
@@ -37,6 +38,11 @@ export interface TemporalDownloadTarget {
|
|
|
37
38
|
platform?: NodeJS.Platform;
|
|
38
39
|
/** Node arch (defaults to process.arch). */
|
|
39
40
|
arch?: string;
|
|
41
|
+
/**
|
|
42
|
+
* A directory that keeps the verified archive and its `checksums.txt` between
|
|
43
|
+
* installs, so a CI lane installs without the release host (`artifact.ts`).
|
|
44
|
+
*/
|
|
45
|
+
cacheDir?: string;
|
|
40
46
|
/** Override the fetch implementation (tests). */
|
|
41
47
|
fetchImpl?: typeof fetch;
|
|
42
48
|
/** Override the wait between download attempts (tests). */
|
|
@@ -53,16 +59,20 @@ export function temporalReleaseAssetUrl(version: string, asset: string): string
|
|
|
53
59
|
return `https://github.com/temporalio/cli/releases/download/v${version}/${asset}`;
|
|
54
60
|
}
|
|
55
61
|
|
|
56
|
-
/**
|
|
57
|
-
|
|
62
|
+
/**
|
|
63
|
+
* Install the verified Temporal CLI binary to `binPath`, from `cacheDir` when it
|
|
64
|
+
* holds a matching copy, otherwise downloaded; says which.
|
|
65
|
+
*/
|
|
66
|
+
export async function downloadTemporalCli(target: TemporalDownloadTarget): Promise<TarballInstall> {
|
|
58
67
|
const archive = temporalArchiveName(target.version, target.platform ?? process.platform, target.arch ?? process.arch);
|
|
59
68
|
|
|
60
|
-
|
|
69
|
+
return fetchTarballBinary({
|
|
61
70
|
url: temporalReleaseAssetUrl(target.version, archive),
|
|
62
71
|
checksumUrl: temporalReleaseAssetUrl(target.version, TEMPORAL_CHECKSUMS_FILE),
|
|
63
72
|
entryName: "temporal",
|
|
64
73
|
binPath: target.binPath,
|
|
65
74
|
label: "Temporal CLI",
|
|
75
|
+
cacheDir: target.cacheDir,
|
|
66
76
|
fetchImpl: target.fetchImpl,
|
|
67
77
|
sleep: target.sleep,
|
|
68
78
|
});
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
// Order matters and mirrors Go: validate cheap flags first (mode, approve
|
|
5
5
|
// default), then parse workspaces, then merge env, then process attachments
|
|
6
6
|
// (the only step that hits the network). A failure short-circuits before any
|
|
7
|
-
// upload.
|
|
7
|
+
// upload. STIGMER_ORG is injected into the runtime env when absent so agents
|
|
8
8
|
// can address the caller's org without the user wiring it manually.
|
|
9
9
|
|
|
10
10
|
import type { Attachment } from "@stigmer/protos/ai/stigmer/agentic/agentexecution/v1/spec_pb";
|
|
@@ -108,7 +108,7 @@ export interface PrepareAgentExecOptions {
|
|
|
108
108
|
|
|
109
109
|
/**
|
|
110
110
|
* Validate flags and resolve all execution inputs. The `org` is used to inject
|
|
111
|
-
*
|
|
111
|
+
* STIGMER_ORG and the `client` to upload non-workspace attachments.
|
|
112
112
|
*/
|
|
113
113
|
export async function prepareAgentExec(
|
|
114
114
|
flags: AgentExecFlags,
|
|
@@ -162,8 +162,8 @@ export async function prepareAgentExec(
|
|
|
162
162
|
envFiles: flags.envFile,
|
|
163
163
|
secretFiles: flags.secretFile,
|
|
164
164
|
});
|
|
165
|
-
if (runtimeEnv.
|
|
166
|
-
runtimeEnv.
|
|
165
|
+
if (runtimeEnv.STIGMER_ORG === undefined && org !== "") {
|
|
166
|
+
runtimeEnv.STIGMER_ORG = { value: org, isSecret: false };
|
|
167
167
|
}
|
|
168
168
|
|
|
169
169
|
const { attachments, workspaceFileRefs } = await processAttachments(
|
|
@@ -32,7 +32,6 @@ const ACTIVE_PHASES: ReadonlySet<ExecutionPhase> = new Set([
|
|
|
32
32
|
export interface OpenSessionDeps {
|
|
33
33
|
readonly client: BackendClient;
|
|
34
34
|
readonly sessionId: string;
|
|
35
|
-
readonly org: string;
|
|
36
35
|
/** Explicit --mode override; "" means infer from the latest execution. */
|
|
37
36
|
readonly mode: RunMode;
|
|
38
37
|
readonly outputMode: RunOutputMode;
|
|
@@ -41,6 +40,9 @@ export interface OpenSessionDeps {
|
|
|
41
40
|
export async function openSession(deps: OpenSessionDeps): Promise<void> {
|
|
42
41
|
const stigmer = deps.client.stigmer;
|
|
43
42
|
const session = await getSessionById(stigmer, deps.sessionId);
|
|
43
|
+
// Every turn in the session is filed under the session's own organization
|
|
44
|
+
// (stigmer/stigmer#1580), never the CLI's context organization.
|
|
45
|
+
const org = session.metadata?.org ?? "";
|
|
44
46
|
const entries = await listExecutionsBySession(stigmer, deps.sessionId);
|
|
45
47
|
if (entries.length === 0) {
|
|
46
48
|
process.stderr.write(`Session ${deps.sessionId} has no executions\n`);
|
|
@@ -66,7 +68,7 @@ export async function openSession(deps: OpenSessionDeps): Promise<void> {
|
|
|
66
68
|
client: stigmer,
|
|
67
69
|
sessionId: deps.sessionId,
|
|
68
70
|
executionId: latest.metadata?.id ?? "",
|
|
69
|
-
org
|
|
71
|
+
org,
|
|
70
72
|
mode: effectiveMode,
|
|
71
73
|
defaultAction: ApprovalAction.UNSPECIFIED,
|
|
72
74
|
outputMode: deps.outputMode,
|
|
@@ -75,13 +77,14 @@ export async function openSession(deps: OpenSessionDeps): Promise<void> {
|
|
|
75
77
|
return;
|
|
76
78
|
}
|
|
77
79
|
|
|
78
|
-
await replaySession(deps, entries, header);
|
|
80
|
+
await replaySession(deps, org, entries, header);
|
|
79
81
|
}
|
|
80
82
|
|
|
81
83
|
// Completed session: render the stored history. TTY → Ink (history + composer);
|
|
82
84
|
// headless → snapshot events through the matching renderer.
|
|
83
85
|
async function replaySession(
|
|
84
86
|
deps: OpenSessionDeps,
|
|
87
|
+
org: string,
|
|
85
88
|
entries: readonly AgentExecution[],
|
|
86
89
|
header: SessionHeaderInfo,
|
|
87
90
|
): Promise<void> {
|
|
@@ -90,7 +93,7 @@ async function replaySession(
|
|
|
90
93
|
await runInkSession({
|
|
91
94
|
client: deps.client.stigmer,
|
|
92
95
|
sessionId: deps.sessionId,
|
|
93
|
-
org
|
|
96
|
+
org,
|
|
94
97
|
mode: header.mode === "plan" ? "plan" : "agent",
|
|
95
98
|
});
|
|
96
99
|
return;
|
|
@@ -29,6 +29,7 @@ import type { Stigmer } from "@stigmer/sdk";
|
|
|
29
29
|
import { shouldColorize, type Styler, styler } from "../../output/style.js";
|
|
30
30
|
import { calculateDuration } from "../execution-format.js";
|
|
31
31
|
import { formatWorkflowPhase } from "../execution.js";
|
|
32
|
+
import { SUBSCRIPTION_DRAIN_GRACE_MS } from "../stream/headless.js";
|
|
32
33
|
import { APPROVAL_RETRY_BASE_DELAY_MS, APPROVAL_RETRY_MAX_ATTEMPTS, retryWithBackoff } from "../stream/submit.js";
|
|
33
34
|
import { toWorkflowEventView } from "../stream/workflow-event-view.js";
|
|
34
35
|
import { renderWorkflowEventPlaintext } from "../stream/workflow-render-plaintext.js";
|
|
@@ -56,6 +57,15 @@ export interface WorkflowStreamStreams {
|
|
|
56
57
|
* Stream a workflow execution to a terminal state, then print a summary. Returns
|
|
57
58
|
* the authoritative final execution (a final Get), mirroring the agent path's
|
|
58
59
|
* return for symmetry. Ctrl-C aborts the subscription cleanly.
|
|
60
|
+
*
|
|
61
|
+
* The subscription never outlives the stream, as on the agent path
|
|
62
|
+
* (resources/stream/headless.ts, #1522): after the terminal event the loop
|
|
63
|
+
* keeps reading, rendering nothing more, until the server ends the
|
|
64
|
+
* subscription, which it does on a terminal phase. Leaving the loop early
|
|
65
|
+
* leaves the HTTP/2 stream's remaining frames unread, so the stream is never
|
|
66
|
+
* destroyed and holds the process alive after the run has finished (#1625).
|
|
67
|
+
* A server that does not end it within SUBSCRIPTION_DRAIN_GRACE_MS is
|
|
68
|
+
* cancelled, and the subscription's own signal is aborted on every way out.
|
|
59
69
|
*/
|
|
60
70
|
export async function streamWorkflowExecution(
|
|
61
71
|
deps: WorkflowStreamDeps,
|
|
@@ -66,20 +76,30 @@ export async function streamWorkflowExecution(
|
|
|
66
76
|
process.once("SIGINT", onSignal);
|
|
67
77
|
process.once("SIGTERM", onSignal);
|
|
68
78
|
|
|
79
|
+
const subscription = new AbortController();
|
|
69
80
|
const resolved = new Set<string>();
|
|
81
|
+
let ended = false;
|
|
82
|
+
let grace: ReturnType<typeof setTimeout> | undefined;
|
|
70
83
|
try {
|
|
71
84
|
const stream = deps.client.workflowExecution.subscribeEvents(
|
|
72
85
|
create(SubscribeEventsRequestSchema, { executionId: deps.executionId }),
|
|
73
|
-
controller.signal,
|
|
86
|
+
AbortSignal.any([controller.signal, subscription.signal]),
|
|
74
87
|
);
|
|
75
88
|
for await (const event of stream) {
|
|
89
|
+
if (ended) continue;
|
|
76
90
|
renderEvent(event, deps.outputMode, streams);
|
|
77
91
|
await maybeResolveApproval(event, deps, streams, resolved, controller.signal);
|
|
78
|
-
if (toWorkflowEventView(event).terminal)
|
|
92
|
+
if (toWorkflowEventView(event).terminal) {
|
|
93
|
+
ended = true;
|
|
94
|
+
grace = setTimeout(() => subscription.abort(), SUBSCRIPTION_DRAIN_GRACE_MS);
|
|
95
|
+
}
|
|
79
96
|
}
|
|
80
97
|
} catch (error) {
|
|
81
|
-
|
|
98
|
+
// After the terminal event the only error is the grace period's own cancel.
|
|
99
|
+
if (!ended && !controller.signal.aborted) throw error;
|
|
82
100
|
} finally {
|
|
101
|
+
clearTimeout(grace);
|
|
102
|
+
subscription.abort();
|
|
83
103
|
process.removeListener("SIGINT", onSignal);
|
|
84
104
|
process.removeListener("SIGTERM", onSignal);
|
|
85
105
|
}
|
|
@@ -31,6 +31,12 @@ export interface HeadlessRenderer {
|
|
|
31
31
|
resolveApproval(event: ApprovalNeededEvent): ApprovalAction;
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
+
/**
|
|
35
|
+
* How long the driver keeps reading after the terminal snapshot, for the
|
|
36
|
+
* server to end the subscription, before it cancels the call itself.
|
|
37
|
+
*/
|
|
38
|
+
export const SUBSCRIPTION_DRAIN_GRACE_MS = 2_000;
|
|
39
|
+
|
|
34
40
|
/** The terminal outcome of a headless stream. */
|
|
35
41
|
export interface HeadlessResult {
|
|
36
42
|
readonly phase: string;
|
|
@@ -52,20 +58,41 @@ export interface HeadlessStreamDeps {
|
|
|
52
58
|
* Drive the stream to a terminal phase and return the outcome. Aborting (Ctrl-C)
|
|
53
59
|
* resolves cleanly with an empty result; a dropped stream renders a stream_error
|
|
54
60
|
* and returns its message.
|
|
61
|
+
*
|
|
62
|
+
* The subscription never outlives the drive (#1522). After the terminal
|
|
63
|
+
* snapshot the driver keeps reading, ignoring what follows, until the server
|
|
64
|
+
* ends the subscription, which it does on a terminal phase: an HTTP/2 stream
|
|
65
|
+
* whose unread frames are left in its buffer is never destroyed, and an open
|
|
66
|
+
* stream holds the session, and with it the process, alive after the run has
|
|
67
|
+
* finished. Leaving the loop early, or aborting the call once the server has
|
|
68
|
+
* already closed its side, does not release it. A server that does not end the
|
|
69
|
+
* stream within SUBSCRIPTION_DRAIN_GRACE_MS is cancelled, and the subscription
|
|
70
|
+
* is subscribed with a signal of the driver's own (joined to the caller's),
|
|
71
|
+
* aborted on every way out.
|
|
55
72
|
*/
|
|
56
73
|
export async function runHeadlessStream(deps: HeadlessStreamDeps): Promise<HeadlessResult> {
|
|
57
74
|
const differ = new SnapshotDiffer();
|
|
75
|
+
const subscription = new AbortController();
|
|
76
|
+
let outcome: HeadlessResult | undefined;
|
|
77
|
+
let grace: ReturnType<typeof setTimeout> | undefined;
|
|
58
78
|
try {
|
|
59
|
-
for await (const snapshot of deps.subscribe(deps.signal)) {
|
|
60
|
-
|
|
61
|
-
|
|
79
|
+
for await (const snapshot of deps.subscribe(AbortSignal.any([deps.signal, subscription.signal]))) {
|
|
80
|
+
if (outcome !== undefined) continue;
|
|
81
|
+
outcome = await drainSnapshot(differ.next(snapshot), deps);
|
|
82
|
+
if (outcome !== undefined) {
|
|
83
|
+
grace = setTimeout(() => subscription.abort(), SUBSCRIPTION_DRAIN_GRACE_MS);
|
|
84
|
+
}
|
|
62
85
|
}
|
|
63
|
-
return { phase: "", error: "" };
|
|
86
|
+
return outcome ?? { phase: "", error: "" };
|
|
64
87
|
} catch (err) {
|
|
88
|
+
if (outcome !== undefined) return outcome;
|
|
65
89
|
if (deps.signal.aborted) return { phase: "", error: "" };
|
|
66
90
|
const message = classifyStreamError(err, deps.sessionId);
|
|
67
91
|
deps.renderer.render({ kind: "streamError", error: message });
|
|
68
92
|
return { phase: "", error: message };
|
|
93
|
+
} finally {
|
|
94
|
+
clearTimeout(grace);
|
|
95
|
+
subscription.abort();
|
|
69
96
|
}
|
|
70
97
|
}
|
|
71
98
|
|
|
@@ -84,8 +84,20 @@ export function toWorkflowEventView(event: WorkflowExecutionEvent): WorkflowEven
|
|
|
84
84
|
case "approvalRequested":
|
|
85
85
|
return view("⏳", "warning", `approval requested: ${taskName} — ${event.payload.value.prompt}`);
|
|
86
86
|
case "approvalResolved": {
|
|
87
|
-
const { action, resolvedBy } = event.payload.value;
|
|
88
|
-
|
|
87
|
+
const { action, outcome, resolvedBy, autoResolved } = event.payload.value;
|
|
88
|
+
// A gate that timed out under the fail policy ends its approval with no
|
|
89
|
+
// decision at all; the task_failed line that follows says why the run
|
|
90
|
+
// stopped.
|
|
91
|
+
if (autoResolved && !outcome) {
|
|
92
|
+
return view("⏱", "warning", `approval resolved: ${taskName} — timed out, no decision`);
|
|
93
|
+
}
|
|
94
|
+
// A workflow human_input gate reports its declared outcome; the
|
|
95
|
+
// ApprovalAction enum is the agent tool approval's, and the fallback
|
|
96
|
+
// for events recorded before the payload carried an outcome.
|
|
97
|
+
const decision = outcome || approvalActionLabel(action);
|
|
98
|
+
const by = resolvedBy ? ` by ${resolvedBy}` : "";
|
|
99
|
+
const timeout = autoResolved ? " (timeout)" : "";
|
|
100
|
+
return view("✓", "success", `approval resolved: ${taskName} — ${decision}${by}${timeout}`);
|
|
89
101
|
}
|
|
90
102
|
case "budgetCheckpoint": {
|
|
91
103
|
const costUsd = Number(event.payload.value.costConsumedMicros) / 1_000_000;
|
|
@@ -51,6 +51,8 @@ function eventPayloadFields(event: WorkflowExecutionEvent): Record<string, unkno
|
|
|
51
51
|
case "approvalResolved":
|
|
52
52
|
return {
|
|
53
53
|
action: (ApprovalAction[event.payload.value.action] ?? "unspecified").toLowerCase(),
|
|
54
|
+
outcome: event.payload.value.outcome,
|
|
55
|
+
autoResolved: event.payload.value.autoResolved,
|
|
54
56
|
resolvedBy: event.payload.value.resolvedBy,
|
|
55
57
|
};
|
|
56
58
|
case "budgetCheckpoint":
|
package/src/resources/usage.ts
CHANGED
|
@@ -41,21 +41,21 @@ export async function getSessionUsageReport(client: Stigmer, sessionId: string):
|
|
|
41
41
|
export async function getAgentUsageReport(
|
|
42
42
|
client: Stigmer,
|
|
43
43
|
agentId: string,
|
|
44
|
-
|
|
44
|
+
org: string,
|
|
45
45
|
range: DateRange,
|
|
46
46
|
): Promise<GetAgentUsageReportOutput> {
|
|
47
47
|
return client.agentExecution.getAgentUsageReport(
|
|
48
|
-
create(GetAgentUsageReportInputSchema, { agentId,
|
|
48
|
+
create(GetAgentUsageReportInputSchema, { agentId, org, fromDate: range.from, toDate: range.to }),
|
|
49
49
|
);
|
|
50
50
|
}
|
|
51
51
|
|
|
52
52
|
export async function getOrgUsageReport(
|
|
53
53
|
client: Stigmer,
|
|
54
|
-
|
|
54
|
+
org: string,
|
|
55
55
|
range: DateRange,
|
|
56
56
|
): Promise<GetOrgUsageReportOutput> {
|
|
57
57
|
return client.agentExecution.getOrgUsageReport(
|
|
58
|
-
create(GetOrgUsageReportInputSchema, {
|
|
58
|
+
create(GetOrgUsageReportInputSchema, { org, fromDate: range.from, toDate: range.to }),
|
|
59
59
|
);
|
|
60
60
|
}
|
|
61
61
|
|