reevesagents 2.1.0 → 2.2.1

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.
@@ -1,19 +1,39 @@
1
1
  #!/usr/bin/env node
2
+ import {
3
+ startFlow
4
+ } from "./chunk-PKMTELW4.js";
2
5
  import {
3
6
  installSkills,
4
7
  skillsStatus
5
8
  } from "./chunk-QIHT27ZG.js";
9
+ import {
10
+ addFlowSpecs,
11
+ dropFlowSpec,
12
+ pauseFlow,
13
+ queueSpecFile,
14
+ resumeFlow,
15
+ stepFlow,
16
+ stopFlow
17
+ } from "./chunk-PVYM35RS.js";
6
18
  import {
7
19
  REEVESAGENTS_VERSION,
20
+ ackFlowIncident,
21
+ claimFlowIncident,
8
22
  createRunApproval,
23
+ flowIncidentAgeMs,
24
+ flowQueueSummary,
25
+ flowStatusPayload,
26
+ listFlowIncidents,
9
27
  listRunApprovals,
10
28
  readRunApproval,
29
+ resolveFlowIncident,
30
+ resolveFlowRunId,
11
31
  resolveRunApproval,
12
32
  sweepAgents,
13
33
  sweepAgentsThrottled,
14
34
  sweepOrphanSessions,
15
35
  sweepOrphanSessionsThrottled
16
- } from "./chunk-YWS3MILO.js";
36
+ } from "./chunk-XEOWHTRQ.js";
17
37
  import {
18
38
  ALLOWED_KEYS,
19
39
  BIN,
@@ -23,14 +43,18 @@ import {
23
43
  attach,
24
44
  attachAll,
25
45
  coerceExtraArgs,
46
+ createPlan,
26
47
  deleteAgent,
27
48
  deletePreset,
28
49
  deleteRunHistory,
29
50
  detach,
30
51
  detectAvailable,
31
52
  detectToolStatuses,
53
+ ensurePlanSummary,
32
54
  findAgent,
55
+ flowPath,
33
56
  hostStatus,
57
+ importInto,
34
58
  interrupt,
35
59
  isProvider,
36
60
  killAgent,
@@ -39,20 +63,31 @@ import {
39
63
  listRunHistory,
40
64
  listRuns,
41
65
  loadConfig,
66
+ mutatePlan,
42
67
  openTmuxTarget,
43
68
  peekAgent,
69
+ planExists,
70
+ planItemView,
71
+ planPath,
72
+ readFlow,
73
+ readPlan,
44
74
  readRun,
75
+ redactSecrets,
76
+ resolveRepositoryPath,
45
77
  runDoctor,
78
+ saveFlow,
46
79
  savePresetFromRun,
47
80
  sendKey,
48
81
  sendText,
49
82
  setConfigValues,
83
+ shortHomePath,
50
84
  spawnWorker,
51
85
  startRun,
52
86
  startRunFromPreset,
53
87
  startRunWithHead,
54
- stopRun
55
- } from "./chunk-DLWYZPW6.js";
88
+ stopRun,
89
+ withRunsLock
90
+ } from "./chunk-CJKEBBUI.js";
56
91
  import "./chunk-Q3WWQP2R.js";
57
92
 
58
93
  // src/surfaces/mcp/server.ts
@@ -64,6 +99,7 @@ import {
64
99
  ListToolsRequestSchema,
65
100
  ReadResourceRequestSchema
66
101
  } from "@modelcontextprotocol/sdk/types.js";
102
+ import { readFileSync as readFileSync2 } from "fs";
67
103
 
68
104
  // src/surfaces/mcp/host.ts
69
105
  import { execFileSync } from "child_process";
@@ -156,9 +192,27 @@ function fail(message) {
156
192
  isError: true
157
193
  };
158
194
  }
