@bybrawe/opencode-loop 0.6.1 → 0.6.2

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/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.6.2 - 2026-09-30
4
+
5
+ - Conform the native OpenCode 2 runtime to the migration-guide location/options boundary: project scope comes only from `ctx.location.directory`; plugin `ctx.options` can no longer masquerade as project location.
6
+ - Keep session/worktree isolation on public `session.get(...).location.directory` and fail setup/dispatch closed when project or session location cannot be established.
7
+ - Retain the official root/server/`./v2` `Plugin.define({ id, setup })` entrypoints, plural `plugins` installer migration, abortable event subscription cleanup, public command/session capabilities and separately isolated V1 compatibility.
8
+ - Keep undocumented `session.shell`, `session.compact` and `session.inbox` properties out of the V2 runtime; scheduled shell remains Loop-managed and automatic compaction remains host-owned.
9
+ - Add lifecycle regression coverage proving `options.directory` is not V2 location authority.
10
+ - Pair trusted publication with immutable OpenCode Goal 1.3.42 and re-run production tarballs plus the joint OpenCode 2.0.18 host matrix.
11
+
3
12
  ## 0.6.1 - 2026-09-29
4
13
 
5
14
  - Expose the root/server and `./v2` npm entrypoints through the official `@opencode/plugin` `Plugin.define({ id, setup })` contract while keeping V1 `server()` as a separate compatibility implementation.
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # OpenCode Loop
2
2
 
3
- ## Native OpenCode 2 (0.6.1)
3
+ ## Native OpenCode 2 (0.6.2)
4
4
 
5
5
  The npm and local-file V2 entrypoints now use the official `@opencode/plugin` `Plugin.define()` contract. The local installer writes a discovered plugin package directory with the generated runtime as a supporting module, while explicit `--legacy-v1` remains a separate compatibility path.
6
6
 
@@ -8,7 +8,7 @@ The installer now defaults to the standalone native V2 plugin. It needs no V1 SD
8
8
 
9
9
  V2 prompt admission and durable inbox/execution/compaction events own scheduling. Core-generated user-role messages never authorize a session abort. An unfinished dedicated Goal reserves its session, including paused and handed-off states; Loop does not wake or replace that Goal. Soft iteration timeouts do not abort a native model/tool/compaction turn.
10
10
 
11
- Scheduled shell commands use bounded local child processes when OpenCode does not expose `session.shell` to plugins. Automatic compaction stays host-owned. **Scheduled compaction requires a host exposing `session.compact`; OpenCode 2.0.18's published plugin Context does not expose it, and those commands are rejected before job creation rather than silently ignored.** Use OpenCode's built-in manual/automatic compaction on that host.
11
+ Scheduled shell commands use Loop-managed bounded local child processes; the OpenCode 2 `ctx.shell` surface is a hook domain, not a command-execution API. Automatic compaction stays host-owned. **The public OpenCode 2 SessionDomain has no manual compaction action, so `/loop-compact`, `--compact`, and `--compact-every` are rejected before job creation instead of probing undocumented `session.compact` fields.** Use OpenCode's built-in manual/automatic compaction on V2.
12
12
 
13
13
  Prompt/command timers, watch and stop conditions, verification, preflight/postrun, notifications, checkpoints and diagnostic commands use the V2 runtime. Uncertain restart admissions pause for review rather than replaying potentially admitted work. The dedicated `@bybrawe/opencode-goal` plugin owns `/goal`; legacy Loop Goal records are preserved and are not silently reinterpreted as new Goal contracts.
14
14
 
@@ -17,7 +17,7 @@ Prompt/command timers, watch and stop conditions, verification, preflight/postru
17
17
 
18
18
  OpenCode Loop adds `/loop`, scheduled prompt/command/shell jobs, compact scheduling, verification/checkpoints, and the `opencode-loopd` background daemon.
19
19
 
20
- > **Current stable release: `0.6.1`.**
20
+ > **Current stable release: `0.6.2`.**
21
21
 
22
22
  ## Install or update
23
23
 
