martin-loop 0.1.4 → 1.3.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/CODE_OF_CONDUCT.md +32 -0
- package/README.md +172 -227
- package/demo/seeded-workspace/README.md +35 -0
- package/demo/seeded-workspace/TASKS.md +29 -0
- package/demo/seeded-workspace/martin.config.yaml +11 -0
- package/demo/seeded-workspace/package.json +8 -0
- package/demo/seeded-workspace/src/invoice-summary.js +11 -0
- package/demo/seeded-workspace/test/invoice-summary.test.js +20 -0
- package/dist/bin/martin-loop.js +0 -0
- package/dist/vendor/adapters/claude-cli.d.ts +19 -4
- package/dist/vendor/adapters/claude-cli.js +55 -24
- package/dist/vendor/adapters/cli-bridge.d.ts +1 -0
- package/dist/vendor/adapters/cli-bridge.js +154 -28
- package/dist/vendor/adapters/counter.d.ts +1 -0
- package/dist/vendor/adapters/counter.js +4 -0
- package/dist/vendor/adapters/git-baseline.d.ts +50 -0
- package/dist/vendor/adapters/git-baseline.js +233 -0
- package/dist/vendor/adapters/index.d.ts +1 -0
- package/dist/vendor/adapters/index.js +1 -0
- package/dist/vendor/adapters/openrouter-adapter.d.ts +15 -0
- package/dist/vendor/adapters/openrouter-adapter.js +302 -0
- package/dist/vendor/adapters/usage.d.ts +48 -0
- package/dist/vendor/adapters/usage.js +66 -0
- package/dist/vendor/adapters/verifier-only.d.ts +7 -0
- package/dist/vendor/adapters/verifier-only.js +57 -0
- package/dist/vendor/cli/bin/exit.d.ts +12 -0
- package/dist/vendor/cli/bin/exit.js +28 -0
- package/dist/vendor/cli/commands/analyze.d.ts +5 -0
- package/dist/vendor/cli/commands/analyze.js +58 -0
- package/dist/vendor/cli/commands/audit-log-verify.d.ts +34 -0
- package/dist/vendor/cli/commands/audit-log-verify.js +99 -0
- package/dist/vendor/cli/commands/audit.d.ts +8 -0
- package/dist/vendor/cli/commands/audit.js +199 -0
- package/dist/vendor/cli/commands/corpus.d.ts +5 -0
- package/dist/vendor/cli/commands/corpus.js +60 -0
- package/dist/vendor/cli/commands/doctor.d.ts +8 -0
- package/dist/vendor/cli/commands/doctor.js +219 -0
- package/dist/vendor/cli/commands/explain.d.ts +17 -0
- package/dist/vendor/cli/commands/explain.js +176 -0
- package/dist/vendor/cli/commands/export.d.ts +5 -0
- package/dist/vendor/cli/commands/export.js +60 -0
- package/dist/vendor/cli/commands/governance.d.ts +8 -0
- package/dist/vendor/cli/commands/governance.js +95 -0
- package/dist/vendor/cli/commands/improve.d.ts +18 -0
- package/dist/vendor/cli/commands/improve.js +396 -0
- package/dist/vendor/cli/commands/init.d.ts +8 -0
- package/dist/vendor/cli/commands/init.js +281 -0
- package/dist/vendor/cli/commands/migration.d.ts +8 -0
- package/dist/vendor/cli/commands/migration.js +67 -0
- package/dist/vendor/cli/commands/prior.d.ts +23 -0
- package/dist/vendor/cli/commands/prior.js +145 -0
- package/dist/vendor/cli/commands/resume.d.ts +21 -0
- package/dist/vendor/cli/commands/resume.js +73 -0
- package/dist/vendor/cli/commands/verify.d.ts +6 -0
- package/dist/vendor/cli/commands/verify.js +43 -0
- package/dist/vendor/cli/index.d.ts +6 -1
- package/dist/vendor/cli/index.js +124 -7
- package/dist/vendor/cli/research/public-corpus.d.ts +43 -0
- package/dist/vendor/cli/research/public-corpus.js +151 -0
- package/dist/vendor/cli/ui/error-card.d.ts +38 -0
- package/dist/vendor/cli/ui/error-card.js +103 -0
- package/dist/vendor/cli/ui/mission-brief.d.ts +41 -0
- package/dist/vendor/cli/ui/mission-brief.js +173 -0
- package/dist/vendor/cli/ui/summary-card.d.ts +34 -0
- package/dist/vendor/cli/ui/summary-card.js +102 -0
- package/dist/vendor/contracts/audit.d.ts +46 -0
- package/dist/vendor/contracts/audit.js +360 -0
- package/dist/vendor/contracts/index.d.ts +3 -1
- package/dist/vendor/contracts/post-phase15.d.ts +240 -0
- package/dist/vendor/contracts/post-phase15.js +166 -0
- package/dist/vendor/core/agent/mandates.d.ts +46 -0
- package/dist/vendor/core/agent/mandates.js +178 -0
- package/dist/vendor/core/agent/receipts.d.ts +38 -0
- package/dist/vendor/core/agent/receipts.js +131 -0
- package/dist/vendor/core/agent/signing.d.ts +17 -0
- package/dist/vendor/core/agent/signing.js +91 -0
- package/dist/vendor/core/attestation/sign.d.ts +25 -0
- package/dist/vendor/core/attestation/sign.js +216 -0
- package/dist/vendor/core/autonomy/autonomous-promotion.d.ts +120 -0
- package/dist/vendor/core/autonomy/autonomous-promotion.js +346 -0
- package/dist/vendor/core/autonomy/envelope-v2.d.ts +29 -0
- package/dist/vendor/core/autonomy/envelope-v2.js +60 -0
- package/dist/vendor/core/autonomy/envelope.d.ts +17 -0
- package/dist/vendor/core/autonomy/envelope.js +27 -0
- package/dist/vendor/core/autonomy/escalation-ledger.d.ts +20 -0
- package/dist/vendor/core/autonomy/escalation-ledger.js +18 -0
- package/dist/vendor/core/autonomy/resume.d.ts +15 -0
- package/dist/vendor/core/autonomy/resume.js +23 -0
- package/dist/vendor/core/circuit/circuit-breaker.d.ts +60 -0
- package/dist/vendor/core/circuit/circuit-breaker.js +143 -0
- package/dist/vendor/core/compiler.d.ts +2 -0
- package/dist/vendor/core/compiler.js +10 -4
- package/dist/vendor/core/context-distillation.d.ts +3 -0
- package/dist/vendor/core/context-distillation.js +44 -0
- package/dist/vendor/core/context-flow/compile-context.d.ts +8 -0
- package/dist/vendor/core/context-flow/compile-context.js +111 -0
- package/dist/vendor/core/context-flow/entities.d.ts +2 -0
- package/dist/vendor/core/context-flow/entities.js +44 -0
- package/dist/vendor/core/context-flow/evaluate-policy.d.ts +2 -0
- package/dist/vendor/core/context-flow/evaluate-policy.js +42 -0
- package/dist/vendor/core/context-flow/index.d.ts +11 -0
- package/dist/vendor/core/context-flow/index.js +24 -0
- package/dist/vendor/core/context-flow/labels.d.ts +3 -0
- package/dist/vendor/core/context-flow/labels.js +17 -0
- package/dist/vendor/core/context-flow/normalizer.d.ts +9 -0
- package/dist/vendor/core/context-flow/normalizer.js +69 -0
- package/dist/vendor/core/context-flow/profiles.d.ts +33 -0
- package/dist/vendor/core/context-flow/profiles.js +36 -0
- package/dist/vendor/core/context-flow/redaction.d.ts +1 -0
- package/dist/vendor/core/context-flow/redaction.js +6 -0
- package/dist/vendor/core/context-flow/sensitivity.d.ts +2 -0
- package/dist/vendor/core/context-flow/sensitivity.js +27 -0
- package/dist/vendor/core/context-flow/sync-preview.d.ts +2 -0
- package/dist/vendor/core/context-flow/sync-preview.js +22 -0
- package/dist/vendor/core/context-flow/token-estimator.d.ts +3 -0
- package/dist/vendor/core/context-flow/token-estimator.js +13 -0
- package/dist/vendor/core/context-flow/types.d.ts +91 -0
- package/dist/vendor/core/context-flow/types.js +2 -0
- package/dist/vendor/core/context-integrity.d.ts +26 -0
- package/dist/vendor/core/context-integrity.js +56 -0
- package/dist/vendor/core/context-utility.d.ts +47 -0
- package/dist/vendor/core/context-utility.js +405 -0
- package/dist/vendor/core/cost/pipeline.d.ts +92 -0
- package/dist/vendor/core/cost/pipeline.js +141 -0
- package/dist/vendor/core/cost/tagged-cost.d.ts +27 -0
- package/dist/vendor/core/cost/tagged-cost.js +55 -0
- package/dist/vendor/core/cost-governor.d.ts +2 -0
- package/dist/vendor/core/cost-governor.js +50 -0
- package/dist/vendor/core/cve/cve-check.d.ts +80 -0
- package/dist/vendor/core/cve/cve-check.js +172 -0
- package/dist/vendor/core/digital-twin/index.d.ts +27 -0
- package/dist/vendor/core/digital-twin/index.js +90 -0
- package/dist/vendor/core/drift/drift-graph.d.ts +47 -0
- package/dist/vendor/core/drift/drift-graph.js +100 -0
- package/dist/vendor/core/drift/objective-lock.d.ts +69 -0
- package/dist/vendor/core/drift/objective-lock.js +88 -0
- package/dist/vendor/core/drift/scope.d.ts +46 -0
- package/dist/vendor/core/drift/scope.js +102 -0
- package/dist/vendor/core/drift/signature-lock.d.ts +48 -0
- package/dist/vendor/core/drift/signature-lock.js +202 -0
- package/dist/vendor/core/drift/stale-proof-gate.d.ts +21 -0
- package/dist/vendor/core/drift/stale-proof-gate.js +19 -0
- package/dist/vendor/core/eval/known-bad-world-runner.d.ts +24 -0
- package/dist/vendor/core/eval/known-bad-world-runner.js +256 -0
- package/dist/vendor/core/evidence/claim-audit.d.ts +18 -0
- package/dist/vendor/core/evidence/claim-audit.js +89 -0
- package/dist/vendor/core/exit-intelligence.d.ts +2 -0
- package/dist/vendor/core/exit-intelligence.js +58 -0
- package/dist/vendor/core/explain/formatter.d.ts +42 -0
- package/dist/vendor/core/explain/formatter.js +171 -0
- package/dist/vendor/core/explain/timeline.d.ts +29 -0
- package/dist/vendor/core/explain/timeline.js +213 -0
- package/dist/vendor/core/failure-taxonomy.d.ts +2 -0
- package/dist/vendor/core/failure-taxonomy.js +76 -0
- package/dist/vendor/core/gateway/index.d.ts +10 -0
- package/dist/vendor/core/gateway/index.js +12 -0
- package/dist/vendor/core/gateway/registry.d.ts +40 -0
- package/dist/vendor/core/gateway/registry.js +97 -0
- package/dist/vendor/core/gateway/transport.d.ts +31 -0
- package/dist/vendor/core/gateway/transport.js +82 -0
- package/dist/vendor/core/gateway/vault.d.ts +19 -0
- package/dist/vendor/core/gateway/vault.js +29 -0
- package/dist/vendor/core/graph/adapters.d.ts +43 -0
- package/dist/vendor/core/graph/adapters.js +91 -0
- package/dist/vendor/core/graph/hotspots.d.ts +22 -0
- package/dist/vendor/core/graph/hotspots.js +30 -0
- package/dist/vendor/core/graph/index.d.ts +1 -0
- package/dist/vendor/core/graph/index.js +2 -0
- package/dist/vendor/core/honey/honey-tokens.d.ts +32 -0
- package/dist/vendor/core/honey/honey-tokens.js +44 -0
- package/dist/vendor/core/index.d.ts +7 -4
- package/dist/vendor/core/index.js +222 -64
- package/dist/vendor/core/learning/bayesian-update.d.ts +31 -0
- package/dist/vendor/core/learning/bayesian-update.js +60 -0
- package/dist/vendor/core/learning/prior-sets.d.ts +42 -0
- package/dist/vendor/core/learning/prior-sets.js +111 -0
- package/dist/vendor/core/learning/promotion-gate.d.ts +17 -0
- package/dist/vendor/core/learning/promotion-gate.js +23 -0
- package/dist/vendor/core/leash/blast-radius.d.ts +42 -0
- package/dist/vendor/core/leash/blast-radius.js +156 -0
- package/dist/vendor/core/leash/policy-leash.d.ts +31 -0
- package/dist/vendor/core/leash/policy-leash.js +117 -0
- package/dist/vendor/core/memo/memo.d.ts +63 -0
- package/dist/vendor/core/memo/memo.js +97 -0
- package/dist/vendor/core/memory/learning-pipeline.d.ts +154 -0
- package/dist/vendor/core/memory/learning-pipeline.js +391 -0
- package/dist/vendor/core/memory/palace.d.ts +84 -0
- package/dist/vendor/core/memory/palace.js +379 -0
- package/dist/vendor/core/merge/ast-merge.d.ts +22 -0
- package/dist/vendor/core/merge/ast-merge.js +350 -0
- package/dist/vendor/core/merge/text-merge.d.ts +12 -0
- package/dist/vendor/core/merge/text-merge.js +182 -0
- package/dist/vendor/core/otel/tracer.d.ts +45 -0
- package/dist/vendor/core/otel/tracer.js +116 -0
- package/dist/vendor/core/parallel/parallel-attempts.d.ts +28 -0
- package/dist/vendor/core/parallel/parallel-attempts.js +41 -0
- package/dist/vendor/core/parallel/scorer.d.ts +24 -0
- package/dist/vendor/core/parallel/scorer.js +65 -0
- package/dist/vendor/core/pattern-detection.d.ts +64 -0
- package/dist/vendor/core/pattern-detection.js +108 -0
- package/dist/vendor/core/persistence/checkpoint.d.ts +44 -0
- package/dist/vendor/core/persistence/checkpoint.js +156 -0
- package/dist/vendor/core/persistence/cleanup.d.ts +22 -0
- package/dist/vendor/core/persistence/cleanup.js +131 -0
- package/dist/vendor/core/persistence/index.d.ts +2 -0
- package/dist/vendor/core/persistence/index.js +1 -0
- package/dist/vendor/core/persistence/runs-reader.d.ts +52 -0
- package/dist/vendor/core/persistence/runs-reader.js +84 -0
- package/dist/vendor/core/persistence/store.d.ts +6 -1
- package/dist/vendor/core/persistence/store.js +5 -0
- package/dist/vendor/core/policy/file-touch-quota.d.ts +60 -0
- package/dist/vendor/core/policy/file-touch-quota.js +105 -0
- package/dist/vendor/core/policy/policy-loader.d.ts +30 -0
- package/dist/vendor/core/policy/policy-loader.js +170 -0
- package/dist/vendor/core/policy/policy-schema.d.ts +55 -0
- package/dist/vendor/core/policy/policy-schema.js +78 -0
- package/dist/vendor/core/policy.d.ts +6 -0
- package/dist/vendor/core/probe/probe.d.ts +49 -0
- package/dist/vendor/core/probe/probe.js +115 -0
- package/dist/vendor/core/proof/patch-proof.d.ts +58 -0
- package/dist/vendor/core/proof/patch-proof.js +84 -0
- package/dist/vendor/core/proof/semantic-probe.d.ts +25 -0
- package/dist/vendor/core/proof/semantic-probe.js +82 -0
- package/dist/vendor/core/recovery/failure-mode-runner.d.ts +29 -0
- package/dist/vendor/core/recovery/failure-mode-runner.js +39 -0
- package/dist/vendor/core/red-blue/red-phase.d.ts +64 -0
- package/dist/vendor/core/red-blue/red-phase.js +141 -0
- package/dist/vendor/core/red-blue/risk-tiers.d.ts +22 -0
- package/dist/vendor/core/red-blue/risk-tiers.js +33 -0
- package/dist/vendor/core/replay/replay.d.ts +85 -0
- package/dist/vendor/core/replay/replay.js +109 -0
- package/dist/vendor/core/router/engine.d.ts +54 -0
- package/dist/vendor/core/router/engine.js +131 -0
- package/dist/vendor/core/router/index.d.ts +1 -0
- package/dist/vendor/core/router/index.js +2 -0
- package/dist/vendor/core/router/trust-calibration.d.ts +57 -0
- package/dist/vendor/core/router/trust-calibration.js +127 -0
- package/dist/vendor/core/run-martin.d.ts +2 -0
- package/dist/vendor/core/run-martin.js +287 -0
- package/dist/vendor/core/security/cve-scanner.d.ts +62 -0
- package/dist/vendor/core/security/cve-scanner.js +178 -0
- package/dist/vendor/core/sentinel/efficiency-sentinel.d.ts +29 -0
- package/dist/vendor/core/sentinel/efficiency-sentinel.js +30 -0
- package/dist/vendor/core/sentinel/progress-guard.d.ts +35 -0
- package/dist/vendor/core/sentinel/progress-guard.js +46 -0
- package/dist/vendor/core/siem/siem-emitter.d.ts +49 -0
- package/dist/vendor/core/siem/siem-emitter.js +157 -0
- package/dist/vendor/core/strategy/attempt-brief.d.ts +22 -0
- package/dist/vendor/core/strategy/attempt-brief.js +89 -0
- package/dist/vendor/core/summarize/diff-summary.d.ts +35 -0
- package/dist/vendor/core/summarize/diff-summary.js +204 -0
- package/dist/vendor/core/surface-signals.d.ts +21 -0
- package/dist/vendor/core/surface-signals.js +139 -0
- package/dist/vendor/core/truth/truth-wall.d.ts +51 -0
- package/dist/vendor/core/truth/truth-wall.js +69 -0
- package/dist/vendor/core/truth-spine.d.ts +26 -0
- package/dist/vendor/core/truth-spine.js +62 -0
- package/dist/vendor/core/types.d.ts +115 -0
- package/dist/vendor/core/types.js +2 -0
- package/dist/vendor/core/verification/tiered-verify.d.ts +17 -0
- package/dist/vendor/core/verification/tiered-verify.js +29 -0
- package/dist/vendor/core/verifier-pyramid.d.ts +32 -0
- package/dist/vendor/core/verifier-pyramid.js +111 -0
- package/dist/vendor/core/workflow-artifacts.d.ts +99 -0
- package/dist/vendor/core/workflow-artifacts.js +668 -0
- package/dist/vendor/core/wrap/supervised-run.d.ts +96 -0
- package/dist/vendor/core/wrap/supervised-run.js +178 -0
- package/docs/assets/cli-animated.svg +139 -0
- package/docs/assets/cli-static.svg +34 -0
- package/docs/assets/github-hero-v2.svg +23 -0
- package/docs/assets/martin-raplph.png.jpg +0 -0
- package/docs/assets/martinloop-logo.png +0 -0
- package/docs/assets/nvidia-inception-program-light.png +0 -0
- package/docs/assets/nvidia-inception-program.png +0 -0
- package/docs/assets/phase3c-sidesidebyside-demo.html +228 -0
- package/docs/assets/side-by-side.svg +134 -0
- package/docs/oss/CLAUDE-CODE-WALKTHROUGH.md +142 -0
- package/docs/oss/EXAMPLES.md +9 -1
- package/docs/oss/OSS-BOUNDARY-REPORT.json +109 -113
- package/docs/oss/OSS-BOUNDARY-REPORT.md +48 -48
- package/docs/oss/QUICKSTART.md +39 -4
- package/docs/oss/RALPH-LOOP-SAFETY.md +113 -0
- package/docs/oss/README.md +7 -4
- package/docs/oss/RELEASE-SURFACE-REPORT.json +46 -45
- package/docs/oss/RELEASE-SURFACE-REPORT.md +36 -35
- package/package.json +129 -49
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
const EMAIL_RE = /[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}/g;
|
|
2
|
+
const PHONE_RE = /(?:\+?\d{1,3}[ -]?)?(?:\(?\d{3}\)?[ -]?)?\d{3}[ -]?\d{4}/g;
|
|
3
|
+
export function redactText(text) {
|
|
4
|
+
return text.replace(EMAIL_RE, "[REDACTED_EMAIL]").replace(PHONE_RE, "[REDACTED_PHONE]");
|
|
5
|
+
}
|
|
6
|
+
//# sourceMappingURL=redaction.js.map
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
const HIGH_RISK_RECORD_TYPES = new Set(["security_incident", "finance_change"]);
|
|
2
|
+
export function classifySensitivity(record) {
|
|
3
|
+
const reasons = [];
|
|
4
|
+
const matchedEntityTypes = [...new Set(record.entities.map((entity) => entity.type))];
|
|
5
|
+
let level = "low";
|
|
6
|
+
if (HIGH_RISK_RECORD_TYPES.has(record.recordType)) {
|
|
7
|
+
level = "high";
|
|
8
|
+
reasons.push(`Sensitive record type "${record.recordType}" requires approval.`);
|
|
9
|
+
}
|
|
10
|
+
if (matchedEntityTypes.includes("money")) {
|
|
11
|
+
level = level === "high" ? "high" : "moderate";
|
|
12
|
+
reasons.push("Financial values were detected in the source record.");
|
|
13
|
+
}
|
|
14
|
+
if (matchedEntityTypes.includes("email")) {
|
|
15
|
+
level = level === "high" ? "high" : "moderate";
|
|
16
|
+
reasons.push("Direct contact data was detected in the source record.");
|
|
17
|
+
}
|
|
18
|
+
if (reasons.length === 0) {
|
|
19
|
+
reasons.push("No elevated sensitivity indicators were detected.");
|
|
20
|
+
}
|
|
21
|
+
return {
|
|
22
|
+
level,
|
|
23
|
+
reasons,
|
|
24
|
+
matchedEntityTypes
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=sensitivity.js.map
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export function buildSyncPreview(input) {
|
|
2
|
+
const destination = input.destination ?? "martinloop";
|
|
3
|
+
const mode = input.mode ?? "upsert_account_brief";
|
|
4
|
+
const contextProfile = destination.toLowerCase().startsWith("martin") ? "martin360_agent_stage" : "generic_agent_small";
|
|
5
|
+
return {
|
|
6
|
+
destination,
|
|
7
|
+
mode,
|
|
8
|
+
payload: {
|
|
9
|
+
record_id: input.canonicalRecord.recordId,
|
|
10
|
+
record_type: input.canonicalRecord.recordType,
|
|
11
|
+
summary: input.canonicalRecord.summary,
|
|
12
|
+
fields: input.canonicalRecord.fields,
|
|
13
|
+
entities: input.canonicalRecord.entities,
|
|
14
|
+
context_profile: contextProfile
|
|
15
|
+
},
|
|
16
|
+
notes: [
|
|
17
|
+
`Preview builder only: live ${destination} execution depends on a host-wired adapter.`,
|
|
18
|
+
"This payload is the canonical contract consumed by the Martin360 writeback adapter."
|
|
19
|
+
]
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=sync-preview.js.map
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export const DEFAULT_COST_PER_1K_TOKENS = 0.003;
|
|
2
|
+
export function estimateTokens(text) {
|
|
3
|
+
const normalized = text.trim();
|
|
4
|
+
if (!normalized) {
|
|
5
|
+
return 1;
|
|
6
|
+
}
|
|
7
|
+
return Math.max(1, normalized.split(/\s+/).length);
|
|
8
|
+
}
|
|
9
|
+
export function estimateCostUsd(text, costPer1kTokens = DEFAULT_COST_PER_1K_TOKENS) {
|
|
10
|
+
const tokens = estimateTokens(text);
|
|
11
|
+
return Number(((tokens / 1000) * costPer1kTokens).toFixed(6));
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=token-estimator.js.map
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import type { HeadlessProfileName } from "./profiles.js";
|
|
2
|
+
export interface Tenant {
|
|
3
|
+
tenantId: string;
|
|
4
|
+
slug: string;
|
|
5
|
+
name: string;
|
|
6
|
+
createdAt: string;
|
|
7
|
+
metadata: Record<string, unknown>;
|
|
8
|
+
}
|
|
9
|
+
export type ApiKeyScope = "ingest" | "compile" | "policy" | "writeback" | "admin";
|
|
10
|
+
export interface ApiKey {
|
|
11
|
+
apiKeyId: string;
|
|
12
|
+
tenantId: string;
|
|
13
|
+
label: string;
|
|
14
|
+
scopes: ApiKeyScope[];
|
|
15
|
+
createdAt: string;
|
|
16
|
+
expiresAt?: string;
|
|
17
|
+
rotatedAt?: string;
|
|
18
|
+
revokedAt?: string;
|
|
19
|
+
}
|
|
20
|
+
export interface ProvenanceItem {
|
|
21
|
+
sourceName: string;
|
|
22
|
+
evidence: string;
|
|
23
|
+
charStart?: number;
|
|
24
|
+
charEnd?: number;
|
|
25
|
+
}
|
|
26
|
+
export interface Entity {
|
|
27
|
+
type: string;
|
|
28
|
+
value: string;
|
|
29
|
+
confidence: number;
|
|
30
|
+
}
|
|
31
|
+
export interface CanonicalRecord {
|
|
32
|
+
recordId: string;
|
|
33
|
+
recordType: string;
|
|
34
|
+
summary: string;
|
|
35
|
+
fields: Record<string, string>;
|
|
36
|
+
entities: Entity[];
|
|
37
|
+
provenance: ProvenanceItem[];
|
|
38
|
+
metadata: Record<string, unknown>;
|
|
39
|
+
}
|
|
40
|
+
export interface CompileOptions {
|
|
41
|
+
redactPii: boolean;
|
|
42
|
+
includeProvenanceSnippets: boolean;
|
|
43
|
+
deltaMode: boolean;
|
|
44
|
+
maxTokensOverride?: number;
|
|
45
|
+
}
|
|
46
|
+
export interface QcReport {
|
|
47
|
+
completenessScore: number;
|
|
48
|
+
tokenEstimateBefore: number;
|
|
49
|
+
tokenEstimateAfter: number;
|
|
50
|
+
tokenReductionPct: number;
|
|
51
|
+
warnings: string[];
|
|
52
|
+
keptFields: string[];
|
|
53
|
+
}
|
|
54
|
+
export type PolicySeverity = "low" | "medium" | "high";
|
|
55
|
+
export type PolicyMode = "auto" | "human_review" | "approval_required";
|
|
56
|
+
export interface PolicyDecision {
|
|
57
|
+
profile: HeadlessProfileName;
|
|
58
|
+
allowAutonomy: boolean;
|
|
59
|
+
severity: PolicySeverity;
|
|
60
|
+
reasons: string[];
|
|
61
|
+
recommendedMode: PolicyMode;
|
|
62
|
+
requiresApproval: boolean;
|
|
63
|
+
}
|
|
64
|
+
export interface CompileTrace {
|
|
65
|
+
compileId: string;
|
|
66
|
+
policyDecision: PolicyDecision;
|
|
67
|
+
}
|
|
68
|
+
export interface ContextPack {
|
|
69
|
+
profile: HeadlessProfileName;
|
|
70
|
+
compiledContext: string;
|
|
71
|
+
qcReport: QcReport;
|
|
72
|
+
canonicalRecord: CanonicalRecord;
|
|
73
|
+
trace: CompileTrace;
|
|
74
|
+
}
|
|
75
|
+
export type SensitivityLevel = "low" | "moderate" | "high";
|
|
76
|
+
export interface SensitivityClassification {
|
|
77
|
+
level: SensitivityLevel;
|
|
78
|
+
reasons: string[];
|
|
79
|
+
matchedEntityTypes: string[];
|
|
80
|
+
}
|
|
81
|
+
export interface SyncPreviewInput {
|
|
82
|
+
destination?: string;
|
|
83
|
+
canonicalRecord: CanonicalRecord;
|
|
84
|
+
mode?: string;
|
|
85
|
+
}
|
|
86
|
+
export interface SyncPreviewResponse {
|
|
87
|
+
destination: string;
|
|
88
|
+
mode: string;
|
|
89
|
+
payload: Record<string, unknown>;
|
|
90
|
+
notes: string[];
|
|
91
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export type ContextIntegrityVerdict = "clean" | "context_poisoning_warning" | "context_poisoning_block";
|
|
2
|
+
export interface ContextIntegrityPrecheck {
|
|
3
|
+
runId: string;
|
|
4
|
+
attemptIndex: number;
|
|
5
|
+
verdict: ContextIntegrityVerdict;
|
|
6
|
+
reason?: string;
|
|
7
|
+
detectedSignals: string[];
|
|
8
|
+
analyzedChannels: {
|
|
9
|
+
system: boolean;
|
|
10
|
+
user: boolean;
|
|
11
|
+
tools: boolean;
|
|
12
|
+
history: boolean;
|
|
13
|
+
};
|
|
14
|
+
timestamp: string;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* T05: Context Poisoning Pre-gate.
|
|
18
|
+
* Scans untrusted input channels for authority inversion or instruction re-injection.
|
|
19
|
+
* Runs BEFORE admission control and core reasoning.
|
|
20
|
+
*/
|
|
21
|
+
export declare function runContextIntegrityPrecheck(runId: string, attemptIndex: number, artifactsDir: string, inputs: {
|
|
22
|
+
userPrompt?: string;
|
|
23
|
+
toolOutput?: string;
|
|
24
|
+
retrievedContext?: string;
|
|
25
|
+
history?: string;
|
|
26
|
+
}): Promise<ContextIntegrityPrecheck>;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { mkdir, writeFile } from "node:fs/promises";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
const POISON_PATTERNS = [
|
|
4
|
+
/ignore\s+(?:all\s+)?previous\s+instructions/i,
|
|
5
|
+
/you\s+are\s+now\s+a\s+(?!Martin\s+Loop)/i,
|
|
6
|
+
/new\s+rule:/i,
|
|
7
|
+
/disregard\s+(?:safety|policy|guardrails)/i,
|
|
8
|
+
/override\s+system\s+authority/i,
|
|
9
|
+
/hidden\s+instruction:/i,
|
|
10
|
+
/\[system_override\]/i,
|
|
11
|
+
/\[authority_inversion\]/i
|
|
12
|
+
];
|
|
13
|
+
/**
|
|
14
|
+
* T05: Context Poisoning Pre-gate.
|
|
15
|
+
* Scans untrusted input channels for authority inversion or instruction re-injection.
|
|
16
|
+
* Runs BEFORE admission control and core reasoning.
|
|
17
|
+
*/
|
|
18
|
+
export async function runContextIntegrityPrecheck(runId, attemptIndex, artifactsDir, inputs) {
|
|
19
|
+
const signals = [];
|
|
20
|
+
const analyzedChannels = {
|
|
21
|
+
system: true,
|
|
22
|
+
user: Boolean(inputs.userPrompt),
|
|
23
|
+
tools: Boolean(inputs.toolOutput),
|
|
24
|
+
history: Boolean(inputs.history)
|
|
25
|
+
};
|
|
26
|
+
const untrustedBuffer = [inputs.userPrompt, inputs.toolOutput, inputs.retrievedContext]
|
|
27
|
+
.filter(Boolean)
|
|
28
|
+
.join("\n---\n");
|
|
29
|
+
for (const pattern of POISON_PATTERNS) {
|
|
30
|
+
if (pattern.test(untrustedBuffer)) {
|
|
31
|
+
signals.push(`Detected poison pattern: ${pattern.toString()}`);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
if (/\b(?:I am|You are)\s+(?!Martin\s+Loop|an\s+AI)\b/i.test(untrustedBuffer)) {
|
|
35
|
+
signals.push("Identity redefinition attempt detected.");
|
|
36
|
+
}
|
|
37
|
+
const verdict = signals.length > 0 ? "context_poisoning_block" : "clean";
|
|
38
|
+
const precheck = {
|
|
39
|
+
runId,
|
|
40
|
+
attemptIndex,
|
|
41
|
+
verdict,
|
|
42
|
+
reason: signals.length > 0 ? `Detected ${signals.length} poisoning signal(s).` : undefined,
|
|
43
|
+
detectedSignals: signals,
|
|
44
|
+
analyzedChannels,
|
|
45
|
+
timestamp: new Date().toISOString()
|
|
46
|
+
};
|
|
47
|
+
try {
|
|
48
|
+
await mkdir(artifactsDir, { recursive: true });
|
|
49
|
+
await writeFile(join(artifactsDir, "context-integrity-precheck.json"), JSON.stringify(precheck, null, 2), "utf8");
|
|
50
|
+
}
|
|
51
|
+
catch {
|
|
52
|
+
// non-fatal — artifact persistence is best-effort
|
|
53
|
+
}
|
|
54
|
+
return precheck;
|
|
55
|
+
}
|
|
56
|
+
//# sourceMappingURL=context-integrity.js.map
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { PromptPacket } from "./compiler.js";
|
|
2
|
+
export type ContextUtilityBand = "low" | "medium" | "high";
|
|
3
|
+
export type ContextUtilityActionType = "compress_context" | "retain_memory" | "evict_memory" | "refresh_verification" | "investigate_anomalies" | "narrow_surfaces";
|
|
4
|
+
export interface ContextUtilityAction {
|
|
5
|
+
type: ContextUtilityActionType;
|
|
6
|
+
priority: "high" | "medium" | "low";
|
|
7
|
+
message: string;
|
|
8
|
+
drawerIds?: string[];
|
|
9
|
+
}
|
|
10
|
+
export interface ContextUtilitySectionScores {
|
|
11
|
+
contract: number;
|
|
12
|
+
guidance: number;
|
|
13
|
+
memory: number;
|
|
14
|
+
verification: number;
|
|
15
|
+
anomalyGuards: number;
|
|
16
|
+
surfaceFocus: number;
|
|
17
|
+
}
|
|
18
|
+
export interface ContextUtilityEvidenceCounts {
|
|
19
|
+
memoryEntryCount: number;
|
|
20
|
+
retainedMemoryCount: number;
|
|
21
|
+
evictableMemoryCount: number;
|
|
22
|
+
priorFailurePatternCount: number;
|
|
23
|
+
anomalyCount: number;
|
|
24
|
+
requiredCheckCount: number;
|
|
25
|
+
optionalCheckCount: number;
|
|
26
|
+
touchedSurfaceCount: number;
|
|
27
|
+
changedFileCount: number;
|
|
28
|
+
acceptanceCriteriaCount: number;
|
|
29
|
+
}
|
|
30
|
+
export interface ContextUtilityScoreArtifact {
|
|
31
|
+
schemaVersion: "martin.context-utility-score.v1";
|
|
32
|
+
attemptIndex: number;
|
|
33
|
+
utilityScore: number;
|
|
34
|
+
utilityBand: ContextUtilityBand;
|
|
35
|
+
summary: string;
|
|
36
|
+
sectionScores: ContextUtilitySectionScores;
|
|
37
|
+
actions: ContextUtilityAction[];
|
|
38
|
+
evidenceCounts: ContextUtilityEvidenceCounts;
|
|
39
|
+
}
|
|
40
|
+
export interface ComputeContextUtilityScoreInput {
|
|
41
|
+
attemptIndex: number;
|
|
42
|
+
compiledContext: PromptPacket;
|
|
43
|
+
verificationPlan?: unknown;
|
|
44
|
+
patterns?: unknown;
|
|
45
|
+
scopeSurface?: unknown;
|
|
46
|
+
}
|
|
47
|
+
export declare function computeContextUtilityScore(input: ComputeContextUtilityScoreInput): ContextUtilityScoreArtifact;
|