@andromarces/agent-loops 0.2.2 → 0.3.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.
Files changed (36) hide show
  1. package/README.md +192 -114
  2. package/docs/orchestrator-instructions.md +25 -22
  3. package/package.json +2 -2
  4. package/src/agents/agy.mjs +2 -11
  5. package/src/agents/codex.mjs +3 -20
  6. package/src/agents/copilot.mjs +8 -16
  7. package/src/agents/opencode.mjs +2 -7
  8. package/src/agents/shared.mjs +29 -0
  9. package/src/cli.mjs +46 -25
  10. package/src/hook/antigravity-parent-guard.mjs +28 -0
  11. package/src/hook/copilot-parent-guard.mjs +5 -30
  12. package/src/hook/decision.mjs +59 -6
  13. package/src/hook/opencode-plugin.mjs +92 -0
  14. package/src/hook/parent-guard.mjs +8 -33
  15. package/src/install/commands.mjs +268 -0
  16. package/src/install/fsutil.mjs +159 -0
  17. package/src/install/harnesses.mjs +170 -0
  18. package/src/install/installer.mjs +688 -0
  19. package/src/install/manifest.mjs +222 -0
  20. package/src/install/settings.mjs +217 -0
  21. package/src/install/templates/antigravity/agent-loop-antigravity-parent-guard.mjs +14 -0
  22. package/src/install/templates/antigravity/hooks.json +16 -0
  23. package/src/install/templates/antigravity/skills/agent-loop/SKILL.md +24 -0
  24. package/src/install/templates/claude/skills/agent-loop/SKILL.md +33 -0
  25. package/src/install/templates/codex/skills/agent-loop/SKILL.md +30 -0
  26. package/src/install/templates/codex/skills/agent-loop/agents/openai.yaml +2 -0
  27. package/src/install/templates/copilot/hooks/parent-guard.json +15 -0
  28. package/src/install/templates/opencode/plugins/parent-guard.ts +11 -0
  29. package/src/lib/args.mjs +23 -0
  30. package/src/lib/hash.mjs +9 -0
  31. package/src/lib/log.mjs +18 -3
  32. package/src/lib/process-ancestry.mjs +104 -0
  33. package/src/lib/runstate.mjs +133 -38
  34. package/src/lib/snapshot.mjs +3 -7
  35. package/src/role.mjs +71 -87
  36. package/src/runtime.mjs +9 -9
package/src/runtime.mjs CHANGED
@@ -1,4 +1,5 @@
1
1
  import { defaultAgents, runAgent } from "./agents/index.mjs";
2
+ import { DEFAULT_MAX_STEPS } from "./lib/args.mjs";
2
3
  import { logError, logInfo, logWarn } from "./lib/log.mjs";
3
4
  import { withMutationCheck } from "./lib/snapshot.mjs";
4
5
  import { decide } from "./orchestrator.mjs";
@@ -59,8 +60,8 @@ export async function runChild(options) {
59
60
  ? workerPrompt(prompt, role.sessionId === null)
60
61
  : reviewerPrompt(prompt);
61
62
 
62
- const runFn = async () => {
63
- return invoke(
63
+ const runFn = () =>
64
+ invoke(
64
65
  agents,
65
66
  role,
66
67
  roleName,
@@ -69,7 +70,6 @@ export async function runChild(options) {
69
70
  onEvent,
70
71
  stepsUsed,
71
72
  );
72
- };
73
73
 
74
74
  try {
75
75
  const response = readOnly ? await withMutationCheck(cwd, roleName, runFn) : await runFn();
@@ -102,7 +102,7 @@ export async function runLoop(options) {
102
102
  const {
103
103
  task,
104
104
  cwd,
105
- maxSteps = 20,
105
+ maxSteps = DEFAULT_MAX_STEPS,
106
106
  timeout,
107
107
  signal,
108
108
  roles,
@@ -119,6 +119,8 @@ export async function runLoop(options) {
119
119
  return { exitCode, ...detail };
120
120
  }
121
121
 
122
+ let stepsUsed = 0;
123
+
122
124
  const orchAdapter = {
123
125
  async run(state, p, opts) {
124
126
  return withMutationCheck(cwd, "orchestrator", () =>
@@ -127,7 +129,6 @@ export async function runLoop(options) {
127
129
  },
128
130
  };
129
131
 
130
- let stepsUsed = 0;
131
132
  let prompt = initialPrompt({ task, maxSteps });
132
133
 
133
134
  while (true) {
@@ -140,11 +141,10 @@ export async function runLoop(options) {
140
141
  options: { cwd, timeout, signal },
141
142
  });
142
143
  } catch (err) {
143
- if (err?.name === "MutationError") {
144
- // Already logged at the detection site in withMutationCheck.
145
- throw err;
144
+ if (err?.name !== "MutationError") {
145
+ // A MutationError is already logged at the detection site in withMutationCheck.
146
+ logError(`orchestrator turn failed: ${String(err?.message ?? err).split("\n")[0]}`);
146
147
  }
147
- logError(`orchestrator turn failed: ${String(err?.message ?? err).split("\n")[0]}`);
148
148
  throw err;
149
149
  }
150
150