@@ -0,0 +1,54 @@
1
+ # OpenCode Loop 0.6.2
2
+
3
+ OpenCode 2 migration-guide conformance release, paired with OpenCode Goal 1.3.42.
4
+
5
+ ## Public V2 plugin context
6
+
7
+ The native runtime treats `ctx.location.directory` as the only plugin-instance
8
+ project location. `ctx.options` remains plugin configuration and is not accepted as
9
+ a project-directory fallback.
10
+
11
+ Per-session scope is verified through public `session.get` location data, so a
12
+ session from another worktree/project cannot borrow this plugin instance's state.
13
+
14
+ ## V2 plugin and installation contract
15
+
16
+ The npm root/server and explicit `./v2` entries use
17
+ `@opencode/plugin` `Plugin.define({ id, setup })`. Native installs use plural
18
+ `plugins` configuration and the V2 plugins layout. Explicit `--legacy-v1` remains
19
+ a separate compatibility path; V1 hooks and SDK request shapes are not the default
20
+ V2 runtime.
21
+
22
+ Native prompt/compaction hooks, command transforms and the event subscription are
23
+ registered through V2 domains and disposed on unload. The event stream is cancelled
24
+ with an abort signal before local resources and registrations are drained.
25
+
26
+ ## Capability boundary
27
+
28
+ Loop does not probe undocumented `session.shell`, `session.compact` or
29
+ `session.inbox` properties. Scheduled shell execution is a bounded Loop-managed
30
+ local process. Manual scheduled compaction remains unsupported on the OpenCode
31
+ 2.0.18 public plugin contract and is rejected before durable job creation; automatic
32
+ compaction remains host-owned.
33
+
34
+ ## Paired Goal release
35
+
36
+ Publication is pinned to OpenCode Goal 1.3.42 from immutable source
37
+ `1dd58abf1e7c08594c2085883e28acea3dbe0418` and refuses to continue until that
38
+ exact package is visible on npm.
39
+
40
+ ## Verification
41
+
42
+ The publisher requires Windows/Linux native regressions, exact-main CI and Native V2
43
+ CI, production tarball installation, joint Goal+Loop installation/options/uninstall,
44
+ real native commands and the two-turn single-session daemon on OpenCode 2.0.18.
45
+
46
+ Install the verified pair after registry publication:
47
+
48
+ ```sh
49
+ npx -y @bybrawe/opencode-goal@1.3.42
50
+ npx -y @bybrawe/opencode-loop@0.6.2 --loop-only --without-loop-goals
51
+ ```
52
+
53
+ Fully restart OpenCode after installation. Existing project Goal/Loop state and
54
+ user-owned files are preserved.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bybrawe/opencode-loop",
3
- "version": "0.6.1",
3
+ "version": "0.6.2",
4
4
  "description": "Claude Code/Codex style /loop and experimental goal mode for OpenCode: heartbeat scheduler, idle-safe loops, scheduled commands, compact scheduling, verification, checkpoints, and persistent coding goals.",
5
5
  "type": "module",
6
6
  "main": "src/plugin.js",
