fixate-on 0.0.0-stage → 0.2.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/index.d.ts ADDED
@@ -0,0 +1,608 @@
1
+ /** Type declarations for fixate-on.
2
+ * They describe the options object a user passes in `opencode.json` under
3
+ * `plugin: [["fixate-on", {... }]]`, together with the shape of the exports
4
+ * this module offers. */
5
+ /** Verdict returned by a completion judge (built-in or custom). See
6
+ * {@link GoalsPluginOptions.judge} and {@link GoalsPluginOptions.childSessionJudge}. */
7
+ export interface JudgeVerdict {
8
+ /** `true` archives the goal as achieved; `false` rejects the completion. */
9
+ approved: boolean;
10
+ /** Reason for the verdict, shown in the goal's status when the completion is rejected. */
11
+ reason?: string;
12
+ } // JudgeVerdict
13
+ /** A timestamped lifecycle event kept with a goal, whether it is active or archived. */
14
+ export interface GoalLifecycleEvent {
15
+ type: string;
16
+ detail: string;
17
+ timestamp: number;
18
+ } // GoalLifecycleEvent
19
+ /** A size-limited progress checkpoint kept with a goal. */
20
+ export interface GoalProgressNote {
21
+ summary: string;
22
+ timestamp: number;
23
+ } // GoalProgressNote
24
+ /** Token and cost usage for the current run of a goal, normalised across hosts. */
25
+ export interface UsageSnapshot {
26
+ input: number;
27
+ output: number;
28
+ reasoning: number;
29
+ cacheRead: number;
30
+ cacheWrite: number;
31
+ cost: number;
32
+ costKnown: boolean;
33
+ } // UsageSnapshot
34
+ // TUI transport types
35
+ //
36
+ // Published because {@link GoalsPluginOptions.tuiTransport} takes one, and because
37
+ // a structural approximation of it does not work: a function parameter is
38
+ // contravariant, so a hand-written approximation that omits a required field of
39
+ // GoalTuiEvent makes the only correct implementation fail to compile. These
40
+ // mirror src/tui-state.ts, which imports them from src/state-machine.ts.
41
+ /** Goal lifecycle status, as the TUI sees it. */
42
+ export type GoalStatus =
43
+ 'active' | 'paused' | 'blocked' | 'budgetLimited' | 'finalizing' | 'complete';
44
+ /** What checked a claim, as an identifier. */
45
+ export type ClaimCheckPath = 'judge' | 'none';
46
+ export type ClaimCheckVerdict =
47
+ | 'COMPLETE'
48
+ | 'WORKING'
49
+ | 'BLOCKED'
50
+ | 'NEEDS_INPUT'
51
+ | 'CANCELLED'
52
+ | 'JUDGE_APPROVED'
53
+ | 'JUDGE_REJECTED'
54
+ | 'JUDGE_FAILURE'
55
+ | 'VERIFIER_FAILURE'
56
+ | 'NONE';
57
+ export type ClaimOutcomeStatus =
58
+ | 'verified-complete'
59
+ | 'claim-refuted'
60
+ | 'unverifiable-claim'
61
+ | 'blocked-acknowledged';
62
+ export type ClaimActor = 'agent' | 'human' | 'slash-command';
63
+ export interface ClaimCheck {
64
+ path: ClaimCheckPath;
65
+ target?: string;
66
+ verdict: ClaimCheckVerdict;
67
+ evidence?: string[];
68
+ timestamp: number;
69
+ } // ClaimCheck
70
+ export interface ClaimOutcome {
71
+ status: ClaimOutcomeStatus;
72
+ detail: string;
73
+ timestamp: number;
74
+ } // ClaimOutcome
75
+ export interface ClaimRecord {
76
+ claimId: string;
77
+ timestamp: number;
78
+ actor: ClaimActor;
79
+ claimedStatus: 'complete' | 'blocked';
80
+ claimText: string;
81
+ check: ClaimCheck;
82
+ outcome: ClaimOutcome;
83
+ } // ClaimRecord
84
+ export interface GoalProposal {
85
+ proposalId: string;
86
+ proposedAt: number;
87
+ objective?: string;
88
+ successCriteria?: string;
89
+ constraints?: string;
90
+ artifactPointers?: string[];
91
+ reason: string;
92
+ } // GoalProposal
93
+ export type TransitionSource =
94
+ | 'create_goal'
95
+ | 'update_goal'
96
+ | 'propose_goal_change'
97
+ | 'list_goals'
98
+ | 'focus_goal'
99
+ | 'slash-command'
100
+ | 'idle-handler'
101
+ | 'chat-message'
102
+ | 'system-transform'
103
+ | 'recovery'
104
+ | 'retraction'
105
+ | 'completion-gate'
106
+ | 'sequence-replace'
107
+ | 'create_goal-rollback'
108
+ /** A re-arm driven by the POLLER's synthetic idle rather than by one the host
109
+ * delivered — the two write different ledger entries so the record can say which
110
+ * one brought a goal back. */
111
+ | 'poll-idle';
112
+ export interface CommitTransition {
113
+ source: TransitionSource;
114
+ from: GoalStatus;
115
+ to: GoalStatus;
116
+ detail: string;
117
+ } // CommitTransition
118
+ /** A frozen, serializable projection of goal state for the TUI layer. This is
119
+ * the data contract between the server plugin and the TUI companion. */
120
+ export interface GoalTuiSnapshot {
121
+ readonly goalId: string;
122
+ readonly sessionID: string;
123
+ readonly condition: string;
124
+ readonly artifactPointers?: ReadonlyArray<string>;
125
+ readonly pendingProposal?: Readonly<GoalProposal> | null;
126
+ readonly claims?: ReadonlyArray<Readonly<ClaimRecord>>;
127
+ readonly lastClaim?: Readonly<ClaimRecord> | null;
128
+ readonly status: GoalStatus;
129
+ readonly revision: number;
130
+ readonly turnCount: number;
131
+ readonly totalTokens: number;
132
+ readonly maxTokens: number;
133
+ readonly maxTurns: number;
134
+ readonly tokenBudget: number | null;
135
+ readonly usage: Readonly<UsageSnapshot>;
136
+ readonly stopReason: string;
137
+ readonly blockedReason: string;
138
+ /** When the elapsed-time clock was paused; `0` while that clock runs.
139
+ * Used to exclude paused intervals from elapsed run time. Ordinary human
140
+ * messages leave the goal active and do not pause that clock. */
141
+ readonly pausedAt: number;
142
+ /** When the current stop was applied; `0` when the goal is not stopped.
143
+ * Renewed on each stop, unlike `pausedAt`, which is set once per paused
144
+ * interval. Retained for status snapshots and persisted-state compatibility. */
145
+ readonly stoppedAt: number;
146
+ readonly createdAt: number;
147
+ readonly updatedAt: number;
148
+ readonly finishedAt: number | null;
149
+ readonly lastCheckpoint: Readonly<{
150
+ summary: string;
151
+ timestamp: number;
152
+ }> | null;
153
+ readonly history: ReadonlyArray<
154
+ Readonly<{type: string; detail: string; timestamp: number}>
155
+ >;
156
+ /** Where this snapshot came from. `"live"` = a real event for the goal's own
157
+ * session. `"disk"` = rehydrated from persisted state, whose goals may belong
158
+ * to pre-restart session IDs, so a dashboard may surface these
159
+ * workspace-wide when the current session has none. */
160
+ readonly origin?: 'live' | 'disk';
161
+ } // GoalTuiSnapshot
162
+ export type GoalTuiEventKind = 'create' | 'transition' | 'usage' | 'remove';
163
+ /** The event payload published by the server broadcaster. */
164
+ export interface GoalTuiEvent {
165
+ readonly kind: GoalTuiEventKind;
166
+ readonly sessionID: string;
167
+ readonly timestamp: number;
168
+ /** Present for create/transition/usage events. Absent for remove. */
169
+ readonly snapshot?: GoalTuiSnapshot;
170
+ /** Present only for transition events. */
171
+ readonly transition?: Readonly<CommitTransition>;
172
+ /** The status the goal held immediately BEFORE this transition, when the
173
+ * producer knows it. Present so a receiver can tell an ENTRY into a status
174
+ * from churn within one: a running goal emits a transition on every
175
+ * continuation, so the status alone cannot distinguish "it started working"
176
+ * from "it is still working". Absent means "the producer did not say" — a
177
+ * receiver may still rely on a snapshot that states its own outcome
178
+ * (`complete`, `blocked`, or a limit-class stop), but must not infer a
179
+ * boundary from an `active` snapshot alone. */
180
+ readonly previousStatus?: GoalStatus;
181
+ /** Present only for remove events. */
182
+ readonly goalId?: string;
183
+ } // GoalTuiEvent
184
+ /** A host-supplied channel for goal lifecycle events. Errors thrown here are
185
+ * swallowed: a TUI disconnect must not break the state machine. */
186
+ export type GoalTuiPublishFn = (
187
+ sessionID: string,
188
+ event: GoalTuiEvent,
189
+ ) => Promise<void> | void;
190
+ /** Read-only goal snapshot passed to custom completion judges. */
191
+ export interface GoalJudgeSnapshot {
192
+ goalId: string;
193
+ runId: string;
194
+ condition: string;
195
+ successCriteria: string;
196
+ constraints: string;
197
+ mode: 'normal' | 'ordered';
198
+ sessionID: string;
199
+ tokenBudget: number | null;
200
+ maxTokens: number;
201
+ maxTurns: number;
202
+ maxDurationMs: number;
203
+ turnCount: number;
204
+ totalTokens: number;
205
+ usage: Readonly<UsageSnapshot>;
206
+ createdAt: number;
207
+ startedAt: number;
208
+ pausedAt: number;
209
+ status: string;
210
+ stopReason: string;
211
+ blockedReason: string;
212
+ lastStatus: string;
213
+ history: readonly Readonly<GoalLifecycleEvent>[];
214
+ checkpoints: readonly Readonly<GoalProgressNote>[];
215
+ lastCheckpoint: Readonly<GoalProgressNote> | null;
216
+ } // GoalJudgeSnapshot
217
+ /** Arguments passed to a custom {@link GoalsPluginOptions.judge} function. */
218
+ export interface JudgeContext {
219
+ /** The goal under judgement: its objective, budget use and checkpoints. */
220
+ goal: Readonly<GoalJudgeSnapshot>;
221
+ /** The OpenCode session that owns the goal. */
222
+ sessionID: string;
223
+ /** The assistant's most recent response, which carries the completion claim. */
224
+ latestText: string;
225
+ } // JudgeContext
226
+ /** Options for the built-in child-session judge, used when `childSessionJudge` is `true`. */
227
+ export interface JudgeOptions {
228
+ /** How long, in milliseconds, the built-in judge waits for a verdict from its
229
+ * child OpenCode session. Verification of a substantial goal can legitimately
230
+ * take minutes, so the default is a generous 30 minutes. Set `0` to disable
231
+ * the deadline entirely (no timer, no child abort; host/provider timeouts
232
+ * still apply). A positive value bounds a hung host operation: on timeout the
233
+ * child is aborted and deleted and the failure is recorded as an attestation
234
+ * fault — retried with backoff under {@link failurePolicy}, never treated as
235
+ * a verdict on the claim. Values above 2147483647 are rejected (they would
236
+ * overflow the runtime timer into an instant abort).
237
+ * @default 1800000 */
238
+ timeoutMs?: number;
239
+ /** The result used when the child-session API is unavailable, returns a
240
+ * malformed response, throws, or times out. A rejected claim or an invalid
241
+ * verdict is always rejected. `"approve"` exists for compatibility only.
242
+ * @default "reject" */
243
+ failurePolicy?: 'reject' | 'approve';
244
+ } // JudgeOptions
245
+ /** Options for fixate-on. Every field is optional; an unset field takes the
246
+ * built-in default. The budget and behaviour fields set the limits for every
247
+ * goal in a session, and most of them can be overridden for one goal with a
248
+ * `/goal` flag (for example `--max-turns`, `--success` or `--mode`). */
249
+ export interface GoalsPluginOptions {
250
+ /** Per-goal defaults for every brake and threshold below, applied to every
251
+ * goal the plugin creates. A `/goal` flag overrides the value for that goal
252
+ * only; this object changes the floor every goal starts from.
253
+ *
254
+ * Omit it to use the documented defaults on each option below. */
255
+ defaultGoalOptions?: Partial<{
256
+ maxTokens: number;
257
+ maxTurns: number;
258
+ maxDurationMs: number;
259
+ minDelayMs: number;
260
+ maxPromptFailures: number;
261
+ maxRecentMessages: number;
262
+ noProgressTokenThreshold: number;
263
+ noProgressTurnsBeforePause: number;
264
+ noToolCallTurnsBeforePause: number;
265
+ budgetWrapupRatio: number;
266
+ maxRecoveryTurns: number;
267
+ maxUnchangedResults: number;
268
+ maxBlockedTurns: number;
269
+ languageTriage: boolean;
270
+ }>;
271
+ /** Path to a loop-policy file. When set, the policy document at this path is
272
+ * read on each continuation and its directives override the plugin's own
273
+ * steering for that goal. Omit it to use the built-in policy. */
274
+ loopPolicyPath?: string;
275
+ /** The OpenCode session SDK argument shape. The plugin input supplies the
276
+ * generated client, which uses the `"legacy"` shape. Set `"flat"` when the
277
+ * plugin is embedded with the v2 SDK. The adapter records the shape that worked
278
+ * for each operation.
279
+ * @default "legacy" */
280
+ sdkShape?: 'legacy' | 'flat';
281
+ /** The maximum number of auto-continue turns sent for a goal before the goal is
282
+ * stopped for exceeding a limit. Set it for one goal with `--max-turns`.
283
+ *
284
+ * **Disabled by default (`0` = no turn brake).** A turn count cannot tell a
285
+ * productive goal from a stuck one, and real work would then fail unless the
286
+ * user remembered `--max-turns`. The goal is still bounded by the stall brake
287
+ * and the cumulative context brake, which fire on observed signals.
288
+ * @default 0 */
289
+ maxTurns?: number;
290
+ /** The maximum time, in milliseconds, a goal may go without progress before it is
291
+ * stopped for exceeding a limit. Set it for one goal with `--max-duration-ms` or
292
+ * `--max-minutes`.
293
+ *
294
+ * This is a stall brake: the clock measures time since the last evidence of
295
+ * progress, not total run time. Progress is recorded on a new assistant turn or
296
+ * an increase in output tokens. An outstanding tool call does not count as
297
+ * progress, so a hung tool call cannot hold the goal open.
298
+ * @default 1800000 */
299
+ maxDurationMs?: number;
300
+ /** Optional cumulative context-token ceiling. By default, no context-token
301
+ * stop or wrap-up threshold is applied. Set a positive value for one goal
302
+ * with `--max-tokens`, or with the `--budget` shorthand, which takes a `k` or
303
+ * `m` suffix such as `100k` or `1.5m`; zero disables the ceiling.
304
+ *
305
+ * The count is cumulative over the whole goal (`totalTokens + compactionBaselineTokens`),
306
+ * so compaction does not reduce it.
307
+ * @default 0 */
308
+ maxTokens?: number;
309
+ /** The minimum delay, in milliseconds, between two auto-continue prompts. Set it
310
+ * for one goal with `--cooldown-ms`.
311
+ * @default 1500 */
312
+ minDelayMs?: number;
313
+ /** The number of recent session messages scanned for the latest assistant turn
314
+ * before auto-continuing. A higher value keeps long, tool-heavy sessions from
315
+ * losing the most recent response.
316
+ * @default 50 */
317
+ maxRecentMessages?: number;
318
+ /** The output-token floor below which a turn counts as low-output for no-progress
319
+ * detection. Set it for one goal with `--no-progress-threshold`.
320
+ * @default 50 */
321
+ noProgressTokenThreshold?: number;
322
+ /** The number of consecutive stalled low-output turns allowed before the goal is
323
+ * paused. The goal is not paused on the first one. Set it for one goal with
324
+ * `--no-progress-turns`.
325
+ * @default 3 */
326
+ noProgressTurnsBeforePause?: number;
327
+ /** The number of consecutive tool-free continuation turns ("talk only" turns)
328
+ * allowed before the goal is paused. This complements the no-progress check by
329
+ * catching loops that produce output without using tools. Set it for one goal
330
+ * with `--no-tool-turns`. Direct replies to human input restart this streak
331
+ * without resetting accumulated turns or token usage. Set the plugin option
332
+ * to `0` to disable the check.
333
+ * @default 3 */
334
+ noToolCallTurnsBeforePause?: number;
335
+ /** The fraction, strictly between 0 and 1, of a budget (turns, duration or
336
+ * tokens) at which the plugin sends one "wrap up" prompt. The prompt asks the
337
+ * model to finish before the hard limit is reached.
338
+ * @default 0.8 */
339
+ budgetWrapupRatio?: number;
340
+ /** The number of remaining auto-continue turns at which a limit warning is added
341
+ * to the continuation prompt.
342
+ *
343
+ * The warning goes in the prompt, not in `/goal status`, so the model receives it
344
+ * while it can still act on it. The three warning options use the same mechanism
345
+ * with different measures. None of them appears on a status surface.
346
+ * @default 3 */
347
+ warnTurnsRemaining?: number;
348
+ /** The remaining duration, in milliseconds, at which a limit warning is added to
349
+ * the continuation prompt. See {@link GoalsPluginOptions.warnTurnsRemaining}.
350
+ *
351
+ * The clock starts at the last evidence of progress, or at the goal's start if
352
+ * there is none. The duration brake uses the same clock, so the warning and the
353
+ * brake agree.
354
+ * @default 60000 */
355
+ warnDurationMsRemaining?: number;
356
+ /** The remaining context tokens at which a limit warning is added to the
357
+ * continuation prompt. See {@link GoalsPluginOptions.warnTurnsRemaining}.
358
+ * @default 25000 */
359
+ warnTokensRemaining?: number;
360
+ /** How many consecutive prompt failures the goal absorbs before it is
361
+ * stopped: a transport error while sending the auto-continue prompt, or a
362
+ * reply that keeps missing the evidence or blocker the format requires.
363
+ * @default 3 */
364
+ maxPromptFailures?: number;
365
+ /** Whether active and background goals, and recent results, are written to disk
366
+ * so they survive a restart. A goal recovered on restart loads paused. Set this
367
+ * to `false` to keep everything in memory. That also disables the lifecycle
368
+ * ledger.
369
+ * @default true */
370
+ persistState?: boolean;
371
+ /** The directory that holds persisted goal state when `persistState` is on. Each
372
+ * session has its own file at `sessions/<sessionID>/state.json`, so two OpenCode
373
+ * processes can share one worktree. This overrides the project-local default and
374
+ * the `FIXATE_ON_STATE_ROOT` environment variable.
375
+ * @default '<cwd>/.opencode/goals' */
376
+ stateRoot?: string;
377
+ /** The workspace directory used to resolve `stateRoot` and other relative paths.
378
+ * On a v2 host the plugin reads the workspace from `ctx.location.directory` when
379
+ * this option is absent; `process.cwd()` is the last fallback, which is correct
380
+ * for v1 hosts and for installed v2 binaries that set their own working
381
+ * directory. Pass the workspace path here only when the host's `process.cwd`
382
+ * differs from the project, for example a from-source checkout that changes
383
+ * directory before it starts the CLI.
384
+ * @default ctx.location.directory on v2, otherwise process.cwd */
385
+ workspaceDirectory?: string;
386
+ /** The maximum size, in bytes, of one lifecycle-ledger generation. Each session has
387
+ * its own ledger at `<sessions>/<sessionID>/state.json.ledger.jsonl`.
388
+ * @default 2097152 */
389
+ ledgerMaxBytes?: number;
390
+ /** The number of rotated lifecycle-ledger generations kept, from 0 to 10. @default 3 */
391
+ ledgerRetentionFiles?: number;
392
+ /** How long, in milliseconds, a finished goal's summary stays available through
393
+ * `/goal status` after the goal leaves active memory.
394
+ * @default 604800000 */
395
+ resultRetentionMs?: number;
396
+ /** The maximum number of finished-goal summaries kept in memory. The oldest are
397
+ * evicted first.
398
+ * @default 10 */
399
+ maxStoredResults?: number;
400
+ /** The slash command the plugin handles. Set it to, for example, `"objective"` to
401
+ * use `/objective` instead of `/goal`. A leading slash is accepted and removed.
402
+ * The same name must also be registered in your OpenCode `command` config.
403
+ * @default "goal" */
404
+ commandName?: string;
405
+ /** The delay, in milliseconds, before the kickoff probe runs after a command that
406
+ * creates a goal. The probe sends the first continuation prompt only when the host
407
+ * started no agent turn for the command. On stock v1, `/goal` runs without an
408
+ * agent, so nothing else drives the new goal and no `session.idle` arrives.
409
+ * @default 2500 */
410
+ kickoffDelayMs?: number;
411
+ /** Whether the synthetic-idle fallback poller runs. On hosts that send no idle
412
+ * events, such as stock v1, the poller is the only way to wake the loop, so it is
413
+ * enabled by default. A host that sends idle events correctly, or a test that
414
+ * drives events directly, should set this to `false`.
415
+ * @default true */
416
+ idlePoller?: boolean;
417
+ /** The poll interval of the synthetic-idle fallback, in milliseconds.
418
+ * @default 5000 */
419
+ idlePollerIntervalMs?: number;
420
+ /** The quiet window, in milliseconds, that must pass before a synthetic idle can
421
+ * fire. It stops the fallback from firing while the host is still working.
422
+ * @default 10000 */
423
+ idleQuietMs?: number;
424
+ /** The grace period, in milliseconds, after a real idle event during which the
425
+ * synthetic poller stays silent. It stops the fallback from driving a turn the
426
+ * host has already ended.
427
+ * @default 30000 */
428
+ idleGraceMs?: number;
429
+ /** A custom transport for goal lifecycle events to the TUI. The v2 adapter uses
430
+ * its own buffer, which passes events through tool `Result.metadata` and never
431
+ * shows them to the user.
432
+ *
433
+ * Supply a transport to bridge a host with a different event surface. If it is
434
+ * unset, the companion takes its state from the persisted state file instead.
435
+ * No host-visible channel is used, because the v1 `client.tui.publish` endpoint
436
+ * shows every envelope as a toast. */
437
+ tuiTransport?: GoalTuiPublishFn;
438
+ /** Whether the plugin owns the slash command: through the
439
+ * `command.execute.before` hook on 1.x hosts, and through the v2 Context's
440
+ * `command.transform` (registering its own `goal` command, overriding the
441
+ * built-in `opencode.goal`) on 2.x hosts. Set it to `false` if you only want
442
+ * auto-continue and persistence, driven through {@link registerTools}, and do
443
+ * not want the plugin to own a slash command.
444
+ * @default true */
445
+ registerCommand?: boolean;
446
+ /** Whether the plugin registers the agent-facing goal tools
447
+ * (canonical `get_goal`, `create_goal`, `update_goal`,
448
+ * `list_goals`, `focus_goal`, `propose_goal_change`) and, on an
449
+ * OpenCode v2 host, the `goal-command` bridge that makes `/goal`
450
+ * reach goal state at all. The bridge is registered inside this same
451
+ * block, so `false` removes it too.
452
+ *
453
+ * The tools define their parameters with `zod` when it is installed. Without it,
454
+ * each tool registers with a permissive schema. The peer dependency on the host
455
+ * is a version floor, not an import.
456
+ * @default true */
457
+ registerTools?: boolean;
458
+ /** Register the `goal` and `goal-verify` agents: through OpenCode's config hook
459
+ * on 1.x hosts, and through the v2 Context's `agent.transform` on 2.x hosts
460
+ * (which never call the 1.x config hook). An existing agent with either name
461
+ * is left unchanged.
462
+ * @default true */
463
+ registerAgents?: boolean;
464
+ /** The name of the goal agent the plugin registers. @default "goal" */
465
+ goalAgentName?: string;
466
+ /** The name of the read-only verifier subagent the plugin registers. @default "goal-verify" */
467
+ verifierAgentName?: string;
468
+ /** Enables the built-in child-session completion judge. It is on unless this is
469
+ * `false`. When it is on, a completion claim is checked by the judge before the
470
+ * goal can become terminal. On WORKING the goal enters bounded recovery. On a
471
+ * judge failure, or when recovery is exhausted, the goal escalates: it is
472
+ * paused, and COMPLETE is never fabricated. Set this to `false` to turn the
473
+ * child-session judge off; the gate then abstains on every claim (recorded as
474
+ * an unverifiable claim, never as complete). Tune the judge with
475
+ * {@link judgeOptions}.
476
+ *
477
+ * All execution is agent-driven: the plugin never runs a program to check a
478
+ * claim — no explicit verifier command, no Makefile target, no auto-detected
479
+ * test command. The agent runs its own checks (tests, builds, diffs) with its
480
+ * own tools and cites the evidence; the judge attests the claim. The judge's
481
+ * verdict object is shaped by `completion-verdict.schema.json`, which ships
482
+ * with the package.
483
+ *
484
+ * @default true */
485
+ childSessionJudge?: boolean;
486
+ /** The maximum number of bounded recovery turns before the goal escalates. It is
487
+ * paused with the stop reason "recovery exhausted". A recovery turn is a forced
488
+ * continuation after the verifier reports WORKING.
489
+ * @default 12 */
490
+ maxRecoveryTurns?: number;
491
+ /** The maximum number of consecutive identical verifier results (same candidate
492
+ * and same fingerprint) before the goal escalates. It catches loops in which the
493
+ * agent makes no progress. A change of candidate resets this counter, but it does
494
+ * not reset the total recovery budget.
495
+ * @default 3 */
496
+ maxUnchangedResults?: number;
497
+ /** The number of consecutive `update_goal(blocked)` calls needed before the goal
498
+ * may move to `blocked`. This is separate from `maxUnchangedResults`, which bounds
499
+ * completion recovery, so raising one budget does not raise the other. The streak
500
+ * carries across the idle boundary while the agent keeps asserting blocked. It is
501
+ * reset by a resume or by a turn that is not blocked.
502
+ * @default 3 */
503
+ maxBlockedTurns?: number;
504
+ /** Enable advisory phrase triage for premature-exit language and warm-cache
505
+ * natural-stop triage on OpenCode 2.x. When true, the agent's final message
506
+ * is scanned for unfinished-work, deferral, permission-seeking, and
507
+ * session-length signals (adding the reason to recovery prompts without
508
+ * overriding a verifier `COMPLETE`), and on 2.x idle natural stops can route
509
+ * completion or blocker claims to the configured verifier.
510
+ * @default true */
511
+ languageTriage?: boolean;
512
+ /** Supply a custom completion judge instead of the built-in
513
+ * child-session one. Takes precedence over `childSessionJudge: true`.
514
+ * A verdict of `{ approved: false }` pauses the goal — the stop reason is
515
+ * `"judge rejected"` — rather than archiving it. A thrown error counts
516
+ * as a rejection, so the gate fails closed.
517
+ *
518
+ * The judge is the only verifier the gate consults: the plugin never runs a
519
+ * command to check a claim. */
520
+ judge?: (context: JudgeContext) => Promise<JudgeVerdict>;
521
+ /** Tuning options for the built-in child-session judge. Ignored when
522
+ * a custom {@link judge} is supplied. */
523
+ judgeOptions?: JudgeOptions;
524
+ /** Whether the plugin announces its decisions about the goal instead of
525
+ * running silently: a verdict, an attestation fault, a pause, a recovery
526
+ * turn, or a goal settled without an attestation.
527
+ * @default true */
528
+ goalMessages?: boolean;
529
+ /** Custom sink for those announcements. Defaults to routing through
530
+ * OpenCode's structured log (`client.app.log`) and the TUI toast, whenever
531
+ * those host APIs are available. Provide this to route them elsewhere. */
532
+ goalMessenger?: (sessionID: string, text: string) => Promise<void> | void;
533
+ } // GoalsPluginOptions
534
+ /** OpenCode plugin hook map returned by the plugin's `server` factory.
535
+ * It matches OpenCode's plugin hook contract, and its input and output stay
536
+ * loose (`unknown`) because OpenCode itself defines those payload shapes,
537
+ * not this package. A member is optional only when the plugin
538
+ * genuinely may omit it — every other hook is registered on every
539
+ * construction. */
540
+ export interface GoalsPluginHooks {
541
+ /** Registers the native goal and verifier agents, leaving any agent of the
542
+ * same name that already exists untouched. */
543
+ config: (config: unknown) => Promise<void>;
544
+ /** Captures the run's execution context (agent, model, working directory) at
545
+ * the moment the directory becomes known, so the handback diff reports only
546
+ * what this goal changed. */
547
+ 'chat.params': (input: unknown) => Promise<void>;
548
+ /** Cancels pending plugin work when a human message arrives. Ordinary input
549
+ * leaves goals active while the host answers; an explicit stop pauses them
550
+ * and requests interruption of an in-flight plugin prompt. */
551
+ 'chat.message': (input: unknown, output: unknown) => Promise<void>;
552
+ /** Omitted entirely when {@link GoalsPluginOptions.registerCommand} is `false`. */
553
+ 'command.execute.before'?: (input: unknown, output: unknown) => Promise<void>;
554
+ event: (input: unknown) => Promise<void>;
555
+ 'experimental.chat.system.transform': (
556
+ input: unknown,
557
+ output: unknown,
558
+ ) => Promise<void>;
559
+ 'experimental.compaction.autocontinue': (
560
+ input: unknown,
561
+ output: unknown,
562
+ ) => Promise<void>;
563
+ /** Carries the goal objective, status, budget usage, elapsed time and latest
564
+ * checkpoint into a compaction context, so a context compaction does not drop
565
+ * the goal thread mid-run. */
566
+ 'experimental.session.compacting': (
567
+ input: unknown,
568
+ output: unknown,
569
+ ) => Promise<void>;
570
+ /** Agent-facing tool definitions, present only when
571
+ * {@link GoalsPluginOptions.registerTools} is enabled (default) and `zod`
572
+ * resolves. On an OpenCode v2 host the `goal-command` bridge is registered
573
+ * inside the same block, so `registerTools: false` removes it too. */
574
+ tool?: Record<string, unknown>;
575
+ /** Cancels the pending continuation work and releases this plugin instance. */
576
+ dispose: () => Promise<void>;
577
+ } // GoalsPluginHooks
578
+ /** The plugin's `server` factory. OpenCode calls this with a client bound
579
+ * to the running session, and with the plugin options it resolved from
580
+ * `opencode.json`. */
581
+ export function GoalsPlugin(
582
+ /**
583
+ * The host context.
584
+ *
585
+ * `client` is optional because the runtime defaults the whole
586
+ * context: `GoalsPlugin` and `GoalsPlugin({})` are both valid
587
+ * and are what the tests drive, so a declaration that made it
588
+ * required would reject correct callers. `directory` is
589
+ * OpenCode's resolved project directory for this plugin instance.
590
+ */
591
+ context: {client?: unknown; directory?: string},
592
+ options?: GoalsPluginOptions,
593
+ ): Promise<GoalsPluginHooks>;
594
+ /** The default export. One object satisfies both host loaders.
595
+ *
596
+ * OpenCode 1.x reads `server` and calls it to obtain the plugin's hooks.
597
+ * OpenCode v2 reads `id` and calls `setup`, which wraps the v2 context and
598
+ * bridges each hook to the same runtime; its loader validates `default`
599
+ * against a schema that requires `effect` or `setup`, so a v2 host cannot
600
+ * load this package without it. */
601
+ declare const goalsPlugin: {
602
+ id: 'fixate-on';
603
+ server: typeof GoalsPlugin;
604
+ /** The OpenCode v2 entry point. See above. Returns the teardown the host
605
+ * calls to release the plugin instance. */
606
+ setup: (context: unknown) => Promise<() => Promise<void>>;
607
+ }; // goalsPlugin
608
+ export default goalsPlugin;