@coderifts/agent-guard 8.3.0 → 8.5.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 +32 -27
- package/dist/cjs/auto-derive.d.ts +74 -0
- package/dist/cjs/auto-derive.d.ts.map +1 -0
- package/dist/cjs/auto-derive.js +272 -0
- package/dist/cjs/auto-derive.js.map +1 -0
- package/dist/cjs/auto-recheck.d.ts +76 -0
- package/dist/cjs/auto-recheck.d.ts.map +1 -0
- package/dist/cjs/auto-recheck.js +240 -0
- package/dist/cjs/auto-recheck.js.map +1 -0
- package/dist/cjs/cas-attestation.d.ts +35 -2
- package/dist/cjs/cas-attestation.d.ts.map +1 -1
- package/dist/cjs/cas-attestation.js +105 -2
- package/dist/cjs/cas-attestation.js.map +1 -1
- package/dist/cjs/execution-proof.d.ts +33 -0
- package/dist/cjs/execution-proof.d.ts.map +1 -1
- package/dist/cjs/execution-proof.js +16 -0
- package/dist/cjs/execution-proof.js.map +1 -1
- package/dist/cjs/final-answer-proof.d.ts.map +1 -1
- package/dist/cjs/final-answer-proof.js +28 -1
- package/dist/cjs/final-answer-proof.js.map +1 -1
- package/dist/cjs/guard.d.ts.map +1 -1
- package/dist/cjs/guard.js +85 -18
- package/dist/cjs/guard.js.map +1 -1
- package/dist/cjs/index.d.ts +8 -2
- package/dist/cjs/index.d.ts.map +1 -1
- package/dist/cjs/index.js +25 -3
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/monitoring-delivery.d.ts +63 -0
- package/dist/cjs/monitoring-delivery.d.ts.map +1 -0
- package/dist/cjs/monitoring-delivery.js +277 -0
- package/dist/cjs/monitoring-delivery.js.map +1 -0
- package/dist/cjs/tool-registry.d.ts.map +1 -1
- package/dist/cjs/tool-registry.js +36 -6
- package/dist/cjs/tool-registry.js.map +1 -1
- package/dist/cjs/types.d.ts +71 -4
- package/dist/cjs/types.d.ts.map +1 -1
- package/dist/cjs/with-coderifts.d.ts +23 -0
- package/dist/cjs/with-coderifts.d.ts.map +1 -1
- package/dist/cjs/with-coderifts.js +21 -0
- package/dist/cjs/with-coderifts.js.map +1 -1
- package/dist/esm/auto-derive.d.ts +74 -0
- package/dist/esm/auto-derive.d.ts.map +1 -0
- package/dist/esm/auto-derive.js +265 -0
- package/dist/esm/auto-derive.js.map +1 -0
- package/dist/esm/auto-recheck.d.ts +76 -0
- package/dist/esm/auto-recheck.d.ts.map +1 -0
- package/dist/esm/auto-recheck.js +234 -0
- package/dist/esm/auto-recheck.js.map +1 -0
- package/dist/esm/cas-attestation.d.ts +35 -2
- package/dist/esm/cas-attestation.d.ts.map +1 -1
- package/dist/esm/cas-attestation.js +103 -2
- package/dist/esm/cas-attestation.js.map +1 -1
- package/dist/esm/execution-proof.d.ts +33 -0
- package/dist/esm/execution-proof.d.ts.map +1 -1
- package/dist/esm/execution-proof.js +16 -0
- package/dist/esm/execution-proof.js.map +1 -1
- package/dist/esm/final-answer-proof.d.ts.map +1 -1
- package/dist/esm/final-answer-proof.js +28 -1
- package/dist/esm/final-answer-proof.js.map +1 -1
- package/dist/esm/guard.d.ts.map +1 -1
- package/dist/esm/guard.js +86 -19
- package/dist/esm/guard.js.map +1 -1
- package/dist/esm/index.d.ts +8 -2
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +6 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/monitoring-delivery.d.ts +63 -0
- package/dist/esm/monitoring-delivery.d.ts.map +1 -0
- package/dist/esm/monitoring-delivery.js +270 -0
- package/dist/esm/monitoring-delivery.js.map +1 -0
- package/dist/esm/tool-registry.d.ts.map +1 -1
- package/dist/esm/tool-registry.js +36 -6
- package/dist/esm/tool-registry.js.map +1 -1
- package/dist/esm/types.d.ts +71 -4
- package/dist/esm/types.d.ts.map +1 -1
- package/dist/esm/with-coderifts.d.ts +23 -0
- package/dist/esm/with-coderifts.d.ts.map +1 -1
- package/dist/esm/with-coderifts.js +21 -0
- package/dist/esm/with-coderifts.js.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -161,6 +161,8 @@ Honesty (verbatim, and also on the machine proof as
|
|
|
161
161
|
`limits.commit_observation_is_observed_at_t3_not_atomic: true`):
|
|
162
162
|
`commit_observation is observed at T3, not atomic: another writer may act between write and observation; token-only adapters compare version token not content; host attestation is a host claim layered on the measurement`.
|
|
163
163
|
|
|
164
|
+
When `withCodeRifts({ executorAttestation: { registry } })` is set and a CAS outcome carries a verified `cr.exec.attest.v1` token, the T3 section upgrades to `committed — executor-attested (ATTEST_VALID, kid …)`. Invalid attestation stays host-claimed with `attest_status` visible. Observation-side only.
|
|
165
|
+
|
|
164
166
|
> **Supply `artifacts[]` with content.** If the guard detects a contract change (e.g. from
|
|
165
167
|
> `filesTouched`/`diff`) but you did **not** supply `artifacts[]` with `before`/`after`, it fails
|
|
166
168
|
> closed **locally** with `outcome.verdict.cause === 'MISSING_ARTIFACT_CONTENT'` — the tool does not
|
|
@@ -807,42 +809,45 @@ The chain records an issued decision for a mutation that may never have landed
|
|
|
807
809
|
Do **not** claim an intact chain proves session completeness, that edits landed, or that downstream
|
|
808
810
|
CI may skip re-analysis. Prefer tamper-evident language over “tamper-proof.”
|
|
809
811
|
|
|
810
|
-
### WARN / `CONTINUE_WITH_MONITORING`
|
|
812
|
+
### WARN / `CONTINUE_WITH_MONITORING` — claim gate + measured delivery
|
|
811
813
|
|
|
812
814
|
Without both **`monitoringSinkWired: true`** and an **`onEvent`** handler, a **WARN** verdict does
|
|
813
|
-
**not** proceed
|
|
814
|
-
not run**. That is intentional, not a transport bug.
|
|
815
|
+
**not** proceed (`MONITORING_UNWIRED`, tool does not run). That claim-agreement gate is unchanged.
|
|
815
816
|
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
does **not** and **cannot** confirm that any event reaches a destination — a no-op `() => {}` is
|
|
819
|
-
indistinguishable from a real logger, and we do not try to detect empty functions. A declaration is
|
|
820
|
-
a claim we record, not a fact we verify.
|
|
817
|
+
**Measured delivery (N-4)** is a separate observation. Set `monitoringSink` to a callback that may
|
|
818
|
+
return an ack, or to `{ url }` (HTTP POST). The CWM outcome then carries `monitoring_delivery`:
|
|
821
819
|
|
|
822
|
-
|
|
820
|
+
| `monitoring_delivery.status` | Meaning |
|
|
821
|
+
|------------------------------|---------|
|
|
822
|
+
| `delivered_acked` | Sink invocation completed and returned a non-error ack (callback value / HTTP 2xx). Evidence: `{ at, ack_hash: sha256(ack-bytes) or status_code, sink_kind }`. Optional HMAC (`ackHmacKey`) valid → `ack_verified: true`. |
|
|
823
|
+
| `sent_unacked` | Invocation dispatched, no ack semantics (undefined-returning callback, or claim+`onEvent` only with no dedicated sink). |
|
|
824
|
+
| `not_delivered` | Throw / timeout (default 5s, `monitoringSinkTimeoutMs`) / HTTP non-2xx / invalid HMAC. |
|
|
823
825
|
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
| `true` | absent | contradiction → `MONITORING_UNWIRED` |
|
|
828
|
-
| absent / `false` | function present | **unwired** — declaration required; `onEvent` alone is not enough |
|
|
829
|
-
| absent / `false` | absent | unwired (same as today with no sink) |
|
|
826
|
+
**Teeth:** under default `failPolicy: 'closed'` (and `profile: 'ENFORCING_STRICT'`), `not_delivered`
|
|
827
|
+
is treated as the sink-not-wired case — `MONITORING_UNWIRED`, factory does not run. `observeOnly` or
|
|
828
|
+
`failPolicy: 'open'` degrade: the call proceeds **unenforced** with the reason visible.
|
|
830
829
|
|
|
831
|
-
**
|
|
832
|
-
|
|
833
|
-
|
|
830
|
+
**Honesty:** `delivered_acked` means the sink returned an ack. It does **not** mean a human saw the
|
|
831
|
+
event. Invalid HMAC is `not_delivered` (a lying sink is worse than no sink). No HMAC key configured
|
|
832
|
+
→ no verification attempted, no penalty.
|
|
834
833
|
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
834
|
+
**Agreement (fail closed on contradiction) — claim gate, still required:**
|
|
835
|
+
|
|
836
|
+
| `monitoringSinkWired` | `onEvent` | MONITOR claim gate |
|
|
837
|
+
|-----------------------|-----------|--------------------|
|
|
838
|
+
| `true` | function present | wired — proceeds to delivery measurement (when receipt verified) |
|
|
839
|
+
| `true` | absent | contradiction → `MONITORING_UNWIRED` |
|
|
840
|
+
| absent / `false` | function present | **unwired** — declaration required; `onEvent` alone is not enough |
|
|
841
|
+
| absent / `false` | absent | unwired |
|
|
838
842
|
|
|
839
|
-
**Three different jobs (not three sinks):** `onEvent` = lifecycle events
|
|
840
|
-
host claim that monitoring is intentionally wired
|
|
841
|
-
|
|
842
|
-
|
|
843
|
+
**Three different jobs (not three sinks):** `onEvent` = lifecycle events (never throws, never an
|
|
844
|
+
ack); `monitoringSinkWired` = host claim that monitoring is intentionally wired; `monitoringSink` =
|
|
845
|
+
measured delivery (callback or HTTP); `onSettledCall` = one settle record per returned-table call
|
|
846
|
+
and gates nothing.
|
|
843
847
|
|
|
844
|
-
Pass
|
|
845
|
-
`
|
|
848
|
+
Pass claim+lifecycle on `withCodeRifts({ …, onEvent, monitoringSinkWired: true })` and optionally
|
|
849
|
+
`monitoringSink` / `ackHmacKey` / `monitoringSinkTimeoutMs`. Same fields on `guardToolCall` /
|
|
850
|
+
`guardToolRegistry`’s `guard` config.
|
|
846
851
|
|
|
847
852
|
## Guarantees (tsc-verified)
|
|
848
853
|
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* S1 auto-derive — wrap-layer before/after pair from the tool call + current-state readers.
|
|
3
|
+
*
|
|
4
|
+
* Default OFF. Frozen guardToolCall is unchanged. Host args.artifacts always win.
|
|
5
|
+
* BEFORE comes from a reader of the SAME target (fs path / api / db / registry).
|
|
6
|
+
* AFTER is the call's intended write content. Missing target → before:null
|
|
7
|
+
* (derivation_note before_unavailable); empty file → before:"".
|
|
8
|
+
*
|
|
9
|
+
* Reader throw/timeout → today's fragment path (binder lift); never block on derivation.
|
|
10
|
+
* Observation-only: derivation is not a fingerprint preimage field.
|
|
11
|
+
*/
|
|
12
|
+
import type { ArtifactType, ResolveConfig } from './artifact-resolver.js';
|
|
13
|
+
import type { GuardConfig, ToolCallDescriptor } from './types.js';
|
|
14
|
+
export declare const AUTO_DERIVE_SOURCE: "guard_auto_derived";
|
|
15
|
+
export declare const AUTO_DERIVE_READ_TIMEOUT_MS = 2000;
|
|
16
|
+
export type AutoDeriveMode = 'host_supplied' | 'auto_derived' | 'fragment_only';
|
|
17
|
+
export type AutoDeriveTargetKind = 'fs' | 'api' | 'db' | 'registry';
|
|
18
|
+
export type AutoDeriveTarget = {
|
|
19
|
+
kind: AutoDeriveTargetKind;
|
|
20
|
+
key: string;
|
|
21
|
+
};
|
|
22
|
+
export type AutoDeriveNote = {
|
|
23
|
+
target: string;
|
|
24
|
+
note: 'before_unavailable' | 'reader_threw' | 'reader_timeout' | 'not_contract_path';
|
|
25
|
+
};
|
|
26
|
+
export type AutoDeriveObservation = {
|
|
27
|
+
derivation?: {
|
|
28
|
+
mode: AutoDeriveMode;
|
|
29
|
+
targets: ReadonlyArray<AutoDeriveTarget>;
|
|
30
|
+
notes?: ReadonlyArray<AutoDeriveNote>;
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
export type AutoDeriveReader = (key: string) => string | null | Promise<string | null>;
|
|
34
|
+
/** Current-state readers. Return null = absent (not empty). Throw/timeout → fragment fallback. */
|
|
35
|
+
export type AutoDeriveReaders = {
|
|
36
|
+
fs?: AutoDeriveReader;
|
|
37
|
+
api?: AutoDeriveReader;
|
|
38
|
+
db?: AutoDeriveReader;
|
|
39
|
+
registry?: AutoDeriveReader;
|
|
40
|
+
};
|
|
41
|
+
export type AutoDeriveConfig = {
|
|
42
|
+
readers?: AutoDeriveReaders;
|
|
43
|
+
/** CAP-202 resolve() config (pathTypeHints, ssotPrefer). Optional; not required for fs reads. */
|
|
44
|
+
resolveConfig?: ResolveConfig;
|
|
45
|
+
};
|
|
46
|
+
export type DerivedArtifact = {
|
|
47
|
+
id: string;
|
|
48
|
+
type: ArtifactType;
|
|
49
|
+
before: string | null;
|
|
50
|
+
after: string;
|
|
51
|
+
source: typeof AUTO_DERIVE_SOURCE;
|
|
52
|
+
};
|
|
53
|
+
/** Default fs reader: utf8 contents, ENOENT → null (absent ≠ empty). Other errors throw. */
|
|
54
|
+
export declare function defaultFsReader(filePath: string): Promise<string | null>;
|
|
55
|
+
export declare function normalizeAutoDerive(raw: unknown): AutoDeriveConfig | null;
|
|
56
|
+
export type AutoDeriveResult = {
|
|
57
|
+
call: ToolCallDescriptor;
|
|
58
|
+
derivation: NonNullable<AutoDeriveObservation['derivation']>;
|
|
59
|
+
failed?: {
|
|
60
|
+
cause: string;
|
|
61
|
+
};
|
|
62
|
+
};
|
|
63
|
+
/**
|
|
64
|
+
* Derive a before/after pair onto the call descriptor when the host did not supply artifacts.
|
|
65
|
+
* Never throws out — reader failures return the bound call with fragment_only + failed.cause.
|
|
66
|
+
*/
|
|
67
|
+
export declare function runAutoDerive(args: {
|
|
68
|
+
bound: ToolCallDescriptor;
|
|
69
|
+
rawArgs: unknown;
|
|
70
|
+
cfg: AutoDeriveConfig;
|
|
71
|
+
config: GuardConfig;
|
|
72
|
+
}): Promise<AutoDeriveResult>;
|
|
73
|
+
export declare function attachDerivation<T>(outcome: T, derivation: NonNullable<AutoDeriveObservation['derivation']> | null | undefined): T;
|
|
74
|
+
//# sourceMappingURL=auto-derive.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auto-derive.d.ts","sourceRoot":"","sources":["../../src/auto-derive.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAIH,OAAO,KAAK,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAC1E,OAAO,KAAK,EAAE,WAAW,EAAc,kBAAkB,EAAY,MAAM,YAAY,CAAC;AAExF,eAAO,MAAM,kBAAkB,EAAG,oBAA6B,CAAC;AAChE,eAAO,MAAM,2BAA2B,OAAO,CAAC;AAEhD,MAAM,MAAM,cAAc,GAAG,eAAe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MAAM,EAAE,OAAO,kBAAkB,CAAC;CACnC,CAAC;AAYF,4FAA4F;AAC5F,wBAAsB,eAAe,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAU9E;AAkBD,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,OAAO,GAAG,gBAAgB,GAAG,IAAI,CAgBzE;AA0FD,MAAM,MAAM,gBAAgB,GAAG;IAC7B,IAAI,EAAE,kBAAkB,CAAC;IACzB,UAAU,EAAE,WAAW,CAAC,qBAAqB,CAAC,YAAY,CAAC,CAAC,CAAC;IAC7D,MAAM,CAAC,EAAE;QAAE,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC;CAC5B,CAAC;AAEF;;;GAGG;AACH,wBAAsB,aAAa,CAAC,IAAI,EAAE;IACxC,KAAK,EAAE,kBAAkB,CAAC;IAC1B,OAAO,EAAE,OAAO,CAAC;IACjB,GAAG,EAAE,gBAAgB,CAAC;IACtB,MAAM,EAAE,WAAW,CAAC;CACrB,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAmG5B;AAED,wBAAgB,gBAAgB,CAAC,CAAC,EAChC,OAAO,EAAE,CAAC,EACV,UAAU,EAAE,WAAW,CAAC,qBAAqB,CAAC,YAAY,CAAC,CAAC,GAAG,IAAI,GAAG,SAAS,GAC9E,CAAC,CAGH"}
|
|
@@ -0,0 +1,272 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* S1 auto-derive — wrap-layer before/after pair from the tool call + current-state readers.
|
|
4
|
+
*
|
|
5
|
+
* Default OFF. Frozen guardToolCall is unchanged. Host args.artifacts always win.
|
|
6
|
+
* BEFORE comes from a reader of the SAME target (fs path / api / db / registry).
|
|
7
|
+
* AFTER is the call's intended write content. Missing target → before:null
|
|
8
|
+
* (derivation_note before_unavailable); empty file → before:"".
|
|
9
|
+
*
|
|
10
|
+
* Reader throw/timeout → today's fragment path (binder lift); never block on derivation.
|
|
11
|
+
* Observation-only: derivation is not a fingerprint preimage field.
|
|
12
|
+
*/
|
|
13
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
exports.AUTO_DERIVE_READ_TIMEOUT_MS = exports.AUTO_DERIVE_SOURCE = void 0;
|
|
15
|
+
exports.defaultFsReader = defaultFsReader;
|
|
16
|
+
exports.normalizeAutoDerive = normalizeAutoDerive;
|
|
17
|
+
exports.runAutoDerive = runAutoDerive;
|
|
18
|
+
exports.attachDerivation = attachDerivation;
|
|
19
|
+
const node_fs_1 = require("node:fs");
|
|
20
|
+
const artifact_resolver_js_1 = require("./artifact-resolver.js");
|
|
21
|
+
exports.AUTO_DERIVE_SOURCE = 'guard_auto_derived';
|
|
22
|
+
exports.AUTO_DERIVE_READ_TIMEOUT_MS = 2000;
|
|
23
|
+
function iso() {
|
|
24
|
+
return new Date().toISOString();
|
|
25
|
+
}
|
|
26
|
+
function emit(config, e) {
|
|
27
|
+
if (config.onEvent) {
|
|
28
|
+
try {
|
|
29
|
+
config.onEvent(e);
|
|
30
|
+
}
|
|
31
|
+
catch { /* onEvent never throws out */ }
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
/** Default fs reader: utf8 contents, ENOENT → null (absent ≠ empty). Other errors throw. */
|
|
35
|
+
async function defaultFsReader(filePath) {
|
|
36
|
+
try {
|
|
37
|
+
return await node_fs_1.promises.readFile(filePath, 'utf8');
|
|
38
|
+
}
|
|
39
|
+
catch (err) {
|
|
40
|
+
const code = err && typeof err === 'object' && 'code' in err
|
|
41
|
+
? String(err.code)
|
|
42
|
+
: '';
|
|
43
|
+
if (code === 'ENOENT')
|
|
44
|
+
return null;
|
|
45
|
+
throw err;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
function looksLikeResolveConfig(o) {
|
|
49
|
+
return 'ssotPrefer' in o
|
|
50
|
+
|| 'generatedGlobs' in o
|
|
51
|
+
|| 'pathTypeHints' in o
|
|
52
|
+
|| 'openApiAssembly' in o
|
|
53
|
+
|| 'maxRefDepth' in o;
|
|
54
|
+
}
|
|
55
|
+
function looksLikeReaders(o) {
|
|
56
|
+
const r = o;
|
|
57
|
+
return typeof r.fs === 'function'
|
|
58
|
+
|| typeof r.api === 'function'
|
|
59
|
+
|| typeof r.db === 'function'
|
|
60
|
+
|| typeof r.registry === 'function';
|
|
61
|
+
}
|
|
62
|
+
function normalizeAutoDerive(raw) {
|
|
63
|
+
if (raw === true)
|
|
64
|
+
return { readers: { fs: defaultFsReader } };
|
|
65
|
+
if (!raw || raw === false || typeof raw !== 'object')
|
|
66
|
+
return null;
|
|
67
|
+
const o = raw;
|
|
68
|
+
const cfg = {};
|
|
69
|
+
if (o.resolveConfig && typeof o.resolveConfig === 'object')
|
|
70
|
+
cfg.resolveConfig = o.resolveConfig;
|
|
71
|
+
if (o.readers && typeof o.readers === 'object') {
|
|
72
|
+
if (looksLikeReaders(o.readers)) {
|
|
73
|
+
cfg.readers = { ...o.readers };
|
|
74
|
+
}
|
|
75
|
+
else if (looksLikeResolveConfig(o.readers)) {
|
|
76
|
+
cfg.resolveConfig = o.readers;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
if (!cfg.readers)
|
|
80
|
+
cfg.readers = {};
|
|
81
|
+
if (typeof cfg.readers.fs !== 'function')
|
|
82
|
+
cfg.readers.fs = defaultFsReader;
|
|
83
|
+
return cfg;
|
|
84
|
+
}
|
|
85
|
+
function rawRecord(args) {
|
|
86
|
+
if (!args || typeof args !== 'object' || Array.isArray(args))
|
|
87
|
+
return null;
|
|
88
|
+
return args;
|
|
89
|
+
}
|
|
90
|
+
function hostSuppliedArtifacts(args) {
|
|
91
|
+
const a = rawRecord(args);
|
|
92
|
+
return !!(a && Array.isArray(a.artifacts));
|
|
93
|
+
}
|
|
94
|
+
function targetFromArgs(a) {
|
|
95
|
+
if (typeof a.path === 'string' && a.path.length > 0)
|
|
96
|
+
return { kind: 'fs', key: a.path };
|
|
97
|
+
if (typeof a.url === 'string' && a.url.length > 0)
|
|
98
|
+
return { kind: 'api', key: a.url };
|
|
99
|
+
if (typeof a.endpoint === 'string' && a.endpoint.length > 0)
|
|
100
|
+
return { kind: 'api', key: a.endpoint };
|
|
101
|
+
if (typeof a.table === 'string' && a.table.length > 0) {
|
|
102
|
+
const id = a.id != null ? String(a.id) : '';
|
|
103
|
+
return { kind: 'db', key: id ? `${a.table}/${id}` : a.table };
|
|
104
|
+
}
|
|
105
|
+
if (typeof a.key === 'string' && a.key.length > 0)
|
|
106
|
+
return { kind: 'registry', key: a.key };
|
|
107
|
+
return null;
|
|
108
|
+
}
|
|
109
|
+
function intendedAfter(a, before) {
|
|
110
|
+
for (const k of ['contents', 'content', 'new_content', 'new_contents']) {
|
|
111
|
+
if (typeof a[k] === 'string')
|
|
112
|
+
return a[k];
|
|
113
|
+
}
|
|
114
|
+
const oldS = typeof a.old_string === 'string' ? a.old_string : null;
|
|
115
|
+
const newS = typeof a.new_string === 'string' ? a.new_string : null;
|
|
116
|
+
if (newS == null)
|
|
117
|
+
return null;
|
|
118
|
+
if (typeof before === 'string' && oldS && oldS.length > 0 && before.includes(oldS)) {
|
|
119
|
+
return before.replace(oldS, newS);
|
|
120
|
+
}
|
|
121
|
+
if (newS.length > 0)
|
|
122
|
+
return newS;
|
|
123
|
+
return null;
|
|
124
|
+
}
|
|
125
|
+
function typeForTarget(target, a, resolveConfig) {
|
|
126
|
+
if (typeof a.type === 'string' && a.type) {
|
|
127
|
+
const t = a.type;
|
|
128
|
+
if (t === 'openapi' || t === 'graphql' || t === 'grpc' || t === 'asyncapi' || t === 'mcp_manifest') {
|
|
129
|
+
return t;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
if (target.kind === 'fs') {
|
|
133
|
+
const hinted = resolveConfig && resolveConfig.pathTypeHints
|
|
134
|
+
? resolveConfig.pathTypeHints[target.key]
|
|
135
|
+
: undefined;
|
|
136
|
+
if (hinted)
|
|
137
|
+
return hinted;
|
|
138
|
+
return (0, artifact_resolver_js_1.classifyByName)(target.key);
|
|
139
|
+
}
|
|
140
|
+
return null;
|
|
141
|
+
}
|
|
142
|
+
async function withTimeout(p, ms) {
|
|
143
|
+
let timer;
|
|
144
|
+
try {
|
|
145
|
+
return await Promise.race([
|
|
146
|
+
p,
|
|
147
|
+
new Promise((_, reject) => {
|
|
148
|
+
timer = setTimeout(() => {
|
|
149
|
+
const e = new Error(`autoDerive reader timed out after ${ms}ms`);
|
|
150
|
+
e.name = 'TimeoutError';
|
|
151
|
+
reject(e);
|
|
152
|
+
}, Math.max(1, ms));
|
|
153
|
+
}),
|
|
154
|
+
]);
|
|
155
|
+
}
|
|
156
|
+
finally {
|
|
157
|
+
if (timer)
|
|
158
|
+
clearTimeout(timer);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
async function readCurrent(readers, target) {
|
|
162
|
+
const fn = readers[target.kind];
|
|
163
|
+
if (typeof fn !== 'function') {
|
|
164
|
+
const err = new Error(`autoDerive: no ${target.kind} reader`);
|
|
165
|
+
err.code = 'NO_READER';
|
|
166
|
+
throw err;
|
|
167
|
+
}
|
|
168
|
+
return withTimeout(Promise.resolve(fn(target.key)), exports.AUTO_DERIVE_READ_TIMEOUT_MS);
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Derive a before/after pair onto the call descriptor when the host did not supply artifacts.
|
|
172
|
+
* Never throws out — reader failures return the bound call with fragment_only + failed.cause.
|
|
173
|
+
*/
|
|
174
|
+
async function runAutoDerive(args) {
|
|
175
|
+
const bound = args.bound;
|
|
176
|
+
if (hostSuppliedArtifacts(args.rawArgs)) {
|
|
177
|
+
return {
|
|
178
|
+
call: bound,
|
|
179
|
+
derivation: { mode: 'host_supplied', targets: [] },
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
const a = rawRecord(args.rawArgs) || rawRecord(bound.arguments);
|
|
183
|
+
if (!a) {
|
|
184
|
+
return { call: bound, derivation: { mode: 'fragment_only', targets: [] } };
|
|
185
|
+
}
|
|
186
|
+
const target = targetFromArgs(a);
|
|
187
|
+
if (!target) {
|
|
188
|
+
return { call: bound, derivation: { mode: 'fragment_only', targets: [] } };
|
|
189
|
+
}
|
|
190
|
+
const type = typeForTarget(target, a, args.cfg.resolveConfig);
|
|
191
|
+
if (!type) {
|
|
192
|
+
return {
|
|
193
|
+
call: bound,
|
|
194
|
+
derivation: {
|
|
195
|
+
mode: 'fragment_only',
|
|
196
|
+
targets: [target],
|
|
197
|
+
notes: [{ target: target.key, note: 'not_contract_path' }],
|
|
198
|
+
},
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
const readers = args.cfg.readers || { fs: defaultFsReader };
|
|
202
|
+
let before;
|
|
203
|
+
try {
|
|
204
|
+
before = await readCurrent(readers, target);
|
|
205
|
+
}
|
|
206
|
+
catch (err) {
|
|
207
|
+
const name = err && typeof err === 'object' && 'name' in err
|
|
208
|
+
? String(err.name)
|
|
209
|
+
: '';
|
|
210
|
+
const cause = name === 'TimeoutError' ? 'reader_timeout' : 'reader_threw';
|
|
211
|
+
emit(args.config, { type: 'derive_failed', at: iso(), cause });
|
|
212
|
+
return {
|
|
213
|
+
call: bound,
|
|
214
|
+
derivation: {
|
|
215
|
+
mode: 'fragment_only',
|
|
216
|
+
targets: [target],
|
|
217
|
+
notes: [{
|
|
218
|
+
target: target.key,
|
|
219
|
+
note: cause === 'reader_timeout' ? 'reader_timeout' : 'reader_threw',
|
|
220
|
+
}],
|
|
221
|
+
},
|
|
222
|
+
failed: { cause },
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
const after = intendedAfter(a, before);
|
|
226
|
+
if (after == null) {
|
|
227
|
+
return {
|
|
228
|
+
call: bound,
|
|
229
|
+
derivation: { mode: 'fragment_only', targets: [target] },
|
|
230
|
+
};
|
|
231
|
+
}
|
|
232
|
+
const notes = [];
|
|
233
|
+
if (before === null) {
|
|
234
|
+
notes.push({ target: target.key, note: 'before_unavailable' });
|
|
235
|
+
// Absence must not erase a binder-lifted fragment pair (old_string/new_string).
|
|
236
|
+
if (Array.isArray(bound.artifacts) && bound.artifacts.length > 0) {
|
|
237
|
+
return {
|
|
238
|
+
call: bound,
|
|
239
|
+
derivation: {
|
|
240
|
+
mode: 'fragment_only',
|
|
241
|
+
targets: [target],
|
|
242
|
+
notes,
|
|
243
|
+
},
|
|
244
|
+
};
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
const derived = {
|
|
248
|
+
id: `${type}:${target.key}`,
|
|
249
|
+
type,
|
|
250
|
+
before,
|
|
251
|
+
after,
|
|
252
|
+
source: exports.AUTO_DERIVE_SOURCE,
|
|
253
|
+
};
|
|
254
|
+
const call = {
|
|
255
|
+
...bound,
|
|
256
|
+
artifacts: [derived],
|
|
257
|
+
};
|
|
258
|
+
return {
|
|
259
|
+
call,
|
|
260
|
+
derivation: {
|
|
261
|
+
mode: 'auto_derived',
|
|
262
|
+
targets: [target],
|
|
263
|
+
...(notes.length ? { notes } : {}),
|
|
264
|
+
},
|
|
265
|
+
};
|
|
266
|
+
}
|
|
267
|
+
function attachDerivation(outcome, derivation) {
|
|
268
|
+
if (!derivation)
|
|
269
|
+
return outcome;
|
|
270
|
+
return { ...outcome, derivation };
|
|
271
|
+
}
|
|
272
|
+
//# sourceMappingURL=auto-derive.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auto-derive.js","sourceRoot":"","sources":["../../src/auto-derive.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;GAUG;;;AAqEH,0CAUC;AAkBD,kDAgBC;AAoGD,sCAwGC;AAED,4CAMC;AAnUD,qCAA0C;AAC1C,iEAAwD;AAI3C,QAAA,kBAAkB,GAAG,oBAA6B,CAAC;AACnD,QAAA,2BAA2B,GAAG,IAAI,CAAC;AAkDhD,SAAS,GAAG;IACV,OAAO,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;AAClC,CAAC;AAED,SAAS,IAAI,CAAC,MAAmB,EAAE,CAAa;IAC9C,IAAI,MAAM,CAAC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E/E,IAAI,CAAC,UAAU;QAAE,OAAO,OAAO,CAAC;IAChC,OAAO,EAAE,GAAI,OAAkB,EAAE,UAAU,EAAO,CAAC;AACrD,CAAC"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* S6 auto-recheck loop — host-side orchestration AFTER a BLOCK with a remediation_transaction.
|
|
3
|
+
*
|
|
4
|
+
* Default OFF. The frozen guardToolCall is unchanged; this wraps it. The guard never writes
|
|
5
|
+
* artifacts: the host's applyFix applies the fix (honesty line). After applyFix true, artifacts
|
|
6
|
+
* are re-resolved FRESH (resolve() from artifact-resolver when resolveInput is supplied, else
|
|
7
|
+
* the host-updated call / rebind).
|
|
8
|
+
*
|
|
9
|
+
* recheck_scope is an OUTPUT on the BLOCK envelope (app remediation-transaction.js). The
|
|
10
|
+
* preflight request does not accept a scope hint (measured SDK / authorizeChangeSet) — so
|
|
11
|
+
* each attempt is a FULL re-preflight. Noted, not faked.
|
|
12
|
+
*
|
|
13
|
+
* Nothing here enters a fingerprint preimage (host orchestration only).
|
|
14
|
+
*/
|
|
15
|
+
import type { GuardConfig, GuardOutcome, ToolCallDescriptor, ExecuteFactory, GuardToolCallContext } from './types.js';
|
|
16
|
+
import type { RemediationTransactionView } from './remediation-loop-attestation.js';
|
|
17
|
+
import type { ResolveInput, ResolveConfig } from './artifact-resolver.js';
|
|
18
|
+
/** Hard cap on RE-preflights per original call. */
|
|
19
|
+
export declare const AUTO_RECHECK_MAX_CAP = 3;
|
|
20
|
+
export type RecheckTrailEntry = {
|
|
21
|
+
attempt: number;
|
|
22
|
+
decision_id: string | null;
|
|
23
|
+
fingerprint: string | null;
|
|
24
|
+
execution_action: string | null;
|
|
25
|
+
};
|
|
26
|
+
export type RecheckStopReason = 'no_progress' | 'apply_fix_declined' | 'apply_fix_threw' | 'exhausted';
|
|
27
|
+
export type RecheckObservation = {
|
|
28
|
+
recheck_trail?: ReadonlyArray<RecheckTrailEntry>;
|
|
29
|
+
/** 849 metric feed. Present only when the loop ran. value true iff a recheck landed allow-class. */
|
|
30
|
+
fixed_after_block?: {
|
|
31
|
+
value: true | null;
|
|
32
|
+
attempt_count: number | null;
|
|
33
|
+
};
|
|
34
|
+
recheck_stop_reason?: RecheckStopReason;
|
|
35
|
+
};
|
|
36
|
+
export type AutoRecheckApplyFixContext = {
|
|
37
|
+
call: ToolCallDescriptor;
|
|
38
|
+
attempt: number;
|
|
39
|
+
outcome: GuardOutcome<unknown>;
|
|
40
|
+
};
|
|
41
|
+
export type AutoRecheckConfig = {
|
|
42
|
+
/**
|
|
43
|
+
* Bound on RE-preflights per original call. Allowed 1–3; values above 3 clamp to 3.
|
|
44
|
+
* Values below 1 disable the loop.
|
|
45
|
+
*/
|
|
46
|
+
maxAttempts: number;
|
|
47
|
+
/**
|
|
48
|
+
* HOST applies the fix. The guard never writes artifacts.
|
|
49
|
+
* false / throw → loop ends, original BLOCK stands.
|
|
50
|
+
*/
|
|
51
|
+
applyFix: (remediation: RemediationTransactionView, context: AutoRecheckApplyFixContext) => boolean | Promise<boolean>;
|
|
52
|
+
/**
|
|
53
|
+
* Optional. After applyFix true, produce a fresh git snapshot for resolve() (CAP-202).
|
|
54
|
+
* When absent, the loop re-runs `rebind` / uses artifacts the host attached on context.call.
|
|
55
|
+
*/
|
|
56
|
+
resolveInput?: () => ResolveInput | Promise<ResolveInput>;
|
|
57
|
+
resolveConfig?: ResolveConfig;
|
|
58
|
+
};
|
|
59
|
+
export declare function clampMaxAttempts(n: unknown): number;
|
|
60
|
+
export declare function normalizeAutoRecheck(raw: unknown): AutoRecheckConfig | null;
|
|
61
|
+
export type AutoRecheckLoopArgs<T> = {
|
|
62
|
+
call: ToolCallDescriptor;
|
|
63
|
+
factory: ExecuteFactory<T>;
|
|
64
|
+
config: GuardConfig;
|
|
65
|
+
callContext?: GuardToolCallContext;
|
|
66
|
+
rebind: () => ToolCallDescriptor | Promise<ToolCallDescriptor>;
|
|
67
|
+
/** Re-collect freshness VALUES from the FRESH call (full re-preflight). */
|
|
68
|
+
refreshContext?: (call: ToolCallDescriptor) => Promise<GuardToolCallContext | undefined>;
|
|
69
|
+
};
|
|
70
|
+
/**
|
|
71
|
+
* First call is always a normal guardToolCall. The loop runs only when autoRecheck is
|
|
72
|
+
* normalized (applyFix present, maxAttempts in 1–3) AND the outcome is BLOCK with a
|
|
73
|
+
* remediation_transaction.
|
|
74
|
+
*/
|
|
75
|
+
export declare function runAutoRecheckLoop<T>(args: AutoRecheckLoopArgs<T>): Promise<GuardOutcome<T>>;
|
|
76
|
+
//# sourceMappingURL=auto-recheck.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auto-recheck.d.ts","sourceRoot":"","sources":["../../src/auto-recheck.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAGH,OAAO,KAAK,EACV,WAAW,EACX,YAAY,EAEZ,kBAAkB,EAClB,cAAc,EAEd,oBAAoB,EAGrB,MAAM,YAAY,CAAC;AAEpB,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,mCAAmC,CAAC;AAEpF,OAAO,KAAK,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAE1E,mDAAmD;AACnD,eAAO,MAAM,oBAAoB,IAAI,CAAC;AAEtC,MAAM,MAAM,iBAAiB,GAAG;IAC9B,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,gBAAgB,EAAE,MAAM,GAAG,IAAI,CAAC;CACjC,CAAC;AAEF,MAAM,MAAM,iBAAiB,GACzB,aAAa,GACb,oBAAoB,GACpB,iBAAiB,GACjB,WAAW,CAAC;AAEhB,MAAM,MAAM,kBAAkB,GAAG;IAC/B,aAAa,CAAC,EAAE,aAAa,CAAC,iBAAiB,CAAC,CAAC;IACjD,oGAAoG;IACpG,iBAAiB,CAAC,EAAE;QAAE,KAA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