195
+ function runWorkingDir(runId) {
196
+ try {
197
+ return readRun(runId).working_dir;
198
+ } catch {
199
+ return process.cwd();
200
+ }
201
+ }
202
+ function readPlanDocument(path) {
203
+ try {
204
+ return readFileSync2(path, "utf-8");
205
+ } catch {
206
+ throw new Error(`cannot read ${shortHomePath(path)}`);
207
+ }
208
+ }
159
209
  function asString(value, fallback = "") {
160
210
  return typeof value === "string" ? value : fallback;
161
211
  }
212
+ function asPositiveNumber(value) {
213
+ const parsed = typeof value === "string" ? Number(value) : value;
214
+ return typeof parsed === "number" && Number.isFinite(parsed) && parsed > 0 ? parsed : void 0;
215
+ }
162
216
  function parseProvider(value) {
163
217
  if (isProvider(value)) return value;
164
218
  throw new Error(`Unsupported provider: ${String(value)}`);
@@ -515,9 +569,16 @@ var TOOLS = [
515
569
  },
516
570
  {
517
571
  name: "reap",
518
- description: "Sweep for zombie agents and orphan tmux sessions: ends any agent whose tmux window has died or that is older than max_lifetime_ms when that is set above 0 (see get_config), and kills reeves-*/reevesweb_* sessions no live record owns. Returns each reaped agent with the reason (window-gone or lifetime-exceeded) and its age, plus the killed orphan session names. This runs on its own in the background; call it to force an immediate sweep, e.g. after a crash or before relying on list.",
572
+ description: 'Sweep for zombie agents and orphan tmux sessions: ends any agent whose tmux window has died or that is older than max_lifetime_ms when that is set above 0 (see get_config), and kills reeves-*/reevesweb_* sessions no live record owns. Returns each reaped agent with the reason (window-gone or lifetime-exceeded) and its age, plus the killed orphan session names. When this state dir owns no runs at all but the tmux server carries reeves sessions, the orphan sweep is skipped (orphan_sweep_skipped = "foreign-registry") instead of treating another registry live fleet as orphans. This runs on its own in the background; call it to force an immediate sweep, e.g. after a crash or before relying on list.',
519
573
  inputSchema: { type: "object", properties: {} },
520
- handler: () => ok({ ...sweepAgents(), killed_sessions: sweepOrphanSessions({ ignoreGrace: true }).killed })
574
+ handler: () => {
575
+ const orphans = sweepOrphanSessions({ ignoreGrace: true });
576
+ return ok({
577
+ ...sweepAgents(),
578
+ killed_sessions: orphans.killed,
579
+ orphan_sweep_skipped: orphans.skipped ?? null
580
+ });
581
+ }
521
582
  },
522
583
  {
523
584
  name: "get_config",
@@ -646,6 +707,283 @@ var TOOLS = [
646
707
  }
647
708
  },
648
709
  handler: (a) => ok(a.status === true ? skillsStatus() : installSkills())
710
+ },
711
+ {
712
+ name: "flow_start",
713
+ description: "Attach a dev -> review -> fix flow to an existing run: the dev agent commits, the review agent reviews it, and the engine moves the loop. Both agents must already belong to that run; `repo` defaults to the run working directory. Writes one flow file and sends nothing \u2014 a flow only moves when someone ticks it, which this server never does on its own. Refuses a second flow on the same run, and refuses to replace an active one.",
714
+ inputSchema: {
715
+ type: "object",
716
+ properties: {
717
+ run_id: { type: "string", description: "Run id, or a unique prefix of it. A flow is keyed by run id." },
718
+ dev: { type: "string", description: "Dev agent id or nickname inside that run." },
719
+ review: { type: "string", description: "Review agent id or nickname inside that run; must differ from dev." },
720
+ repo: { type: "string", description: "Project directory the flow watches; defaults to the run working directory." },
721
+ max_rounds: { type: "number", description: "Fix rounds the flow may spend before it escalates (default 6)." },
722
+ review_timeout_sec: { type: "number", description: "Seconds a requested review may stay unanswered before it escalates (default 900)." },
723
+ dev_timeout_sec: { type: "number", description: "Seconds an idle dev may hold a plan item before a retry (default 900)." },
724
+ dev_stall_max_attempts: { type: "number", description: "Re-nudges before an idle plan item escalates (default 2)." },
725
+ replace: { type: "boolean", description: "Start over on a run whose flow is closed (escalated or done). An active flow is never replaced." }
726
+ },
727
+ required: ["run_id", "dev", "review"]
728
+ },
729
+ handler: (a) => {
730
+ const started = startFlow({
731
+ run_id: asString(a.run_id),
732
+ dev: asString(a.dev),
733
+ review: asString(a.review),
734
+ repo: asString(a.repo) || void 0,
735
+ max_rounds: asPositiveNumber(a.max_rounds),
736
+ review_timeout_sec: asPositiveNumber(a.review_timeout_sec),
737
+ dev_timeout_sec: asPositiveNumber(a.dev_timeout_sec),
738
+ dev_stall_max_attempts: asPositiveNumber(a.dev_stall_max_attempts),
739
+ replace: a.replace === true
740
+ });
741
+ return ok(flowStatusPayload(started.state, started.path));
742
+ }
743
+ },
744
+ {
745
+ name: "flow_status",
746
+ description: "Read the dev -> review -> fix pipeline attached to one run: its state, the round budget, the commit under review, the last verdict, the review deadline and the last decision. Read-only: it does not tick the flow and sends nothing to an agent.",
747
+ inputSchema: {
748
+ type: "object",
749
+ properties: {
750
+ run_id: { type: "string", description: "Run id, or a unique prefix of it. A flow is keyed by run id." }
751
+ },
752
+ required: ["run_id"]
753
+ },
754
+ handler: (a) => {
755
+ const runId = resolveFlowRunId(asString(a.run_id));
756
+ return ok(flowStatusPayload(readFlow(runId), flowPath(runId)));
757
+ }
758
+ },
759
+ {
760
+ name: "flow_incidents",
761
+ description: "List and route durable flow incidents. `claim` assigns responsibility to the orchestrator, `ack` records that the orchestrator has taken responsibility without resolving the incident, and `resolve` requires a note. No action sends text or keys to an agent pane.",
762
+ inputSchema: {
763
+ type: "object",
764
+ properties: {
765
+ run_id: { type: "string", description: "Run id, or a unique prefix." },
766
+ action: { type: "string", enum: ["list", "claim", "ack", "resolve"] },
767
+ incident_id: { type: "string", description: "Incident id or unique prefix for claim, ack, or resolve." },
768
+ note: { type: "string", description: "Required explanation when resolving an incident." }
769
+ },
770
+ required: ["run_id", "action"]
771
+ },
772
+ handler: (a) => {
773
+ const runId = resolveFlowRunId(asString(a.run_id));
774
+ const action = asString(a.action);
775
+ if (action === "list") {
776
+ const now = Date.now();
777
+ return ok({ run_id: runId, incidents: listFlowIncidents(runId, { open_only: true, now }).map((row) => ({ ...row, age_ms: flowIncidentAgeMs(row, now) })) });
778
+ }
779
+ const incidentId = asString(a.incident_id);
780
+ if (!incidentId) throw new Error(`${action} needs an incident_id`);
781
+ if (action === "claim") return ok(claimFlowIncident(runId, incidentId));
782
+ if (action === "ack") return ok(ackFlowIncident(runId, incidentId));
783
+ if (action === "resolve") return ok(resolveFlowIncident(runId, incidentId, asString(a.note)));
784
+ throw new Error(`unknown incident action ${JSON.stringify(action)}; expected list, claim, ack or resolve`);
785
+ }
786
+ },
787
+ {
788
+ name: "flow_add_spec",
789
+ description: "Queue a block spec file on the flow of one run: the next block the dev will receive. The file must already exist; a relative path resolves inside the flow project directory and may not leave it, an absolute path is taken as written. Refuses an unreadable or empty file, a spec without requirements or checks, and a block id already queued or dispatched. Queueing dispatches nothing.",
790
+ inputSchema: {
791
+ type: "object",
792
+ properties: {
793
+ run_id: { type: "string", description: "Run id, or a unique prefix of it." },
794
+ path: { type: "string", description: "Spec file: a JSON block spec, or a markdown brief (queued as an unstructured block)." }
795
+ },
796
+ required: ["run_id", "path"]
797
+ },
798
+ handler: (a) => {
799
+ const runId = resolveFlowRunId(asString(a.run_id));
800
+ const specPath = asString(a.path);
801
+ return withRunsLock(() => {
802
+ const queued = queueSpecFile(readFlow(runId), specPath);
803
+ saveFlow(queued.state);
804
+ return ok({
805
+ run_id: runId,
806
+ block: {
807
+ id: queued.spec.id,
808
+ // The title is user text: the answer is a transcript, so it is redacted here too.
809
+ title: redactSecrets(queued.spec.title),
810
+ unstructured: queued.spec.unstructured === true,
811
+ source_path: shortHomePath(queued.spec.source_path ?? "")
812
+ },
813
+ queue: flowQueueSummary(queued.state)
814
+ });
815
+ });
816
+ }
817
+ },
818
+ {
819
+ name: "flow_plan",
820
+ description: "Read the plan imported from the project document: progress, the items that wait for a human, the next item, and \u2014 with `item_id` \u2014 one item with the commit that closed it, its rounds and its brief. Read-only: it imports nothing and ticks nothing. Answers `{error}` when no plan was imported for the run.",
821
+ inputSchema: {
822
+ type: "object",
823
+ properties: {
824
+ run_id: { type: "string", description: "Run id, or a unique prefix of it." },
825
+ item_id: { type: "string", description: "Optional plan item id, e.g. P1.7.1, to read one item instead of the whole plan." }
826
+ },
827
+ required: ["run_id"]
828
+ },
829
+ handler: (a) => {
830
+ const runId = resolveFlowRunId(asString(a.run_id));
831
+ if (!planExists(runId)) return fail(`no plan for run ${runId}: import the project document first`);
832
+ ensurePlanSummary(runId);
833
+ const plan = readPlan(runId);
834
+ const itemId = asString(a.item_id);
835
+ if (itemId) {
836
+ const item = plan.items.find((entry) => entry.id === itemId);
837
+ if (!item) return fail(`no plan item ${itemId} in run ${runId}`);
838
+ return ok({ run_id: runId, item: planItemView(item), conflicts: plan.conflicts.filter((entry) => entry.item_id === itemId) });
839
+ }
840
+ const done = plan.items.filter((item) => item.status === "done").length;
841
+ const next = plan.items.find((item) => item.missing_since === null && item.status !== "done" && item.status !== "skipped");
842
+ return ok({
843
+ run_id: runId,
844
+ source_path: plan.source_path,
845
+ imported_at: plan.imported_at,
846
+ source_hash: plan.source_hash,
847
+ progress: { done, total: plan.items.length },
848
+ waiting: {
849
+ needs_brief: plan.items.filter((item) => item.status === "needs_brief").map((item) => item.id),
850
+ blocked_owner: plan.items.filter((item) => item.status === "blocked_owner").map((item) => item.id),
851
+ missing: plan.items.filter((item) => item.missing_since !== null).map((item) => item.id),
852
+ conflicts: plan.conflicts.length
853
+ },
854
+ next: next ? { id: next.id, title: next.title, status: next.status, spec_path: next.spec_path } : null,
855
+ // The items themselves, without the brief bodies: a payload is a transcript, the file is the record.
856
+ items: plan.items.map(planItemView)
857
+ });
858
+ }
859
+ },
860
+ {
861
+ name: "flow_plan_import",
862
+ description: "Import (or re-import) the project plan document into a flow. Adds new items, retires the ones the document dropped, retitles, and never demotes a closed item: a document that disagrees with the record produces an entry in `conflicts` instead. `dry_run: true` parses and reports without writing.",
863
+ inputSchema: {
864
+ type: "object",
865
+ properties: {
866
+ run_id: { type: "string", description: "Run id, or a unique prefix of it." },
867
+ file: { type: "string", description: "The plan document, e.g. docs/implementation-plan.md." },
868
+ dry_run: { type: "boolean", description: "Parse and report; write nothing." }
869
+ },
870
+ required: ["run_id", "file"]
871
+ },
872
+ handler: (a) => {
873
+ const runId = resolveFlowRunId(asString(a.run_id));
874
+ const file = asString(a.file);
875
+ const root = runWorkingDir(runId);
876
+ const target = resolveRepositoryPath(file, root);
877
+ const sourcePath = target.relative;
878
+ const text = readPlanDocument(target.absolute);
879
+ const dryRun = a.dry_run === true;
880
+ const result = dryRun ? planExists(runId) ? importInto(readPlan(runId), { run_id: runId, source_path: sourcePath, text, now: Date.now() }) : createPlan({ run_id: runId, source_path: sourcePath, text, now: Date.now() }) : mutatePlan(runId, (current) => {
881
+ const imported = current ? importInto(current, { run_id: runId, source_path: sourcePath, text, now: Date.now() }) : createPlan({ run_id: runId, source_path: sourcePath, text, now: Date.now() });
882
+ return { plan: imported.unchanged ? null : imported.plan, value: imported };
883
+ });
884
+ return ok({
885
+ run_id: runId,
886
+ dry_run: a.dry_run === true,
887
+ unchanged: result.unchanged,
888
+ added: result.added,
889
+ missing: result.missing,
890
+ conflicts: result.conflicts,
891
+ source_hash: result.source_hash,
892
+ total: result.plan.items.length,
893
+ path: shortHomePath(planPath(runId))
894
+ });
895
+ }
896
+ },
897
+ {
898
+ name: "flow_step",
899
+ description: "Run ONE engine step on a flow: observe, decide, claim, send and settle \u2014 the `flow tick` equivalent. It sends at most one guarded prompt, and only into a pane that is positively idle; an unsettled claim from another process makes it hold instead of pasting. Answers `changed: false` with the reason when it decided to do nothing, which makes polling it cheap. Nothing here starts a timer or a loop: one call is one step, and the flow engine owns every rule (rounds, timeout, escalation, pane guard).",
900
+ inputSchema: {
901
+ type: "object",
902
+ properties: {
903
+ run_id: { type: "string", description: "Run id, or a unique prefix of it." },
904
+ dry_run: { type: "boolean", description: "Print the decision; send nothing and write nothing." }
905
+ },
906
+ required: ["run_id"]
907
+ },
908
+ handler: (a) => {
909
+ const runId = resolveFlowRunId(asString(a.run_id));
910
+ const result = stepFlow(runId, { dryRun: a.dry_run === true });
911
+ return ok({
912
+ run_id: runId,
913
+ // What the host needs to decide whether to call again: nothing happened, it worked, a pane
914
+ // refused (retry later), a paste landed without its submit (a human looks), or another
915
+ // process owns the state right now.
916
+ changed: result.status === "applied",
917
+ status: result.status,
918
+ decision: result.decision.kind,
919
+ reason: result.decision.reason,
920
+ dry_run: a.dry_run === true,
921
+ send: result.send ? { sent: result.send.sent, reason: result.send.sent ? null : result.send.reason } : null,
922
+ flow: flowStatusPayload(result.state, result.path)
923
+ });
924
+ }
925
+ },
926
+ {
927
+ name: "flow_control",
928
+ description: "Drive a flow with one explicit action: `pause` parks it (a paused flow is never ticked and sends nothing), `resume` returns it to the state it was paused from or grants an escalated flow a fresh round budget, `stop` closes it for good and requires `confirm: true`, `add_spec` queues one block file (`file` for a structured JSON spec, `markdown` for an explicit unstructured ingest), `drop_spec` removes a queued block the engine never sent (`spec_id`, optional `reason`) and also requires `confirm: true`. Every action answers with the same payload `flow_status` returns; a refused action answers with the reason and its code (`not_found`, `already_dispatched`, `dispatch_pending`, `flow_closed`), never with a fake success.",
929
+ inputSchema: {
930
+ type: "object",
931
+ properties: {
932
+ run_id: { type: "string", description: "Run id, or a unique prefix of it." },
933
+ action: { type: "string", enum: ["pause", "resume", "stop", "add_spec", "drop_spec"], description: "What to do with the flow." },
934
+ file: { type: "string", description: "add_spec: JSON block spec path (requirements and checks are mandatory)." },
935
+ markdown: { type: "string", description: "add_spec: file to ingest as an unstructured markdown block. An explicit downgrade." },
936
+ spec_id: { type: "string", description: "drop_spec: the queued block id to remove, as `flow_status` lists it in `queue`." },
937
+ reason: { type: "string", description: "drop_spec: why it is being dropped; journalled as `spec_dropped <id>: <reason>`." },
938
+ confirm: { type: "boolean", description: "stop and drop_spec: must be true, because neither can be undone." }
939
+ },
940
+ required: ["run_id", "action"]
941
+ },
942
+ handler: (a) => {
943
+ const runId = resolveFlowRunId(asString(a.run_id));
944
+ const action = asString(a.action);
945
+ if (action === "pause") {
946
+ const paused = pauseFlow(runId);
947
+ return ok(flowStatusPayload(paused.state, paused.path));
948
+ }
949
+ if (action === "resume") {
950
+ const resumed = resumeFlow(runId);
951
+ return ok(flowStatusPayload(resumed.state, resumed.path));
952
+ }
953
+ if (action === "stop") {
954
+ if (a.confirm !== true) throw new Error("stop closes the flow for good; pass confirm: true");
955
+ const stopped = stopFlow(runId);
956
+ return ok(flowStatusPayload(stopped.state, stopped.path));
957
+ }
958
+ if (action === "add_spec") {
959
+ const file = asString(a.file);
960
+ const markdown = asString(a.markdown);
961
+ if (!file && !markdown) throw new Error("add_spec needs a `file` (JSON spec) or a `markdown` path");
962
+ if (file && markdown) throw new Error("add_spec takes one file per call: `file` or `markdown`, not both");
963
+ const added = addFlowSpecs({
964
+ run_id: runId,
965
+ files: file ? [file] : [],
966
+ markdown: markdown ? [markdown] : []
967
+ });
968
+ return ok({
969
+ run_id: runId,
970
+ queued: added.queued.map((spec) => ({
971
+ id: spec.id,
972
+ title: redactSecrets(spec.title),
973
+ unstructured: spec.unstructured === true
974
+ })),
975
+ flow: flowStatusPayload(added.state, added.path)
976
+ });
977
+ }
978
+ if (action === "drop_spec") {
979
+ if (a.confirm !== true) throw new Error("drop_spec removes a queued block; pass confirm: true");
980
+ const specId = asString(a.spec_id);
981
+ if (!specId) throw new Error("drop_spec needs a `spec_id` \u2014 the id `flow_status` lists in `queue`");
982
+ const dropped = dropFlowSpec({ run_id: runId, id: specId, reason: asString(a.reason) || void 0 });
983
+ return ok(flowStatusPayload(dropped.state, dropped.path));
984
+ }
985
+ throw new Error(`unknown action ${JSON.stringify(action)}; expected pause, resume, stop, add_spec or drop_spec`);
986
+ }
649
987
  }
650
988
  ];
651
989
  var MCP_TOOLS = TOOLS.map(({ name, description, inputSchema }) => ({ name, description, inputSchema }));
@@ -763,4 +1101,4 @@ export {
763
1101
  sessionRunIsLive,
764
1102
  startAgentMcpServer
765
1103
  };
766
- //# sourceMappingURL=server-TIFQ5JSM.js.map
1104
+ //# sourceMappingURL=server-4OILK2LL.js.map