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