Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -426,3 +426,5 @@ Three tools for launching, monitoring, and cancelling detached background jobs.
- **ADL is an append-log, not a document row.** Read it with `goop_adl({ action: "read" })`. `goop_read_db({ doc_type: "adl" })` returns "No adl document found" — the ADL is stored as structured events, not a full document.

- **`goop_write_wave` accepts `verifications[]` and `traceability[]` in two forms, and the distinction matters.** With `task_updates[]` (the common case), supply them as top-level fields — they are processed atomically alongside task updates. With `items[]`, supply them **per-item** — each `items[]` entry can carry its own `verifications[]` and `traceability[]`. A traceability row omitting `wave_number` inherits the enclosing item's wave; an explicit value overrides. A verification omitting `wave_id` defaults to the enclosing item's resolved wave row; an explicit id wins. Everything is written in one transaction — any failure rolls back rows *and* events, so no orphan events survive. Supplying top-level `verifications`/`traceability` **alongside** `items[]` is rejected deliberately, because those payloads would otherwise be silently dropped.

- **Compaction hook replaces `output.prompt`, does not append to `output.context`.** The `experimental.session.compacting` hook (V1-only) overwrites `output.prompt` with a bounded continuation prompt from the shared formatter (`src/shared/continuation-prompt.ts`). `output.prompt` is last-writer-wins — earlier prompt content is not preserved or merged. `output.context` is never touched by the hook; if the host does not read `output.context` after compaction, context entries from other hooks are silently discarded. The hook stands down without mutating either field when no valid workflow can be resolved.
4 changes: 3 additions & 1 deletion packages/opencode-plugin/references/core-protocol.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@ When `goop_compact` queues a compaction, it captures a `CompactionHandoffSnapsho
- The `next_step` string provided by the caller.
- A `capturedAtMs` timestamp.

This snapshot is stored in the in-process `compactionHandoff` map keyed by session ID. When the compaction survival hook fires (`experimental.session.compacting`), it reads the snapshot, reconciles the active workflow binding (rebinding to the snapshot's workflow if the live binding has drifted), and builds a survival block that is pushed into `output.context`. The snapshot is consumed once and deleted.
This snapshot is stored in the in-process `compactionHandoff` map keyed by session ID. When the compaction survival hook fires (`experimental.session.compacting`), it reads the snapshot, reconciles the active workflow binding (rebinding to the snapshot's workflow if the live binding has drifted), and **replaces `output.prompt`** with a bounded continuation prompt built by the shared formatter (`src/shared/continuation-prompt.ts`). The hook does not append to `output.context`; the snapshot is consumed once and deleted.

**`output.prompt` is last-writer-wins.** The compaction hook overwrites any prompt content the host or an earlier hook placed in `output.prompt`; earlier content is not preserved or merged. `output.context` is never modified by the hook — if the host does not read `output.context` after compaction, any context entries pushed by other hooks are silently discarded. The hook stands down without mutating either field when no valid workflow can be resolved.

### Pre-Flush Before Compaction

Expand Down
29 changes: 29 additions & 0 deletions packages/opencode-plugin/src/core/hooks-v2.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,35 @@ describe("registerHooksV2()", () => {
env.cleanup();
});

it("keeps experimental.session.compacting in the V2 skipped list and registers no compaction capability (AD8, NFR4)", async () => {
const ctx = createMockPluginContext();
contexts.push(ctx);
const registrations: Registrations = {
agentTransforms: 0,
catalogTransforms: 0,
agentReloads: 0,
catalogReloads: 0,
};
const runtimeCtx = createRuntimeContext(registrations);
const session = runtimeCtx.session;
const tool = runtimeCtx.tool;
if (!session || !tool) throw new Error("test setup: session and tool must be present");
const sessionHookSpy = spyOn(session, "hook");
const toolHookSpy = spyOn(tool, "hook");

await registerHooksV2(runtimeCtx, ctx);

// AD8/NFR4: experimental.session.compacting is V1-only. The V2 adapter
// must never register a compaction handler with either runtime capability.
const sessionEvents = sessionHookSpy.mock.calls.map((call) => call[0]);
expect(sessionEvents).not.toContain("experimental.session.compacting");
expect(sessionEvents).toEqual(["request"]);

const toolEvents = toolHookSpy.mock.calls.map((call) => call[0]);
expect(toolEvents).not.toContain("experimental.session.compacting");
expect(toolEvents).toEqual(expect.arrayContaining(["execute.before", "execute.after"]));
});

it("logs the V2 lazy-autopilot limitation without claiming a fallback", async () => {
const ctx = createMockPluginContext();
contexts.push(ctx);
Expand Down
18 changes: 18 additions & 0 deletions packages/opencode-plugin/src/core/tools-v2.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,24 @@ describe("registerToolsV2()", () => {
expect(registrations).toHaveLength(38);
});

it("omits goop_compact when client.session exists but summarize is not a function (NFR4)", async () => {
const ctx = createMockPluginContext();
contexts.push(ctx);
// The capability gate checks typeof client.session.summarize === "function".
// A session object without summarize must still be treated as incapable.
Object.defineProperty(ctx.sdk, "client", {
configurable: true,
value: { session: {} },
});
const registrations: V2ToolDefinition[] = [];

await registerToolsV2(createRuntimeContext(registrations), ctx);

const names = registrations.map((definition) => definition.name);
expect(names).not.toContain("goop_compact");
expect(names).toContain("goop_status");
});

it("converts goop_status arguments with Zod's native JSON Schema support", () => {
const ctx = createMockPluginContext();
contexts.push(ctx);
Expand Down
30 changes: 30 additions & 0 deletions packages/opencode-plugin/src/core/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,34 @@ export interface PendingLazyAutopilotNudge {
source: "prompt-async" | "system-transform";
}

/**
* A single task row projected into a compaction handoff snapshot.
*/
export interface CompactionHandoffTask {
readonly index: number;
readonly description: string;
readonly status: string;
readonly agent: string | undefined;
}

/**
* A single open blocker projected into a compaction handoff snapshot.
*/
export interface CompactionHandoffBlocker {
readonly id: number;
readonly severity: string;
readonly description: string;
}

/**
* Durable-in-memory workflow context captured when a compaction is queued.
* `nextStep` remains directly consumable by the compaction hook rather than
* requiring consumers to decode an opaque serialized payload.
*
* The optional fields (`currentWaveTitle` … `prUrl`) are populated from the
* GoopSpecDB at queue time when the current wave has a row. They are
* `undefined` when the DB is empty, the current wave is 0, or a DB accessor
* throws. The core fields are always present on a valid snapshot.
*/
export interface CompactionHandoffSnapshot {
readonly workflowId: string;
Expand All @@ -112,6 +136,12 @@ export interface CompactionHandoffSnapshot {
readonly branch: string | undefined;
readonly nextStep: string;
readonly capturedAtMs: number;
readonly currentWaveTitle?: string;
readonly currentWaveStatus?: string;
readonly tasks?: ReadonlyArray<CompactionHandoffTask>;
readonly openBlockers?: ReadonlyArray<CompactionHandoffBlocker>;
readonly prBranch?: string;
readonly prUrl?: string;
}

// ---------------------------------------------------------------------------
Expand Down
Loading
Loading