@stigmer/cli 3.5.3 → 3.7.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.
- package/commands/agent-exec-flags.d.ts +1 -0
- package/commands/agent-exec-flags.d.ts.map +1 -1
- package/commands/agent-exec-flags.js +3 -1
- package/commands/agent-exec-flags.js.map +1 -1
- package/commands/list.js +8 -5
- package/commands/list.js.map +1 -1
- package/commands/mcp-server.js +1 -1
- package/commands/resume.js +5 -1
- package/commands/resume.js.map +1 -1
- package/commands/schedule.d.ts +3 -0
- package/commands/schedule.d.ts.map +1 -0
- package/commands/schedule.js +57 -0
- package/commands/schedule.js.map +1 -0
- package/package.json +5 -5
- package/program.d.ts.map +1 -1
- package/program.js +2 -0
- package/program.js.map +1 -1
- package/registry/metadata.d.ts.map +1 -1
- package/registry/metadata.js +2 -0
- package/registry/metadata.js.map +1 -1
- package/registry/verb-support.d.ts.map +1 -1
- package/registry/verb-support.js +29 -21
- package/registry/verb-support.js.map +1 -1
- package/registry/verbs.d.ts.map +1 -1
- package/registry/verbs.js +0 -1
- package/registry/verbs.js.map +1 -1
- package/resources/apply/apply.d.ts +6 -1
- package/resources/apply/apply.d.ts.map +1 -1
- package/resources/apply/apply.js +14 -24
- package/resources/apply/apply.js.map +1 -1
- package/resources/apply/handlers.d.ts +9 -1
- package/resources/apply/handlers.d.ts.map +1 -1
- package/resources/apply/handlers.js +50 -148
- package/resources/apply/handlers.js.map +1 -1
- package/resources/delete.d.ts +12 -0
- package/resources/delete.d.ts.map +1 -1
- package/resources/delete.js +8 -4
- package/resources/delete.js.map +1 -1
- package/resources/execution.d.ts +14 -4
- package/resources/execution.d.ts.map +1 -1
- package/resources/execution.js +16 -6
- package/resources/execution.js.map +1 -1
- package/resources/get-bindings.d.ts +1 -0
- package/resources/get-bindings.d.ts.map +1 -1
- package/resources/get-bindings.js +8 -1
- package/resources/get-bindings.js.map +1 -1
- package/resources/list.d.ts +4 -0
- package/resources/list.d.ts.map +1 -1
- package/resources/list.js +95 -27
- package/resources/list.js.map +1 -1
- package/resources/reference.d.ts +2 -0
- package/resources/reference.d.ts.map +1 -1
- package/resources/reference.js +4 -0
- package/resources/reference.js.map +1 -1
- package/resources/run/agent-exec.d.ts.map +1 -1
- package/resources/run/agent-exec.js +1 -0
- package/resources/run/agent-exec.js.map +1 -1
- package/resources/run/create.d.ts +2 -1
- package/resources/run/create.d.ts.map +1 -1
- package/resources/run/create.js +12 -6
- package/resources/run/create.js.map +1 -1
- package/resources/run/prepare.d.ts +15 -0
- package/resources/run/prepare.d.ts.map +1 -1
- package/resources/run/prepare.js +13 -0
- package/resources/run/prepare.js.map +1 -1
- package/resources/schedule.d.ts +22 -0
- package/resources/schedule.d.ts.map +1 -0
- package/resources/schedule.js +114 -0
- package/resources/schedule.js.map +1 -0
- package/src/commands/agent-exec-flags.ts +5 -2
- package/src/commands/list.ts +8 -5
- package/src/commands/mcp-server.ts +1 -1
- package/src/commands/resume.ts +8 -1
- package/src/commands/schedule.ts +70 -0
- package/src/program.ts +2 -0
- package/src/registry/metadata.ts +2 -0
- package/src/registry/registry.test.ts +113 -8
- package/src/registry/verb-support.ts +29 -21
- package/src/registry/verbs.ts +0 -1
- package/src/resources/apply/apply.integration.test.ts +132 -0
- package/src/resources/apply/apply.ts +16 -25
- package/src/resources/apply/handlers.ts +60 -150
- package/src/resources/delete.ts +8 -4
- package/src/resources/execution.ts +20 -6
- package/src/resources/get-bindings.ts +8 -1
- package/src/resources/list.ts +107 -31
- package/src/resources/mutate-verbs.integration.test.ts +78 -4
- package/src/resources/read-verbs.integration.test.ts +124 -5
- package/src/resources/reference.ts +5 -0
- package/src/resources/run/agent-exec.test.ts +1 -0
- package/src/resources/run/agent-exec.ts +1 -0
- package/src/resources/run/create.test.ts +44 -1
- package/src/resources/run/create.ts +16 -7
- package/src/resources/run/prepare.test.ts +14 -1
- package/src/resources/run/prepare.ts +25 -0
- package/src/resources/schedule.ts +132 -0
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
// `schedule resume` dispatch: clear a platform auto-pause from a schedule
|
|
2
|
+
// and report what was cleared.
|
|
3
|
+
//
|
|
4
|
+
// "Paused" is the platform's latch (status.paused_reason, written after
|
|
5
|
+
// repeated failed runs), distinct from "disabled", the owner's switch
|
|
6
|
+
// (spec.enabled) — two words, two levers (see docs/vocabulary.md). The
|
|
7
|
+
// resume RPC is deliberately the only path that clears the latch: applying
|
|
8
|
+
// a manifest preserves status verbatim, so no declarative workflow can
|
|
9
|
+
// silently un-pause a failing schedule.
|
|
10
|
+
//
|
|
11
|
+
// The pre-state read exists for honest messaging only: the RPC is
|
|
12
|
+
// idempotent and its response always shows a cleared latch, so "resumed"
|
|
13
|
+
// versus "was not paused" can only be told apart by looking first. The
|
|
14
|
+
// resume call is made either way — on the no-op path it doubles as a
|
|
15
|
+
// harmless re-arm of the schedule's clock.
|
|
16
|
+
|
|
17
|
+
import { timestampDate } from "@bufbuild/protobuf/wkt";
|
|
18
|
+
import type { Schedule } from "@stigmer/protos/ai/stigmer/agentic/schedule/v1/api_pb";
|
|
19
|
+
import { ScheduleRunOutcome } from "@stigmer/protos/ai/stigmer/agentic/schedule/v1/io_pb";
|
|
20
|
+
import type { Stigmer } from "@stigmer/sdk";
|
|
21
|
+
import { UsageError } from "../errors/index.js";
|
|
22
|
+
import { CommandResult } from "../output/index.js";
|
|
23
|
+
import { parseReference } from "./reference.js";
|
|
24
|
+
|
|
25
|
+
/** The schedule kind's canonical id prefix (proto kind_meta). */
|
|
26
|
+
const SCHEDULE_ID_PREFIX = "sch";
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Resolve `ref` (a `sch_…` id, `org/slug`, or bare slug against `org`),
|
|
30
|
+
* clear its platform pause, and describe the outcome.
|
|
31
|
+
*/
|
|
32
|
+
export async function resumeSchedule(stigmer: Stigmer, ref: string, org: string): Promise<CommandResult> {
|
|
33
|
+
const before = await loadSchedule(stigmer, ref, org);
|
|
34
|
+
const id = before.metadata?.id ?? "";
|
|
35
|
+
if (id === "") {
|
|
36
|
+
throw new UsageError(`Schedule '${ref}' has no id — cannot resume`);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const wasPausedReason = before.status?.pausedReason ?? "";
|
|
40
|
+
const wasFailures = before.status?.consecutiveFailures ?? 0;
|
|
41
|
+
|
|
42
|
+
const resumed = await stigmer.schedule.resume(id);
|
|
43
|
+
|
|
44
|
+
return describeOutcome(resumed, wasPausedReason, wasFailures);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
async function loadSchedule(stigmer: Stigmer, ref: string, org: string): Promise<Schedule> {
|
|
48
|
+
const parsed = parseReference(ref, org, SCHEDULE_ID_PREFIX);
|
|
49
|
+
if (parsed.kind === "id") {
|
|
50
|
+
return stigmer.schedule.get(parsed.id);
|
|
51
|
+
}
|
|
52
|
+
if (parsed.org === "") {
|
|
53
|
+
throw new UsageError(
|
|
54
|
+
"organization not set\n\nSet it with:\n stigmer config context set --org <org>\n stigmer schedule resume --org <org> ...",
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
return stigmer.schedule.getByReference({ org: parsed.org, slug: parsed.slug });
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Resolve `ref` (a `sch_…` id, `org/slug`, or bare slug against `org`) and
|
|
62
|
+
* fire it once, immediately (project DD-017 D-5/D-6, amending DD-014).
|
|
63
|
+
*
|
|
64
|
+
* The fire is SYNCHRONOUS: the RPC runs the full execution create pipeline
|
|
65
|
+
* and the result names the run's real outcome — the created execution's
|
|
66
|
+
* id, or the refusing gate's copy verbatim. A refused run renders as an
|
|
67
|
+
* error result (non-zero exit) so a scripted test fire fails honestly,
|
|
68
|
+
* but the trigger itself succeeded: the fire is recorded in the
|
|
69
|
+
* schedule's run history either way. A disabled schedule is refused by
|
|
70
|
+
* the server with teaching copy; the CLI relays the server's message
|
|
71
|
+
* verbatim (never pattern-match refusal text).
|
|
72
|
+
*/
|
|
73
|
+
export async function triggerSchedule(stigmer: Stigmer, ref: string, org: string): Promise<CommandResult> {
|
|
74
|
+
const before = await loadSchedule(stigmer, ref, org);
|
|
75
|
+
const id = before.metadata?.id ?? "";
|
|
76
|
+
if (id === "") {
|
|
77
|
+
throw new UsageError(`Schedule '${ref}' has no id — cannot trigger`);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const triggered = await stigmer.schedule.trigger(id);
|
|
81
|
+
const schedule = triggered.schedule ?? before;
|
|
82
|
+
const slug = schedule.metadata?.slug ?? "";
|
|
83
|
+
const name = schedule.metadata?.name || slug;
|
|
84
|
+
|
|
85
|
+
if (triggered.outcome === ScheduleRunOutcome.STARTED) {
|
|
86
|
+
const result = CommandResult.success(`Schedule '${name}' fired — run started`);
|
|
87
|
+
const section = result.addSection();
|
|
88
|
+
section.field("Execution", triggered.executionId);
|
|
89
|
+
section.field("Watch it", `stigmer get agentexecution ${triggered.executionId}`);
|
|
90
|
+
if (schedule.status?.nextFireAt !== undefined) {
|
|
91
|
+
section.field("Next cron fire", timestampDate(schedule.status.nextFireAt).toISOString());
|
|
92
|
+
}
|
|
93
|
+
return result;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// The run was refused deterministically (a launch gate said no, or the
|
|
97
|
+
// target agent is gone). The fire happened and is recorded in run
|
|
98
|
+
// history; the refusing gate's copy relays verbatim.
|
|
99
|
+
const what = triggered.outcome === ScheduleRunOutcome.TARGET_MISSING
|
|
100
|
+
? "the target agent was not found"
|
|
101
|
+
: "a launch gate refused the run";
|
|
102
|
+
const result = CommandResult.error(`Schedule '${name}' fired, but ${what}`);
|
|
103
|
+
const section = result.addSection();
|
|
104
|
+
section.field("Reason", triggered.refusalReason);
|
|
105
|
+
result.hint("The fire is recorded in the schedule's run history; fix the cause and trigger again.");
|
|
106
|
+
return result;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function describeOutcome(schedule: Schedule, wasPausedReason: string, wasFailures: number): CommandResult {
|
|
110
|
+
const slug = schedule.metadata?.slug ?? "";
|
|
111
|
+
const name = schedule.metadata?.name || slug;
|
|
112
|
+
const wasPaused = wasPausedReason !== "" || wasFailures > 0;
|
|
113
|
+
|
|
114
|
+
const result = CommandResult.success(
|
|
115
|
+
wasPaused ? `Schedule '${name}' resumed` : `Schedule '${name}' was not paused — nothing to clear`,
|
|
116
|
+
);
|
|
117
|
+
|
|
118
|
+
if (wasPaused) {
|
|
119
|
+
const section = result.addSection("Cleared");
|
|
120
|
+
if (wasPausedReason !== "") section.field("Pause reason", wasPausedReason);
|
|
121
|
+
if (wasFailures > 0) section.field("Consecutive failures", String(wasFailures));
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
if (schedule.spec?.enabled !== true) {
|
|
125
|
+
result.hint("This schedule is disabled (enabled: false) — it will not fire until you enable it:");
|
|
126
|
+
result.hint(` edit the manifest to 'enabled: true' and run: stigmer apply -f <file>`);
|
|
127
|
+
} else if (schedule.status?.nextFireAt !== undefined) {
|
|
128
|
+
result.addSection().field("Next fire", timestampDate(schedule.status.nextFireAt).toISOString());
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
return result;
|
|
132
|
+
}
|