/** * Per-phase structural sub-fingerprint (M6). * * `phaseFingerprint` produces a content-addressed hash of ONLY the subset of * the flow definition that can affect a single phase's subagent output: the * phase itself plus its transitive dependency closure. Folding this into the * cross-run cache key (instead of the whole-flow `flowDefHash`) means editing * phase B invalidates only B and its transitive dependents — independent * sibling phase A keeps its cache hit. * * ## Soundness (the fallback gate) * * Per-phase invalidation is only sound when a phase's *real* dependencies are * fully captured by the static `dependsOn ∪ from` closure. Three cases break * that guarantee, so `phaseFingerprint` returns `undefined` for them and the * caller falls back to the whole-flow `flowDefHash` (safe, = pre-M6 behavior): * * 1. **Shared Context Tree** (`def.contextSharing === true` or any closure * member has `shareContext === true`): a sharing phase can read sibling * blackboard writes OUTSIDE its declared deps, so the static closure * under-approximates real reads. * 2. **`flow` phase in the closure** (`type === "flow"`): a `flow` phase's * sub-structure is resolved at runtime (inline `def`) or from a saved * flow (`use`) and is not statically visible here. Editing the saved * sub-flow would not move this phase's sub-fingerprint. * 3. **`join: "any"` phase** (`phase.join === "any"`): validation exempts it * from the `{steps.X}`-must-be-in-`dependsOn` check, so it may read * phases outside its static closure. The closure under-approximates its * real reads, so fall back to whole-flow invalidation. * * `cache`, `retry`, `concurrency`, and `final` are stripped from each phase * before hashing: none of them changes the subagent's OUTPUT (they are policy, * execution mechanics, or result selection). `cache`'s sub-fields * (`scope`/`ttl`/`fingerprint`) reach the cache key through other paths * (`cc.scope` gates the lookup, `cc.ttlMs` governs expiry, `cc.fingerprint` is * in the key tail). Every other `Phase` field is hashed. `PhaseSchema` uses * `additionalProperties: false`, so no surprise field can be missed. * * Pure + async (Web Crypto via `hashCanonical`). Reuses the vendored * `canonicalJson`/`hashCanonical` (byte-identical to overstory's contract) so * the sub-fingerprint shares one hashing contract with `flowDefHash`. Never * throws — callers wrap in try/catch and degrade to `flowDefHash`. * * @see docs/internal/cache-migration.md (v3:phasefp tier) */ import { type Taskflow } from "../schema.ts"; /** * Per-phase structural sub-fingerprint. * * @returns the hex hash, or `undefined` when per-phase soundness cannot be * guaranteed (caller falls back to the whole-flow `flowDefHash`). Never * throws. */ export declare function phaseFingerprint(def: Taskflow, phaseId: string): Promise; //# sourceMappingURL=phasefp.d.ts.map