@@ -19,6 +19,7 @@ async function fixture({ failDispose = false, failSubscribe = false } = {}) {
19
19
  const ctx = {
20
20
  location: { directory }, options: {},
21
21
  session: {
22
+ get: async ({ sessionID }) => ({ id: sessionID, location: { directory } }),
22
23
  prompt: async () => { throw new Error("cleanup must not prompt or abort a native session") },
23
24
  hook: async name => registration(name),
24
25
  },
@@ -46,6 +47,18 @@ async function bounded(promise) {
46
47
  finally { clearTimeout(timer) }
47
48
  }
48
49
 
50
+ test("native setup never treats plugin options.directory as location authority", async () => {
51
+ const host = await fixture()
52
+ try {
53
+ host.ctx.location = {}
54
+ host.ctx.options.directory = "/not-a-v2-location"
55
+ await assert.rejects(
56
+ plugin.setup(host.ctx),
57
+ /requires a project directory/i,
58
+ )
59
+ } finally { host.release(); await host.remove() }
60
+ })
61
+
49
62
  test("native unload aborts a pending public event stream and shares cleanup", async () => {
50
63
  const host = await fixture()
51
64
  let dispose
@@ -17,6 +17,7 @@ function fixture(directory, { failCleanup = false } = {}) {
17
17
  const ctx = {
18
18
  location: { directory }, options: {}, app: { version: "2.0.18" },
19
19
  session: {
20
+ get: async ({ sessionID }) => ({ id: sessionID, location: { directory } }),
20
21
  prompt: async () => { throw new Error("cleanup must not dispatch a prompt") },
21
22
  hook: async (name) => registration(name),
22
23
  },
@@ -47,6 +48,18 @@ async function bounded(promise) {
47
48
  } finally { clearTimeout(timer) }
48
49
  }
49
50
 
51
+ test("native Loop fails setup when the public session.get location capability is unavailable", async () => {
52
+ const directory = await mkdtemp(path.join(os.tmpdir(), "loop-v2-no-session-get-"))
53
+ const host = fixture(directory)
54
+ delete host.ctx.session.get
55
+ try {
56
+ await assert.rejects(plugin.setup(host.ctx), /requires session\.get/)
57
+ } finally {
58
+ host.end()
59
+ await rm(directory, { recursive: true, force: true, maxRetries: 5, retryDelay: 20 })
60
+ }
61
+ })
62
+
50
63
  test("native Loop aborts an idle subscription before awaiting iterator return", async () => {
51
64
  const directory = await mkdtemp(path.join(os.tmpdir(), "loop-v2-lifetime-"))
52
65
  const host = fixture(directory)
@@ -87,6 +100,26 @@ test("native Loop cleanup is shared and drains all registrations after an error"
87
100
  }
88
101
  })
89
102
 
103
+ test("native Loop never probes undocumented SessionDomain shell compact or inbox fields", async () => {
104
+ const directory = await mkdtemp(path.join(os.tmpdir(), "loop-v2-public-session-"))
105
+ const host = fixture(directory)
106
+ let dispose
107
+ try {
108
+ for (const field of ["shell", "compact", "inbox"]) {
109
+ Object.defineProperty(host.ctx.session, field, {
110
+ configurable: true,
111
+ get() { throw new Error(`undocumented session.${field} was accessed`) },
112
+ })
113
+ }
114
+ dispose = await plugin.setup(host.ctx)
115
+ assert.equal(typeof dispose, "function")
116
+ } finally {
117
+ host.end()
118
+ await dispose?.().catch(() => {})
119
+ await rm(directory, { recursive: true, force: true, maxRetries: 5, retryDelay: 20 })
120
+ }
121
+ })
122
+
90
123
  test("native Loop uses the same public plugin identity as the package entry", () => {
91
124
  assert.equal(plugin.id, "@bybrawe/opencode-loop", "native entry must share canonical plugin identity")
92
125
  })
@@ -9,9 +9,9 @@ import { presetDefaults } from "../src/source/core/jobs.js"
9
9
  import { normalizeLoopScheduleArgs } from "../src/source/core/schedule-syntax.js"
10
10
  import { readState } from "../src/source/core/state.js"
11
11
 
12
- const PRESETS = ["loop-dev", "loop-testfix", "loop-compact", "loop-progress", "loop-safe-dev", "loop-command", "loop-cmd", "loop-prompt", "loop-ask", "loop-shell"]
12
+ const PRESETS = ["loop-dev", "loop-testfix", "loop-progress", "loop-safe-dev", "loop-command", "loop-cmd", "loop-prompt", "loop-ask", "loop-shell"]
13
13
  const SESSION = "ses_native_presets"
14
- async function fixture({ compact = true } = {}) {
14
+ async function fixture() {
15
15
  const temp = await mkdtemp(path.join(os.tmpdir(), "loop-native-presets-"))
16
16
  const directory = path.join(temp, "project with spaces")
17
17
  await mkdir(directory)
@@ -27,7 +27,6 @@ async function fixture({ compact = true } = {}) {
27
27
  command: async () => { throw new Error("a deferred/dry-run preset must not execute a slash command") },
28
28
  wait: async () => {},
29
29
  shell: async request => { shellCalls.push(request); return { id: request.id, status: "exited", exit: 0 } },
30
- ...(compact ? { compact: async () => { throw new Error("a deferred/dry-run preset must not compact") } } : {}),
31
30
  },
32
31
  command: { transform: async edit => edit({ add(definition) {
33
32
  assert.equal(commands.has(definition.name), false, `duplicate command ${definition.name}`)
@@ -54,7 +53,7 @@ for (const name of PRESETS) {
54
53
  const action = ["loop-command", "loop-cmd"].includes(name) ? "/review project"
55
54
  : name === "loop-shell" ? "npm test"
56
55
  : ["loop-prompt", "loop-ask"].includes(name) ? "did you run tests and tsc --noEmit?" : ""
57
- const text = name === "loop-compact" ? "--dry-run" : `every 1h --dry-run --max-runs 2 ${action}`.trim()
56
+ const text = `every 1h --dry-run --max-runs 2 ${action}`.trim()
58
57
  const normalized = normalizeLoopScheduleArgs(text, presetDefaults(name))
59
58
  assert.equal(normalized.ok, true, normalized.error)
60
59
  const expected = parseLoopArgs(normalized.args, normalized.defaults)
@@ -64,7 +63,7 @@ for (const name of PRESETS) {
64
63
  const state = await host.state()
65
64
  assert.equal(state.jobs.length, 1)
66
65
  for (const field of fields) assert.deepEqual(state.jobs[0][field], expected.job[field], `${name}: ${field}`)
67
- assert.equal(state.jobs[0].intervalMs, name === "loop-compact" ? 12000000 : 3600000, "explicit duration cannot remain part of the task text")
66
+ assert.equal(state.jobs[0].intervalMs, 3600000, "explicit duration cannot remain part of the task text")
68
67
  assert.equal(state.jobs[0].immediate, false)
69
68
  assert.equal(state.jobs[0].scheduleMode, normalized.scheduleMode)
70
69
  assert.equal(state.jobs[0].scheduleSyntax, normalized.scheduleSyntax)
@@ -98,21 +97,28 @@ test("an immediate native development preset enters the existing dry-run safety
98
97
  } finally { await host.dispose() }
99
98
  })
100
99
 
101
- test("zero-delay deferred shell preset is scheduled without an unrelated model turn", async () => {
100
+ test("zero-delay deferred shell preset uses Loop-managed local execution without an unrelated model turn", async () => {
102
101
  const host = await fixture()
103
102
  try {
104
- await host.execute("loop-shell", "0s echo safe --max-runs 1")
105
- const deadline = Date.now() + 3000
106
- while (Date.now() < deadline && (await host.state()).jobs[0]?.v2Run) await new Promise(resolve => setTimeout(resolve, 10))
103
+ const marker = path.join(host.directory, "shell-ran.txt")
104
+ await writeFile(path.join(host.directory, "shell-test.cjs"), 'require("fs").writeFileSync("shell-ran.txt", "ok")')
105
+ const command = `"${process.execPath}" shell-test.cjs`
106
+ await host.execute("loop-shell", `0s ${command} --max-runs 1`)
107
+ const deadline = Date.now() + 5000
107
108
  while (Date.now() < deadline && (await host.state()).jobs[0]?.runCount !== 1) await new Promise(resolve => setTimeout(resolve, 10))
109
+ while (Date.now() < deadline) {
110
+ try { if ((await readFile(marker, "utf8")) === "ok") break } catch {}
111
+ await new Promise(resolve => setTimeout(resolve, 10))
112
+ }
108
113
  assert.equal((await host.state()).jobs[0].runCount, 1)
109
- assert.equal(host.shellCalls.length, 1)
114
+ assert.equal(await readFile(marker, "utf8"), "ok")
115
+ assert.equal(host.shellCalls.length, 0, "V2 must not call undocumented session.shell")
110
116
  assert.deepEqual(host.prompts, [])
111
117
  } finally { await host.dispose() }
112
118
  })
113
119
 
114
- test("unavailable native compaction rejects its preset before job persistence", async () => {
115
- const host = await fixture({ compact: false })
120
+ test("native compaction rejects its preset before job persistence because V2 exposes no manual compaction action", async () => {
121
+ const host = await fixture()
116
122
  try {
117
123
  await assert.rejects(host.execute("loop-compact", "--dry-run"), /native compaction capability/)
118
124
  assert.deepEqual((await host.state()).jobs, [])
@@ -7,12 +7,12 @@ export function validateRelease(request, pkg, env) {
7
7
  assert.equal(env.GITHUB_REPOSITORY, "ByBrawe/opencode-loop", "wrong release repository")
8
8
  assert.equal(env.GITHUB_REF, "refs/heads/main", "npm release must come from main")
9
9
  assert.match(env.GITHUB_SHA ?? "", /^[a-f0-9]{40}$/, "immutable release SHA required")
10
- assert.equal(request?.version, "0.6.1", "release version is not authorized")
10
+ assert.equal(request?.version, "0.6.2", "release version is not authorized")
11
11
  assert.equal(request?.name, "@bybrawe/opencode-loop")
12
12
  assert.equal(pkg.name, request.name)
13
13
  assert.equal(pkg.version, request.version)
14
- assert.equal(request.predecessor, "0.6.0")
15
- assert.equal(request.goal?.version, "1.3.40")
14
+ assert.equal(request.predecessor, "0.6.1")
15
+ assert.equal(request.goal?.version, "1.3.42")
16
16
  assert.match(request.goal?.sha ?? "", /^[a-f0-9]{40}$/)
17
17
  return request
18
18
  }
@@ -183,6 +183,16 @@ await test("preflight failure does not consume a run", async (f) => {
183
183
  assert.equal(f.prompts.length, 0)
184
184
  }, { runShellCommand: async () => ({ code: 3, stdout: "", stderr: "not ready" }) })
185
185
 
186
+ await test("native slash command dispatch uses OpenCode 2 command and arguments fields", async (f) => {
187
+ await f.add("0s --command /review --staged --max-runs 1")
188
+ await f.wake()
189
+ assert.equal(f.commands.length, 1)
190
+ assert.equal(f.commands[0].command, "review")
191
+ assert.equal(f.commands[0].arguments, "--staged")
192
+ assert.equal("name" in f.commands[0], false)
193
+ assert.equal("text" in f.commands[0], false)
194
+ })
195
+
186
196
  await test("safe guard covers verification commands too", async (f) => {
187
197
  await f.add('0s task --safe --verify "git reset --hard" --max-runs 1')
188
198
  await f.wake()
@@ -41,14 +41,14 @@ const publisher = workflow.slice(workflow.indexOf(" publish:\n"), workflow.inde
41
41
  assert.doesNotMatch(publisher, /contents:\s*write/, "OIDC publisher must not gain repository mutation privileges")
42
42
 
43
43
  const sha = "a".repeat(40)
44
- const request = { name: "@bybrawe/opencode-loop", version: "0.6.1", predecessor: "0.6.0", goal: { version: "1.3.40", sha: "b".repeat(40) } }
44
+ const request = { name: "@bybrawe/opencode-loop", version: "0.6.2", predecessor: "0.6.1", goal: { version: "1.3.42", sha: "b".repeat(40) } }
45
45
  const pkg = { name: request.name, version: request.version }
46
46
  const env = { GITHUB_REPOSITORY: "ByBrawe/opencode-loop", GITHUB_REF: "refs/heads/main", GITHUB_SHA: sha }
47
47
  assert.strictEqual(validateRelease(request, pkg, env), request)
48
48
  for (const change of [{ GITHUB_REPOSITORY: "someone/fork" }, { GITHUB_REF: "refs/heads/release" }, { GITHUB_SHA: "main" }]) assert.throws(() => validateRelease(request, pkg, { ...env, ...change }))
49
49
  assert.throws(() => validateRelease({ ...request, version: "9.0.0" }, pkg, env))
50
- assert.throws(() => validateRelease(request, { ...pkg, version: "0.6.0" }, env))
51
- assert.equal(releaseDecision(404, null, request, sha, "0.6.0"), true)
50
+ assert.throws(() => validateRelease(request, { ...pkg, version: "0.6.1" }, env))
51
+ assert.equal(releaseDecision(404, null, request, sha, "0.6.1"), true)
52
52
  for (const status of [401, 403, 429, 500, 503]) assert.throws(() => releaseDecision(status, null, request, sha, "0.6.0"))
53
53
  assert.throws(() => releaseDecision(404, null, request, sha, "0.7.0"))
54
54
  const manifest = { ...pkg, gitHead: sha }
package/src/native.js CHANGED
@@ -1862,7 +1862,7 @@ ${await policy.buildPrompt(scope.directory, job)}`, delivery: "queue", metadata:
1862
1862
  request = { sessionID: scope.sessionID, id: id(), command: String(job.action).replace(/^[!$]\s*/, ""), timeoutMs: job.timeoutMs };
1863
1863
  else {
1864
1864
  const [name, text] = splitFirst(String(job.action).replace(/^\/+/, ""));
1865
- request = { sessionID: scope.sessionID, name, text: text || "", delivery: "queue" };
1865
+ request = { sessionID: scope.sessionID, command: name, arguments: text || "", delivery: "queue" };
1866
1866
  }
1867
1867
  if (!isCurrent())
1868
1868
  return result({ reason: "foreground-or-compaction" });
@@ -2963,8 +2963,8 @@ Presets: /loop-dev, /loop-testfix, /loop-progress, /loop-safe-dev, /loop-ask, /l
2963
2963
  /loop-init [progress.md] creates a missing project-local progress file without overwriting existing data.
2964
2964
  Controls: /loop-now, /loop-pause, /loop-resume, /loop-stop, /loop-remove, /loop-clear, /loop-status, /loop-export.
2965
2965
  Preflight, postrun, notifications, stop files, completion markers, runtime/failure/run limits, branches and checkpoints are supported.
2966
- Scheduled shell commands run as bounded local child processes when the plugin context has no session.shell.
2967
- Scheduled/manual compaction requires session.compact on the host; unavailable capability is rejected before creating a job. Native automatic compaction is always left to OpenCode.
2966
+ Scheduled shell commands run as bounded local child processes managed by Loop; OpenCode 2's ctx.shell surface is a hook API, not a shell-execution method.
2967
+ The public OpenCode 2 plugin API does not expose manual session compaction. /loop-compact, --compact and --compact-every are rejected before job creation on V2; native automatic compaction remains host-owned and is observed through the compaction hook.
2968
2968
  An unfinished dedicated Goal reserves its session; Loop will not override it.
2969
2969
  --timeout pauses future iterations without aborting the current native model/tool/compaction operation.
2970
2970
  --safe is a command heuristic, not a sandbox. --dry-run does not dispatch or run hooks.
@@ -2982,11 +2982,11 @@ async function cleanup(value) {
2982
2982
  var OpenCodeLoopNativePlugin = Object.freeze({
2983
2983
  id: "@bybrawe/opencode-loop",
2984
2984
  async setup(ctx) {
2985
- for (const [label, fn] of [["session.prompt", ctx?.session?.prompt], ["session.hook", ctx?.session?.hook], ["event.subscribe", ctx?.event?.subscribe], ["command.transform", ctx?.command?.transform]]) {
2985
+ for (const [label, fn] of [["session.get", ctx?.session?.get], ["session.prompt", ctx?.session?.prompt], ["session.hook", ctx?.session?.hook], ["event.subscribe", ctx?.event?.subscribe], ["command.transform", ctx?.command?.transform]]) {
2986
2986
  if (typeof fn !== "function")
2987
2987
  throw new Error(`Native OpenCode Loop requires ${label}; use OpenCode 2.0.18 or newer.`);
2988
2988
  }
2989
- const directory = String(ctx.location?.directory || ctx.options?.directory || "").trim();
2989
+ const directory = String(ctx.location?.directory || "").trim();
2990
2990
  if (!directory)
2991
2991
  throw new Error("Native OpenCode Loop requires a project directory");
2992
2992
  const ownsSession = createNativeSessionLocationGuard({
@@ -3010,12 +3010,9 @@ var OpenCodeLoopNativePlugin = Object.freeze({
3010
3010
  prompt,
3011
3011
  command: typeof ctx.session.command === "function" ? (request) => ctx.session.command(request) : undefined,
3012
3012
  wait: typeof ctx.session.wait === "function" ? (request) => ctx.session.wait(request) : undefined,
3013
- compact: typeof ctx.session.compact === "function" ? (request) => ctx.session.compact({ ...request, delivery: "queue" }) : undefined,
3014
- shell: typeof ctx.session.shell === "function" ? (request) => ctx.session.shell(request) : (request) => shellHost.dispatch(request),
3015
- cancel: typeof ctx.session.inbox?.cancel === "function" ? async (request) => {
3016
- await ctx.session.inbox.cancel(request);
3017
- return false;
3018
- } : undefined,
3013
+ compact: undefined,
3014
+ shell: (request) => shellHost.dispatch(request),
3015
+ cancel: undefined,
3019
3016
  onError: (error) => {
3020
3017
  appendLoopLog(directory, "v2-native-error", { message: String(error?.message || error) }).catch(() => {});
3021
3018
  }
package/src/server.js CHANGED
@@ -1862,7 +1862,7 @@ ${await policy.buildPrompt(scope.directory, job)}`, delivery: "queue", metadata:
1862
1862
  request = { sessionID: scope.sessionID, id: id(), command: String(job.action).replace(/^[!$]\s*/, ""), timeoutMs: job.timeoutMs };
1863
1863
  else {
1864
1864
  const [name, text] = splitFirst(String(job.action).replace(/^\/+/, ""));
1865
- request = { sessionID: scope.sessionID, name, text: text || "", delivery: "queue" };
1865
+ request = { sessionID: scope.sessionID, command: name, arguments: text || "", delivery: "queue" };
1866
1866
  }
1867
1867
  if (!isCurrent())
1868
1868
  return result({ reason: "foreground-or-compaction" });
@@ -2963,8 +2963,8 @@ Presets: /loop-dev, /loop-testfix, /loop-progress, /loop-safe-dev, /loop-ask, /l
2963
2963
  /loop-init [progress.md] creates a missing project-local progress file without overwriting existing data.
2964
2964
  Controls: /loop-now, /loop-pause, /loop-resume, /loop-stop, /loop-remove, /loop-clear, /loop-status, /loop-export.
2965
2965
  Preflight, postrun, notifications, stop files, completion markers, runtime/failure/run limits, branches and checkpoints are supported.
2966
- Scheduled shell commands run as bounded local child processes when the plugin context has no session.shell.
2967
- Scheduled/manual compaction requires session.compact on the host; unavailable capability is rejected before creating a job. Native automatic compaction is always left to OpenCode.
2966
+ Scheduled shell commands run as bounded local child processes managed by Loop; OpenCode 2's ctx.shell surface is a hook API, not a shell-execution method.
2967
+ The public OpenCode 2 plugin API does not expose manual session compaction. /loop-compact, --compact and --compact-every are rejected before job creation on V2; native automatic compaction remains host-owned and is observed through the compaction hook.
2968
2968
  An unfinished dedicated Goal reserves its session; Loop will not override it.
2969
2969
  --timeout pauses future iterations without aborting the current native model/tool/compaction operation.
2970
2970
  --safe is a command heuristic, not a sandbox. --dry-run does not dispatch or run hooks.
@@ -2982,11 +2982,11 @@ async function cleanup(value) {
2982
2982
  var OpenCodeLoopNativePlugin = Object.freeze({
2983
2983
  id: "@bybrawe/opencode-loop",
2984
2984
  async setup(ctx) {
2985
- for (const [label, fn] of [["session.prompt", ctx?.session?.prompt], ["session.hook", ctx?.session?.hook], ["event.subscribe", ctx?.event?.subscribe], ["command.transform", ctx?.command?.transform]]) {
2985
+ for (const [label, fn] of [["session.get", ctx?.session?.get], ["session.prompt", ctx?.session?.prompt], ["session.hook", ctx?.session?.hook], ["event.subscribe", ctx?.event?.subscribe], ["command.transform", ctx?.command?.transform]]) {
2986
2986
  if (typeof fn !== "function")
2987
2987
  throw new Error(`Native OpenCode Loop requires ${label}; use OpenCode 2.0.18 or newer.`);
2988
2988
  }
2989
- const directory = String(ctx.location?.directory || ctx.options?.directory || "").trim();
2989
+ const directory = String(ctx.location?.directory || "").trim();
2990
2990
  if (!directory)
2991
2991
  throw new Error("Native OpenCode Loop requires a project directory");
2992
2992
  const ownsSession = createNativeSessionLocationGuard({
@@ -3010,12 +3010,9 @@ var OpenCodeLoopNativePlugin = Object.freeze({
3010
3010
  prompt,
3011
3011
  command: typeof ctx.session.command === "function" ? (request) => ctx.session.command(request) : undefined,
3012
3012
  wait: typeof ctx.session.wait === "function" ? (request) => ctx.session.wait(request) : undefined,
3013
- compact: typeof ctx.session.compact === "function" ? (request) => ctx.session.compact({ ...request, delivery: "queue" }) : undefined,
3014
- shell: typeof ctx.session.shell === "function" ? (request) => ctx.session.shell(request) : (request) => shellHost.dispatch(request),
3015
- cancel: typeof ctx.session.inbox?.cancel === "function" ? async (request) => {
3016
- await ctx.session.inbox.cancel(request);
3017
- return false;
3018
- } : undefined,
3013
+ compact: undefined,
3014
+ shell: (request) => shellHost.dispatch(request),
3015
+ cancel: undefined,
3019
3016
  onError: (error) => {
3020
3017
  appendLoopLog(directory, "v2-native-error", { message: String(error?.message || error) }).catch(() => {});
3021
3018
  }
@@ -20,8 +20,8 @@ Presets: /loop-dev, /loop-testfix, /loop-progress, /loop-safe-dev, /loop-ask, /l
20
20
  /loop-init [progress.md] creates a missing project-local progress file without overwriting existing data.
21
21
  Controls: /loop-now, /loop-pause, /loop-resume, /loop-stop, /loop-remove, /loop-clear, /loop-status, /loop-export.
22
22
  Preflight, postrun, notifications, stop files, completion markers, runtime/failure/run limits, branches and checkpoints are supported.
23
- Scheduled shell commands run as bounded local child processes when the plugin context has no session.shell.
24
- Scheduled/manual compaction requires session.compact on the host; unavailable capability is rejected before creating a job. Native automatic compaction is always left to OpenCode.
23
+ Scheduled shell commands run as bounded local child processes managed by Loop; OpenCode 2's ctx.shell surface is a hook API, not a shell-execution method.
24
+ The public OpenCode 2 plugin API does not expose manual session compaction. /loop-compact, --compact and --compact-every are rejected before job creation on V2; native automatic compaction remains host-owned and is observed through the compaction hook.
25
25
  An unfinished dedicated Goal reserves its session; Loop will not override it.
26
26
  --timeout pauses future iterations without aborting the current native model/tool/compaction operation.
27
27
  --safe is a command heuristic, not a sandbox. --dry-run does not dispatch or run hooks.
@@ -38,10 +38,10 @@ async function cleanup(value) {
38
38
  export const OpenCodeLoopNativePlugin = Object.freeze({
39
39
  id: "@bybrawe/opencode-loop",
40
40
  async setup(ctx) {
41
- for (const [label, fn] of [["session.prompt", ctx?.session?.prompt], ["session.hook", ctx?.session?.hook], ["event.subscribe", ctx?.event?.subscribe], ["command.transform", ctx?.command?.transform]]) {
41
+ for (const [label, fn] of [["session.get", ctx?.session?.get], ["session.prompt", ctx?.session?.prompt], ["session.hook", ctx?.session?.hook], ["event.subscribe", ctx?.event?.subscribe], ["command.transform", ctx?.command?.transform]]) {
42
42
  if (typeof fn !== "function") throw new Error(`Native OpenCode Loop requires ${label}; use OpenCode 2.0.18 or newer.`)
43
43
  }
44
- const directory = String(ctx.location?.directory || ctx.options?.directory || "").trim()
44
+ const directory = String(ctx.location?.directory || "").trim()
45
45
  if (!directory) throw new Error("Native OpenCode Loop requires a project directory")
46
46
  const ownsSession = createNativeSessionLocationGuard({
47
47
  directory, workspaceID: ctx.location?.workspaceID,
@@ -61,11 +61,13 @@ export const OpenCodeLoopNativePlugin = Object.freeze({
61
61
  prompt,
62
62
  command: typeof ctx.session.command === "function" ? (request) => ctx.session.command(request) : undefined,
63
63
  wait: typeof ctx.session.wait === "function" ? (request) => ctx.session.wait(request) : undefined,
64
- compact: typeof ctx.session.compact === "function" ? (request) => ctx.session.compact({ ...request, delivery: "queue" }) : undefined,
65
- shell: typeof ctx.session.shell === "function" ? (request) => ctx.session.shell(request) : (request) => shellHost.dispatch(request),
66
- // cancel() returns void. The durable inbox.cancelled event, not this
67
- // response alone, proves that an undelivered input can be refunded.
68
- cancel: typeof ctx.session.inbox?.cancel === "function" ? async (request) => { await ctx.session.inbox.cancel(request); return false } : undefined,
64
+ // OpenCode 2 exposes ctx.shell as a hook domain, not an execution method,
65
+ // and SessionDomain has no public compact/inbox-cancel action. Keep those
66
+ // undocumented capabilities out of the V2 runtime instead of probing
67
+ // private host fields that may disappear between releases.
68
+ compact: undefined,
69
+ shell: (request) => shellHost.dispatch(request),
70
+ cancel: undefined,
69
71
  onError: (error) => { void appendLoopLog(directory, "v2-native-error", { message: String(error?.message || error) }).catch(() => {}) },
70
72
  })
71
73
  const bridge = createOpenCode2EventBridge({ directory, allowInboxCommands: false, onEvent: async (event) => {
@@ -166,7 +166,7 @@ export function createNativeLoopRuntime(options = {}) {
166
166
  else if (kind === "shell") request = { sessionID: scope.sessionID, id: id(), command: String(job.action).replace(/^[!$]\s*/, ""), timeoutMs: job.timeoutMs }
167
167
  else {
168
168
  const [name, text] = splitFirst(String(job.action).replace(/^\/+/, ""))
169
- request = { sessionID: scope.sessionID, name, text: text || "", delivery: "queue" }
169
+ request = { sessionID: scope.sessionID, command: name, arguments: text || "", delivery: "queue" }
170
170
  }
171
171
  if (!isCurrent()) return result({ reason: "foreground-or-compaction" })
172
172
  if (job.dryRun) {