pi-continual-harness 0.20.0 → 0.22.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/README.md CHANGED
@@ -181,7 +181,7 @@ preset menu, or a declined final write; declining an individual feature only
181
181
  skips that feature (the accepted deltas still apply). The wizard never
182
182
  touches harness state, only the config file.
183
183
 
184
- Optional config at `~/.pi/agent/harness.json` (missing → defaults; malformed → defaults plus a once-per-session warning, so a typo can't silently reset your settings):
184
+ Optional config at `~/.pi/agent/harness.json` (missing → defaults; malformed → defaults plus a once-per-session warning, so a typo can't silently reset your settings). The **full key-by-key reference lives in [docs/CONFIG.md](docs/CONFIG.md)**; the shape:
185
185
 
186
186
  ```json
187
187
  {
@@ -191,10 +191,11 @@ Optional config at `~/.pi/agent/harness.json` (missing → defaults; malformed
191
191
  "proposer": "steering",
192
192
  "dedupe": { "threshold": 0.6, "merge": true },
193
193
  "injection": { "enabled": true, "maxTokens": 1500, "maxPerKind": 10, "charsPerToken": 4 },
194
+ "provenance": { "label": true, "priority": true },
194
195
  "remindRefine": { "enabled": true, "everyTurns": 25, "detailEvery": 4 },
195
196
  "autoRefine": { "enabled": false, "everyTurns": 100, "commit": false, "gate": false, "refineNoOpSkip": 3 },
196
197
  "outcomeImportance": { "enabled": false, "bump": 0.03 },
197
- "classifier": { "model": "typesafe/jev-latest" },
198
+ "classifier": { "model": "github-copilot/microsoft-decision-1", "auto": true },
198
199
  "virtualBinding": "virtual"
199
200
  }
200
201
  ```
@@ -206,125 +207,25 @@ schemas (the same pattern pi ≥ 1.2 ships for its own `settings.json` /
206
207
  `models.json`). The loader ignores unknown keys — `$schema` included — and a
207
208
  `/harness setup` rewrite preserves it.
208
209
 
209
- - **`autoImport`** — opt-in **durable sync** (off by default). `true` bundles
210
- both directions: on `session_start` the durable layers are imported
211
- automatically (global file always + the current project's file, with the same
212
- loss-free merge as `/harness import` — an import that changes nothing stays
213
- silent), and on `turn_end` the layers are re-exported whenever the live store
214
- changed since the last export. This is what makes `/refine` output survive
215
- into **new** sessions without manual export/import ceremony. Both halves are
216
- visible (one notify line) and use the same persisted `harness-state` entries
217
- as every other mutation (`/tree` rollback covers them). Enabling it
218
- mid-session (e.g. via `/harness setup`) is safe: the first `turn_end`
219
- imports the layers *before* any export, so a late enable can never
220
- overwrite the durable files with a never-imported store.
221
- - **`importRemind`** — **awareness reminders** for that sync (effective only
222
- when `autoImport` is on; default `{ "enabled": true, "everyTurns": 25 }`).
223
- The session-start import doesn't just count — it **lists what arrived**
224
- (item id, kind, first words of content), and every `everyTurns` turns a
225
- one-line reminder re-surfaces the imported items so silently-injected
226
- instructions never go unnoticed (full list via the agent's `harness_list`
227
- tool — `/harness status` shows only counts). Bounded: at most 3 reminders
228
- per imported batch, then quiet until the next session; aborted/error turns
229
- are inert (completed-turn cadence). Kill-switch:
230
- `{ "importRemind": { "enabled": false } }` (the start-of-session listing
231
- still fires).
232
- - **`injection`** — the selection policy for WHAT gets surfaced in the system
233
- prompt each turn (see [Injection selection](#injection-selection-on-by-default)).
234
- ON by default: items are importance-ordered, capped at `maxPerKind` (default
235
- 10) per kind and `maxTokens` (default 1500) total. Set `enabled: false` to
236
- restore the legacy "inject all items, in store order" behaviour.
237
- - **`proposer`** — which delta proposer `/refine` and auto-refine use. Defaults
238
- to `steering` (the agent reasons via a steering message). `dedupe` applies a
239
- rule-based merge directly. See [Proposers](#proposers).
240
- - **`dedupe`** — the rule-based dedupe proposer's policy. `threshold` (default
241
- `0.6`, valid `(0,1]`) is the token-overlap level at which two items sharing
242
- the key fields (kind, owner model, durable layer) count as duplicates;
243
- `merge` (default `true`) **merges** each duplicate into its keeper — the
244
- keeper keeps its content verbatim, its `evidence` becomes the line-wise union
245
- of both, applied as one audited `update` + `delete` pair — while `false`
246
- restores the pre-0.10 delete-only behavior. `/refine --proposer dedupe
247
- --threshold 0.75` overrides the threshold for one run. A fourth key,
248
- `similarity`, is API-only (functions cannot come from `harness.json`):
249
- companion packages inject a richer comparator whose return may **abstain**
250
- per pair (`{ score, abstain }` — see [`SimilarityResult`](#proposers)); an
251
- abstaining pair is always kept, never merged or deleted.
252
- - **`remindRefine`** — the `turn_end` **activation nudge**, ON by default
253
- (informational only; it never mutates state). Every `everyTurns` completed
254
- turns (default 25) a one-line reminder suggests `/refine`, garnished with
255
- live data from the store (e.g. "12 active item(s), 4 never cited since
256
- creation"; an empty store gets first-run guidance instead). Every
257
- `detailEvery`-th reminder (default 4: at the default cadence, roughly
258
- every 100 turns) escalates to a rotating educational guide: how the loop
259
- works (with alternate descriptions so it never reads as boilerplate), the
260
- `/refine` workflow, `keep`/`drop`/`prune --decay` hygiene, `push-mem`,
261
- `split`, `export-corpus`, and a recommended starter config. Fresh installs
262
- used to be silent; that was the bug, not the feature. Aborted/error turns
263
- are skipped, so `everyTurns` counts completed turns of work. Silence it
264
- with `{ "remindRefine": { "enabled": false } }`; `detailEvery: 1` makes
265
- every reminder detailed.
266
- - **`autoRefine`** — opt-in autonomous self-improvement (**off by default**).
267
- When `enabled`, the agent runs `/refine` itself every `everyTurns` turns
268
- (default 100). It is one of the package's opt-in autonomous paths: it reuses
269
- the exact `/refine` routine (audited `REFINE_ENTRY` tagged `source: "auto"`,
270
- branch-local, `/tree` rollback) and notifies before firing. `commit: true`
271
- also flushes durable state on each run. `gate: true` (needs `classifier.model`)
272
- asks the classifier first whether the recent trajectory contains a durable,
273
- reusable correction and skips the refine when it does not — cadence becomes
274
- signal, not just time (errors fall back to the plain cadence).
275
- `refineNoOpSkip` (default 3, `0` disables) is a free **history gate** that
276
- runs first: when the last N refine runs (any source) all produced nothing
277
- durable, the cadenced refine is skipped as a likely repeat no-op. It is
278
- **bounded**: at most one consecutive cadence is skipped on history grounds,
279
- so the gate can never latch shut — later trajectory evidence always gets a
280
- refine within one cadence (and manual `/refine` never consults the gate).
281
- The steering
282
- prompt is delivered via the pi ≥ 0.87 actionable `turn_end` boundary (a
283
- structural `harness.auto-refine-request` entry + `continue: true`), not a
284
- synthetic user message. Aborted/error turns (pi `turn_end`
285
- `BoundaryState.outcome`) are inert: they neither seed nor advance the
286
- cadence window — a refine never fires over partial evidence.
287
- - **`classifier`** — opt-in classifier model (pi ≥ 0.99) for the cheap gated
288
- paths: `"provider/id"` or a bare id of a **classifier** catalog entry, e.g.
289
- `"typesafe/jev-latest"` or a local `llama-cpp` classifier (every chat model
290
- listed for llama.cpp also appears as one). With pi ≥ 1.1.0 the catalog also
291
- offers OpenAI's GPT-6 Luna through the Decisions API (e.g.
292
- `"openai/gpt-6-luna"`, needs `OPENAI_API_KEY`) and the native llama.cpp
293
- decision models (Julia-1, Laya, Kev, lev, OpenJev through `/v1/systemone`,
294
- llama.cpp ≥ 0.6.0 — listed *only* as classifiers, which is exactly our use:
295
- a free local gate). When set and resolvable it enables the
296
- classifier-confirmed dedupe (see `dedupe` above) and the auto-refine `gate`.
297
- When unset or unresolvable, every classifier feature degrades to its
298
- no-classifier behavior.
299
- - **`virtualBinding`** — how the per-model isolation key treats pi **virtual
300
- models** (router extensions, pi ≥ 0.99). Default `"virtual"`: the key is
301
- the selected model's own `provider/id` — a router starts a blank harness.
302
- `"physical"`: when the selection is virtual, the key is the *physical*
303
- model behind the latest successful response on the branch — notes
304
- accumulated under that physical model keep injecting through the router, and
305
- switching routed models re-scopes exactly like a manual model switch. Before
306
- the first response the key is unknown: creates stay orphans and are adopted
307
- on first contact.
308
- - **`outcomeImportance`** — opt-in autonomous **promotion** loop (**off by
309
- default**). When `enabled`, a `turn_end` hook bumps (+`bump`, default 0.03)
310
- the importance of any active item the agent cited by its `[h_xxxx]` tag in the
311
- turn's output. Citations are read from completed turns only — an aborted
312
- turn's partial text is scanned by the next completed turn (the initial seed
313
- turn itself is never scanned, as before). Referenced items
314
- gain importance and get their `updatedAt`
315
- touched (so they survive time-based decay); ignored items keep decaying. This
316
- is the package's second opt-in autonomous path — promotion only, never
317
- deletes, persisted/branchable like `harness_mutate`. Autonomous demotion from
318
- outcomes is intentionally NOT done (high false-positive); use `/harness drop`,
319
- `prune --decay`, or the `dedupe` proposer for that.
320
-
321
- > **Removed:** the store-wide `durableScope` config key (deprecated 0.9.0,
322
- > removed now). Items carry their own scope (`/harness move`), and durable I/O
323
- > is always layered. Config files that still set the key load fine — unknown
324
- > keys are ignored. Migration from a `durableScope: "project"` setup: run
325
- > `/harness import` once in the project (its file's items adopt project
326
- > scope), then move any strays with `/harness move` (or classify the whole
327
- > store with `/harness split`).
210
+ | Key | Default | What it controls |
211
+ |---|---|---|
212
+ | `autoImport` | `false` | Opt-in durable sync: session_start layered auto-import + turn_end auto-export — `/refine` output survives into new sessions. |
213
+ | `importRemind` | on, every 25 turns | Awareness reminders for the sync (what arrived; bounded re-surfacings). Effective only with `autoImport`. |
214
+ | `injection` | on, 1500 tokens / 10 per kind | The per-turn prompt selection policy ([below](#injection-selection-on-by-default)). |
215
+ | `provenance` | on, both gates | Trust boundary: label agent-authored items unverified + let trusted items win budget contention ([below](#provenance-and-trust-boundary)). Stamping always happens; the gates only affect presentation. |
216
+ | `proposer` | `"steering"` | Which delta proposer `/refine` uses ([below](#proposers)). |
217
+ | `dedupe` | threshold 0.6, merge on | The rule-based dedupe proposer's policy. |
218
+ | `remindRefine` | on, every 25 turns | The notify-only `/refine` activation nudge; every 4th one is a detailed educational guide. |
219
+ | `autoRefine` | off, every 100 turns | Opt-in autonomous `/refine` on a cadence; `gate` adds the classifier question, `refineNoOpSkip` the free history gate. |
220
+ | `outcomeImportance` | off, bump 0.03 | Opt-in promotion of items you cite by `[h_xxxx]` tag. Promotion only — never deletes. |
221
+ | `classifier` | `model` unset, `auto: true` | Classifier enabling classifier-confirmed dedupe + the auto-refine gate. With `auto` (default), an unset `model` auto-resolves the hosted `github-copilot/microsoft-decision-1` on pi ≥ 1.5.1 with Copilot auth; set `model` to pin any classifier, or `auto: false` to require it. |
222
+ | `virtualBinding` | `"virtual"` | Per-model isolation key for router (virtual) models; `"physical"` keys by the routed model. |
223
+
224
+ The package's autonomous paths (`autoImport`, `autoRefine`, `outcomeImportance`)
225
+ are all opt-in and off by default; everything else is notify-only or
226
+ human-triggered. Removed keys: the store-wide `durableScope` (0.9.0) — items
227
+ carry their own scope (`/harness move`, `/harness split`); see
228
+ [docs/CONFIG.md](docs/CONFIG.md) for the migration note.
328
229
 
329
230
  ## Lessons and support signals (harnessing-level recursion)
330
231
 
@@ -476,6 +377,50 @@ re-exported from the package entry, so a companion package can layer richer
476
377
  policies (e.g. relevance to the current turn, via the shared `tokenize` /
477
378
  `tokenOverlap` helpers) without touching `inject.ts`.
478
379
 
380
+ ## Provenance and trust boundary
381
+
382
+ Almost every item in a running store was written by the **model itself** (via
383
+ `harness_mutate` or a `/refine` proposer). Without a trust boundary, a stale,
384
+ wrong, or injected note steers future sessions with the same authority as your
385
+ own instructions. Since 0.21 each item records **who last wrote its content**:
386
+
387
+ - **`provenance: "agent"`** — the content was last written by the model
388
+ (harness_mutate create, or any content rewrite through the tool or a
389
+ proposer). Stamped **server-side**: the model can never set it, and the
390
+ tool strips attempts (a smuggled `provenance: "owner"` cannot upgrade trust).
391
+ - **absent** — trusted. Owner-authored items, AGENTS.md imports, legacy
392
+ snapshots, and durable files without the marker. **No migration needed**:
393
+ existing stores keep today's rendering until new agent items appear.
394
+ - **Flip rule** — provenance follows the last content write. An agent rewrite
395
+ of a trusted item flips it to agent (losing trust is the safe direction;
396
+ nothing the model does can ever flip it back). Importance/keep/drop/scope
397
+ updates never flip it.
398
+
399
+ Two presentation effects, both on by default (`harness.json`):
400
+
401
+ ```json
402
+ { "provenance": { "label": true, "priority": true } }
403
+ ```
404
+
405
+ - **Label** — agent items render in the block as
406
+ `- [h_ab12] (unverified: agent-authored) …`, with one intro line defining
407
+ the marker (paid only when such an item is actually surfaced). `/harness
408
+ list` rows carry an `(unverified)` chip; `-f` spells it out.
409
+ - **Priority** — trusted items fill each kind's item slots and the injection
410
+ budget **first**; agent items only compete for what remains. An agent note
411
+ can never crowd an owner note out of the block — neither at the per-kind
412
+ cap nor at the token budget. Stores without agent items queue identically
413
+ to before.
414
+
415
+ Stamping always happens regardless of the knobs; they gate only presentation.
416
+ The durable file carries a ` - provenance: agent` sub-line for agent items
417
+ (legacy files stay byte-identical), and **durable wins** on import: hand-
418
+ deleting the line is the documented way to trust an item again.
419
+
420
+ **This is a visibility convention, not authentication.** It makes agent
421
+ authority explicit so you can review it; it cannot stop a model that already
422
+ runs commands from writing files or persuading you to import its text.
423
+
479
424
  ## Proposers
480
425
 
481
426
  `/refine` is split into two stages: **propose** (given evidence + state, decide
@@ -555,7 +500,9 @@ implementation on first `propose()`) directly into
555
500
 
556
501
  ## Status
557
502
 
558
- 0.18.x. Requires **pi ≥ 1.2.0**. Implemented:
503
+ 0.20.x. Requires **pi ≥ 1.2.0** (tool schemas are plain JSON Schema, so pi
504
+ 1.5's move to `@earendil-works/pi-schema` argument validation needs no
505
+ migration; developed and tested against pi 1.5). Implemented:
559
506
 
560
507
  - Unified harness-state store with branch-local snapshots (`/tree` rollback).
561
508
  - Online `/refine` + `harness_mutate` / `harness_list` tools.
@@ -595,8 +542,12 @@ implementation on first `propose()`) directly into
595
542
  config key; the store is never changed by selection. Rendered on **every
596
543
  provider request** (`context_with_system`), so a mid-run `harness_mutate`
597
544
  shows up on the very next request.
598
- - **Classifier features (pi ≥ 0.99, opt-in)**: `"classifier": { "model": … }`
599
- enables (1) classifier-confirmed dedupe — candidate merge pairs confirmed by
545
+ - **Classifier features (pi ≥ 0.99, opt-in)**: a classifier resolves via
546
+ `"classifier": { "model": … }`, or — when `model` is unset — via
547
+ auto-discovery (default on, `"classifier": { "auto": false }` opts out)
548
+ of the hosted `github-copilot/microsoft-decision-1` that pi ≥ 1.5.1 ships
549
+ with GitHub Copilot auth. A resolved classifier enables (1)
550
+ classifier-confirmed dedupe — candidate merge pairs confirmed by
600
551
  one batched yes/no call (errors fall back to the rule-based plan) — and (2)
601
552
  the auto-refine gate `"autoRefine": { "gate": true }`, which skips a cadenced
602
553
  refine when the trajectory holds no durable correction.
@@ -59,5 +59,3 @@ export declare function buildOmissionDrafts(projected: Iterable<ProjectedLike>):
59
59
  * boundary continuation when a steering draft lands (pi ≥ 0.87). Exported
60
60
  * so the thin entry (entry.ts) can delegate via dynamic import (issue #36). */
61
61
  export declare function handleAutoRefineTurnEnd(pi: ExtensionAPI, event: TurnEndEvent, ctx: ExtensionContext): Promise<TurnEndEventResult | void>;
62
- /** Subscribe to turn_end and run /refine on the configured cadence. */
63
- export declare function registerAutoRefine(pi: ExtensionAPI): void;
@@ -34,7 +34,7 @@
34
34
  // It stays visible: it notifies before firing, and the boundary draft (and the
35
35
  // gate decision) appear in the transcript. The decision logic is factored into
36
36
  // evaluateAutoRefine() so it is unit-testable without a live pi runtime.
37
- import { DEFAULT_AUTO_EVERY_TURNS, DEFAULT_REFINE_NOOP_SKIP, loadConfig } from "./config.js";
37
+ import { DEFAULT_AUTO_EVERY_TURNS, DEFAULT_REFINE_NOOP_SKIP, loadConfig, } from "./config.js";
38
38
  import { runRefine, gatherEvidence, DEFAULT_LOOKBACK_TURNS } from "./refine.js";
39
39
  import { buildClassify, buildGateRequest, gateDecision } from "./classify.js";
40
40
  import { recentIneffectiveRuns } from "./lessons.js";
@@ -79,7 +79,12 @@ export function evaluateAutoRefine(config, outcome) {
79
79
  export const AUTO_REFINE_ENTRY = "harness.auto-refine-request";
80
80
  /** Build the boundary draft carrying a steering message. Pure — testable. */
81
81
  export function buildRefineDraft(steeringMessage) {
82
- return { type: "custom_message", customType: AUTO_REFINE_ENTRY, content: steeringMessage, display: true };
82
+ return {
83
+ type: "custom_message",
84
+ customType: AUTO_REFINE_ENTRY,
85
+ content: steeringMessage,
86
+ display: true,
87
+ };
83
88
  }
84
89
  /**
85
90
  * Context-edit drafts omitting every LIVE prior auto-refine request from
@@ -118,14 +123,15 @@ export async function handleAutoRefineTurnEnd(pi, event, ctx) {
118
123
  // gate can never latch shut against later, richer trajectory evidence
119
124
  // (review r4341960942) — the run after a skip always happens.
120
125
  const noOpSkip = config.autoRefine?.refineNoOpSkip ?? DEFAULT_REFINE_NOOP_SKIP;
121
- if (historyGateSkips < HISTORY_GATE_MAX_CONSECUTIVE_SKIPS && recentIneffectiveRuns(ctx.sessionManager.getBranch(), noOpSkip)) {
126
+ if (historyGateSkips < HISTORY_GATE_MAX_CONSECUTIVE_SKIPS &&
127
+ recentIneffectiveRuns(ctx.sessionManager.getBranch(), noOpSkip)) {
122
128
  historyGateSkips += 1;
123
129
  ctx.ui.notify(`Auto-refine: skipped — the last ${noOpSkip} refine run(s) produced nothing durable (history gate, ${historyGateSkips}/${HISTORY_GATE_MAX_CONSECUTIVE_SKIPS} consecutive skip; the next cadence runs regardless; refineNoOpSkip: 0 disables).`, "info");
124
130
  return;
125
131
  }
126
132
  // Opt-in classifier gate: cheap yes/no before spending the refine.
127
133
  if (config.autoRefine?.gate) {
128
- const classify = buildClassify(ctx, config.classifier?.model);
134
+ const classify = buildClassify(ctx, config.classifier);
129
135
  if (classify) {
130
136
  const evidence = gatherEvidence(ctx, DEFAULT_LOOKBACK_TURNS);
131
137
  const res = await classify(buildGateRequest(evidence));
@@ -178,7 +184,3 @@ export async function handleAutoRefineTurnEnd(pi, event, ctx) {
178
184
  ctx.ui.notify(`Auto-refine failed: ${err.message}`, "error");
179
185
  }
180
186
  }
181
- /** Subscribe to turn_end and run /refine on the configured cadence. */
182
- export function registerAutoRefine(pi) {
183
- pi.on("turn_end", (event, ctx) => handleAutoRefineTurnEnd(pi, event, ctx));
184
- }
@@ -65,14 +65,36 @@ interface ClassifierModelLike {
65
65
  * it then degrades to its no-classifier behavior.
66
66
  */
67
67
  export declare function resolveClassifierModel(registry: RegistryLike | undefined, configured?: string): ClassifierModelLike | undefined;
68
+ /**
69
+ * The auto-discovered default classifier: a hosted bool/score classifier that
70
+ * pi ≥ 1.5.1 ships with GitHub Copilot authentication (billed to the user's
71
+ * Copilot plan; no local server, no extra API key). Keeping this a single
72
+ * known-good id — not "first classifier in the catalog" — makes discovery
73
+ * deterministic and reviewable; widen it only deliberately.
74
+ */
75
+ export declare const DEFAULT_CLASSIFIER = "github-copilot/microsoft-decision-1";
76
+ /**
77
+ * Auto-discovery fallback for buildClassify: the hosted default above when the
78
+ * registry lists it, otherwise undefined (degrade to no-classifier behavior).
79
+ */
80
+ export declare function discoverClassifierModel(registry: RegistryLike | undefined): ClassifierModelLike | undefined;
68
81
  /** Build the ClassifyFn adapter over a resolved classifier model. */
69
82
  export declare function makeClassifyFn(registry: RegistryLike, model: ClassifierModelLike, signal?: AbortSignal): ClassifyFn;
83
+ /** Structural slice of the normalized `classifier` config (config.ts). */
84
+ export interface ClassifierConfigSlice {
85
+ model?: string | undefined;
86
+ /** Default true (opt-out): when `model` is unset, fall back to the hosted
87
+ * default classifier when the registry lists one. */
88
+ auto?: boolean;
89
+ }
70
90
  /**
71
91
  * Resolve the ClassifyFn for a session from config + ctx, or undefined.
72
92
  * The single construction point shared by refine (ProposeInput.classify) and
73
- * the auto-refine gate.
93
+ * the auto-refine gate. An explicit `classifier.model` always wins; with
94
+ * `auto` (default) an unset model falls back to discovery (see
95
+ * discoverClassifierModel).
74
96
  */
75
- export declare function buildClassify(ctx: ExtensionContext, configuredModel?: string): ClassifyFn | undefined;
97
+ export declare function buildClassify(ctx: ExtensionContext, classifier?: ClassifierConfigSlice): ClassifyFn | undefined;
76
98
  /**
77
99
  * The auto-refine gate question: did the recent trajectory contain a durable,
78
100
  * reusable correction worth a /refine pass? Pure builder — unit-testable.
package/dist/classify.js CHANGED
@@ -10,6 +10,15 @@
10
10
  // 2. dedupe confirmation (proposer.ts): a precision filter on candidate merge
11
11
  // pairs — see classifyConfirmPairs().
12
12
  //
13
+ // Model resolution has two tiers (buildClassify): an explicitly configured
14
+ // `classifier.model` always wins; when it is unset, auto-discovery (default on,
15
+ // `classifier.auto: false` opts out) falls back to ONE known hosted classifier —
16
+ // github-copilot/microsoft-decision-1, shipped by pi ≥ 1.5.1 with GitHub
17
+ // Copilot auth — so the gated paths work with zero setup for Copilot users.
18
+ // Discovery deliberately never picks a local llama.cpp entry: the catalog can
19
+ // list one while no server is running, and an unreachable classifier is worse
20
+ // than none (the gates would soft-fail every time).
21
+ //
13
22
  // The pi-ai classifier shapes (ClassifierContext/ClassifierQuestion/…) are kept
14
23
  // OUT of the public proposer interface: ClassifyFn below is a minimal structural
15
24
  // contract so proposers stay testable without pi runtime types.
@@ -35,6 +44,21 @@ export function resolveClassifierModel(registry, configured) {
35
44
  return cm.id === configured || `${cm.provider}/${cm.id}` === configured;
36
45
  }) ?? undefined);
37
46
  }
47
+ /**
48
+ * The auto-discovered default classifier: a hosted bool/score classifier that
49
+ * pi ≥ 1.5.1 ships with GitHub Copilot authentication (billed to the user's
50
+ * Copilot plan; no local server, no extra API key). Keeping this a single
51
+ * known-good id — not "first classifier in the catalog" — makes discovery
52
+ * deterministic and reviewable; widen it only deliberately.
53
+ */
54
+ export const DEFAULT_CLASSIFIER = "github-copilot/microsoft-decision-1";
55
+ /**
56
+ * Auto-discovery fallback for buildClassify: the hosted default above when the
57
+ * registry lists it, otherwise undefined (degrade to no-classifier behavior).
58
+ */
59
+ export function discoverClassifierModel(registry) {
60
+ return resolveClassifierModel(registry, DEFAULT_CLASSIFIER);
61
+ }
38
62
  /** Build the ClassifyFn adapter over a resolved classifier model. */
39
63
  export function makeClassifyFn(registry, model, signal) {
40
64
  const label = `${model.provider}/${model.id}`;
@@ -102,12 +126,17 @@ export function makeClassifyFn(registry, model, signal) {
102
126
  /**
103
127
  * Resolve the ClassifyFn for a session from config + ctx, or undefined.
104
128
  * The single construction point shared by refine (ProposeInput.classify) and
105
- * the auto-refine gate.
129
+ * the auto-refine gate. An explicit `classifier.model` always wins; with
130
+ * `auto` (default) an unset model falls back to discovery (see
131
+ * discoverClassifierModel).
106
132
  */
107
- export function buildClassify(ctx, configuredModel) {
133
+ export function buildClassify(ctx, classifier) {
108
134
  const registry = ctx.modelRegistry;
109
- const model = resolveClassifierModel(registry, configuredModel);
110
- if (!registry || !model)
135
+ if (!registry)
136
+ return undefined;
137
+ const model = resolveClassifierModel(registry, classifier?.model) ??
138
+ (classifier?.auto !== false ? discoverClassifierModel(registry) : undefined);
139
+ if (!model)
111
140
  return undefined;
112
141
  return makeClassifyFn(registry, model, ctx.signal);
113
142
  }
@@ -135,11 +164,17 @@ export function buildGateRequest(evidence) {
135
164
  */
136
165
  export function gateDecision(result) {
137
166
  if (!result.ok)
138
- return { proceed: true, because: `classifier error (${result.error ?? "unknown"}); falling back to cadence` };
167
+ return {
168
+ proceed: true,
169
+ because: `classifier error (${result.error ?? "unknown"}); falling back to cadence`,
170
+ };
139
171
  const a = result.answers.gate;
140
172
  if (!a)
141
173
  return { proceed: true, because: "no gate answer; falling back to cadence" };
142
174
  return a.value
143
175
  ? { proceed: true, because: `classifier: yes (confidence ${a.confidence ?? "?"})` }
144
- : { proceed: false, because: `classifier: no durable correction (confidence ${a.confidence ?? "?"})` };
176
+ : {
177
+ proceed: false,
178
+ because: `classifier: no durable correction (confidence ${a.confidence ?? "?"})`,
179
+ };
145
180
  }
package/dist/config.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { type LayerFile, type ScopeInfo } from "./store.js";
2
2
  import { type NormalizedInjection } from "./select.js";
3
+ import { type NormalizedProvenance } from "./types.js";
3
4
  export declare const DEFAULT_EVERY_TURNS = 25;
4
5
  export declare const DEFAULT_AUTO_EVERY_TURNS = 100;
5
6
  /** Default per-reference importance bump for the opt-in outcome loop. */
@@ -39,10 +40,10 @@ export interface HarnessConfig {
39
40
  everyTurns?: number;
40
41
  };
41
42
  /** /refine cadence nudge (ON by default, issue #19 — activation nudge, notify-only):
42
- * every `everyTurns` completed turns a one-line reminder fires; every
43
- * `detailEvery`-th reminder escalates to a rotating educational guide
44
- * (see src/remind.ts). Never mutates state; `enabled: false` restores the
45
- * old silence. */
43
+ * every `everyTurns` completed turns a one-line reminder fires; every
44
+ * `detailEvery`-th reminder escalates to a rotating educational guide
45
+ * (see src/remind.ts). Never mutates state; `enabled: false` restores the
46
+ * old silence. */
46
47
  remindRefine?: {
47
48
  enabled?: boolean;
48
49
  everyTurns?: number;
@@ -71,12 +72,18 @@ export interface HarnessConfig {
71
72
  * DEFAULT_REFINE_NOOP_SKIP (3); 0 disables the history gate. */
72
73
  refineNoOpSkip?: number;
73
74
  };
74
- /** Classifier model for the cheap gated paths (pi ≥ 0.99): "provider/id" or
75
+ /** Classifier for the cheap gated paths (pi ≥ 0.99): "provider/id" or
75
76
  * a bare id of a classifier catalog entry (e.g. "typesafe/jev-latest" or a
76
- * local llama.cpp classifier). When unset or unresolvable, every classifier
77
- * feature degrades to its no-classifier behavior. */
77
+ * local llama.cpp classifier). When `model` is unset or unresolvable,
78
+ * `auto` (default true) falls back to a hosted zero-setup classifier when
79
+ * the registry lists one — pi ≥ 1.5.1 ships
80
+ * "github-copilot/microsoft-decision-1" with GitHub Copilot auth. When
81
+ * nothing resolves, every classifier feature degrades to its no-classifier
82
+ * behavior. */
78
83
  classifier?: {
79
84
  model?: string | undefined;
85
+ /** Default true (opt-out). Set false to require an explicit `model`. */
86
+ auto?: boolean;
80
87
  };
81
88
  /** Virtual-model binding policy (pi ≥ 0.99). Default "virtual". */
82
89
  virtualBinding?: VirtualBinding;
@@ -91,6 +98,10 @@ export interface HarnessConfig {
91
98
  /** Injection selection policy (on by default). Resolved by loadConfig, so the
92
99
  * value here is always fully-populated. See src/select.ts. */
93
100
  injection?: NormalizedInjection;
101
+ /** Provenance trust-boundary policy (label + selection priority, both on by
102
+ * default). Gates only PRESENTATION — stamping always happens server-side.
103
+ * Resolved by loadConfig. See src/select.ts / src/inject.ts. */
104
+ provenance?: NormalizedProvenance;
94
105
  /** Dedupe proposer policy (merge-capable). Resolved by loadConfig, so the
95
106
  * value here is always fully-populated. See src/proposer.ts. */
96
107
  dedupe?: NormalizedDedupe;
@@ -131,12 +142,14 @@ export declare function saveConfig(next: Partial<HarnessConfig> | Record<string,
131
142
  * silently (expected for a fresh setup); a MALFORMED file → defaults too, but
132
143
  * flagged via configMalformed() so the session can warn instead of every
133
144
  * setting silently stopping (review finding #6). Cached for the process
134
- * lifetime (config is read once per session). */
145
+ * lifetime (config is read once per session); concurrent cold callers share
146
+ * one in-flight read. */
135
147
  export declare function loadConfig(path?: string): Promise<HarnessConfig>;
136
148
  /** True when the file at `path` existed but failed to parse on the last
137
149
  * loadConfig — the effective config silently fell back to defaults. */
138
150
  export declare function configMalformed(path?: string): boolean;
139
- /** Test hook: drop the in-process cache. */
151
+ /** Test hook: drop the in-process cache — including any in-flight read (it
152
+ * resolves to its caller but can no longer populate the cache). */
140
153
  export declare function resetConfigCache(): void;
141
154
  /** Path of a project's durable layer file: <projectDir>/<slug>.md. */
142
155
  export declare function projectDurablePath(cwd?: string): string;