@atbash/sdk 0.19.2-dev.0 → 0.20.0-dev.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.
@@ -1,3 +1,4 @@
1
+ import nodePath from 'node:path';
1
2
  import { Logger } from '@opentelemetry/api-logs';
2
3
 
3
4
  type JudgeEndpointConfig = {
@@ -199,6 +200,8 @@ interface JudgeResult {
199
200
  * Whether the org's protection mode actually acts on a HOLD/BLOCK verdict.
200
201
  * `false` in Monitor mode (verdict is logged for observation, agent is NOT
201
202
  * jailed and the action is not held); `true` in Enforce mode.
203
+ * A plain boolean: an omitted field reads as `false`. `Decision.enforced`
204
+ * keeps "unknown" apart; gate on that, not on this.
202
205
  */
203
206
  enforced: boolean;
204
207
  /** Server-reported protection mode: `off`, `monitor`, or `enforce`. */
@@ -372,7 +375,16 @@ interface AtbashOptions {
372
375
  * `orgEncryptionPubKey` overrides this, same as `verifyPubKey`.
373
376
  */
374
377
  orgEncryptionPubKey?: string;
375
- /** When true (default), `auditToolCall` denies on any error. */
378
+ /**
379
+ * When true (default), `auditToolCall` denies on any error. When false, it
380
+ * allows only when Atbash could not be reached or could not answer: a
381
+ * transport failure, a timeout, a 5xx or a 408 (and a readable reply that
382
+ * neither grants nor refuses). Atbash's own refusals still deny: an
383
+ * unregistered agent, any other 4xx (no policy, billing suspended, quota
384
+ * exhausted or rate limited, unauthorized), and a 2xx reply that is not a
385
+ * JSON object. Direct `judgeAction` callers get a `JudgeRefusalError` for
386
+ * an unregistered agent or an unreadable reply.
387
+ */
376
388
  failClosed?: boolean;
377
389
  /**
378
390
  * When true (the default), an answer that carries no enforcement decision
@@ -399,6 +411,15 @@ interface Decision {
399
411
  verdict: DecisionVerdict;
400
412
  reason?: string;
401
413
  toolCallId?: string;
414
+ /**
415
+ * Whether the organisation acts on a HOLD/BLOCK verdict; false under Monitor mode and per-agent Shadow Mode. Absent means unknown: a
416
+ * transport error, or a judge that stated no mode. Test `=== false`, never
417
+ * `!decision.enforced`, or every outage counts as a would-block.
418
+ * Informational only; `allow` remains the gate.
419
+ */
420
+ enforced?: boolean;
421
+ /** Server-reported protection mode (`off`, `monitor`, `enforce`); absent when unknown. */
422
+ enforcementMode?: string;
402
423
  }
403
424
  /** Input to `auditToolCall`. */
404
425
  interface ToolCallInput {
@@ -622,6 +643,13 @@ declare class Atbash {
622
643
  * return the signed tx hex. The server broadcasts to chain.
623
644
  */
624
645
  logToolCall(action: string, context?: string, options?: LogToolCallOptions): Promise<LogToolCallResult>;
646
+ /**
647
+ * `raisePreflightErrors` (the judge path, like Python's
648
+ * `raise_preflight_errors`): a failed registration check throws instead of
649
+ * becoming `{ success: false }`, so the caller can tell Atbash's "no"
650
+ * (not registered, or a 4xx) from an outage.
651
+ */
652
+ private _logToolCall;
625
653
  /**
626
654
  * Sign log_tool_call + optionally judge_action, POST /api/v1/judge.
627
655
  *
@@ -630,6 +658,15 @@ declare class Atbash {
630
658
  */
631
659
  judgeAction(action: string, context?: string, options?: JudgeOptions): Promise<JudgeResult>;
632
660
  private _judgeAction;
661
+ /**
662
+ * Start a local hold on an enforced, on-chain BLOCK (the verdict that jails).
663
+ * Refuse any other result that lands while the agent is held, or whose
664
+ * request was already in flight when the block arrived: the server judged it
665
+ * on pre-jail state.
666
+ */
667
+ private applyJailHold;
668
+ /** The server's jailed refusal, produced locally while the agent is held. */
669
+ private localJailBlock;
633
670
  /**
634
671
  * High-level guard: redact secrets, submit for judgement, and collapse the
635
672
  * result into an allow/deny `Decision`. Fails closed by default — any error
@@ -654,6 +691,7 @@ declare class Atbash {
654
691
  * never overrides a refusal.
655
692
  */
656
693
  private decide;
694
+ private decideInner;
657
695
  /**
658
696
  * One exit for every judge failure.
659
697
  *
@@ -673,12 +711,12 @@ declare class Atbash {
673
711
  /**
674
712
  * Return the current status of a previously submitted judgment.
675
713
  *
676
- * `chainOpts` names which chain the judgment was signed against. The
677
- * server's GET /api/v1/judge routes to that chain when the SDK sends
678
- * a `brid` query param; without it, the server falls back to public.
679
- * Callers on the private chain must pass a `chainOpts` (or configure
680
- * the client on the private chain) — otherwise polling a POSTed
681
- * judgment on the private chain 404s at the server.
714
+ * `chainOpts` names which chain the judgment was signed against; the SDK
715
+ * sends it as the `brid` query param the server routes by. Without it the
716
+ * read uses the same chain `judgeAction` signs for (see `callBrid`): the
717
+ * client's org chain when it has an `orgName`, else the client default.
718
+ * A judgment signed with an explicit per-call `chainOpts` (or a per-call
719
+ * `orgName` on another chain) must be polled with that same `chainOpts`.
682
720
  */
683
721
  getJudgmentStatus(judgmentId: string, agentPubkey?: string, chainOpts?: ChainOpts): Promise<JudgmentStatus>;
684
722
  getToolCalls(maxCount: number): Promise<ToolCallRecord[]>;
@@ -743,6 +781,13 @@ declare class Atbash {
743
781
  * chains; otherwise the client's default.
744
782
  */
745
783
  private bridFromChainOpts;
784
+ /**
785
+ * The chain one call's transactions are signed for: the per-call override
786
+ * when given, otherwise the client's org, otherwise the client default.
787
+ * log_tool_call, judge_action and the judgment-status read all use this, so
788
+ * a request never pairs transactions signed for two different chains.
789
+ */
790
+ private callBrid;
746
791
  /**
747
792
  * Resolve the dashboard chain used by agent metadata/policy reads.
748
793
  * Explicit per-call network overrides win; otherwise use the supplied org
@@ -813,6 +858,17 @@ declare class Atbash {
813
858
  static containsEvasionCharacters(text: string): boolean;
814
859
  }
815
860
 
861
+ declare const DEFAULTS: {
862
+ ceilingMs: number;
863
+ pollMs: number;
864
+ };
865
+ /** Whether `pubkey` is currently held. */
866
+ declare function isJailHeld(pubkey: string): boolean;
867
+ /** Forget every hold and stop its poll; tests and hosts that reset state. */
868
+ declare function releaseJailHolds(): void;
869
+ /** Override the ceiling or poll interval; an empty object restores defaults. */
870
+ declare function configureJailHold(next: Partial<typeof DEFAULTS>): void;
871
+
816
872
  declare const DEFAULT_ENDPOINT: string;
817
873
  declare const DEFAULT_CHROMIA_NODE_URLS: readonly string[];
818
874
  declare const DEFAULT_BLOCKCHAIN_RID: string;
@@ -838,6 +894,14 @@ declare class AtbashAPIError extends Error {
838
894
  declare class SignatureVerificationError extends Error {
839
895
  constructor(message: string);
840
896
  }
897
+ /**
898
+ * Atbash answered, and the answer was not a grant: the agent is not
899
+ * registered, or the reply could not be read. Unlike an unreachable judge this
900
+ * always denies, whatever `failClosed` says.
901
+ */
902
+ declare class JudgeRefusalError extends Error {
903
+ constructor(message: string);
904
+ }
841
905
 
842
906
  /**
843
907
  * Thin typed fetch wrapper.
@@ -1250,6 +1314,39 @@ interface GuardMemoryWriteResult {
1250
1314
  */
1251
1315
  declare function guardMemoryWrite(input: GuardMemoryWriteInput): Promise<GuardMemoryWriteResult>;
1252
1316
 
1317
+ /**
1318
+ * The chain slot of a memory file, computed the same way everywhere.
1319
+ *
1320
+ * The Rust core finds the slot by stripping the agent's home from the file's
1321
+ * path, as an exact string prefix. The file path arrives resolved
1322
+ * (`path.resolve`), but the home did not: on Windows `HOME=/home/agent`
1323
+ * resolves the file to `C:\home\agent\...` and never matches, and a host that
1324
+ * spells the drive or the user folder differently (`c:\users\me` against
1325
+ * `C:\Users\Me`, both the same folder) did not match either. A file with no
1326
+ * slot is scanned but never recorded on chain, silently, so the on-chain
1327
+ * version record and its rollback/read checks were skipped for it.
1328
+ *
1329
+ * Here the home (and the memory root) is resolved like the file, and on a
1330
+ * case-insensitive file system it is passed to the core spelled the way the
1331
+ * file path spells it. The slot itself, the part below the agent home, keeps
1332
+ * the file's own spelling, so slots recorded before this change still match.
1333
+ *
1334
+ * Known limit: a folder with NTFS per-directory case sensitivity enabled
1335
+ * (`fsutil file setCaseSensitiveInfo`, or one created from WSL) can hold both
1336
+ * `Me` and `me`; there ASCII case does separate folders, and a sibling spelled
1337
+ * in another case would share the home's slots. Creating one needs write
1338
+ * access to the home's parent. A follow-up can confirm the same folder on disk
1339
+ * when the spellings differ.
1340
+ */
1341
+
1342
+ /** Path semantics: `node:path` here, `path.win32` / `path.posix` in tests. */
1343
+ type PathImpl = typeof nodePath;
1344
+ /**
1345
+ * The chain slot for `target`, or null when it gets no chain record. `p`
1346
+ * selects path semantics (tests pass `path.win32` to check Windows anywhere).
1347
+ */
1348
+ declare function memorySlotOf(target: string, home: string, root?: string, extraHomes?: string[], p?: PathImpl): string | null;
1349
+
1253
1350
  /**
1254
1351
  * Aligns a local `MemoryPointer` with chain's active memory version
1255
1352
  * via a TTL-cached pointer check. Inside the TTL window: no-op.
@@ -1894,4 +1991,4 @@ declare function containsSecret(text: string): boolean;
1894
1991
  declare function createMemorySnapshot(entries: MemoryEntry[], takenAt: number): MemorySnapshot;
1895
1992
  declare function diffMemorySnapshots(before: MemorySnapshot, after: MemorySnapshot): MemoryDiffResult;
1896
1993
 
1897
- export { type ActionType, type AgentAuth, type AgentLookupOptions, type AgentMemoryEntry, type AgentPolicy, type AnomalySeverity, type AnomalyType, Atbash, AtbashAPIError, type AtbashLogger, type AtbashOptions, type AtbashUserConfig, BOOT_SYNC_HINT, type ChainConfig, type ChainOpts, type ClassifierToolContext, type ClassifierToolEvent, type ClassifyMemoryReadOptions, type ClassifyMemoryWriteOptions, type ClientSource, type CommitMemoryOptions, DEFAULT_BLOCKCHAIN_RID, DEFAULT_CHROMIA_NODE_URLS, DEFAULT_ENDPOINT, DEFAULT_MEMORY_PATH_PATTERNS, DEFAULT_MEMORY_READ_TOOL_NAMES, DEFAULT_MEMORY_WRITE_TOOL_NAMES, type Decision, type DecisionVerdict, EciesDomain, type EncryptedMemory, type Envelope, type FromConfigOptions, type GuardLogger, type GuardMemoryDecision, type GuardMemoryWriteInput, type GuardMemoryWriteResult, type HeldAction, type HeldActionReview, type HookDecision, HttpClient, HttpTransportError, type JudgeEndpointConfig, type JudgeOptions, type JudgeResult, type JudgmentState, type JudgmentStatus, KEY_FILENAMES, type KeyPair, type LogToolCallOptions, type LogToolCallResult, type MemoryAnomaly, type MemoryDiffResult, type MemoryEntry, MemoryGuardManager, type MemoryGuardManagerOptions, MemoryIntegrityError, type MemoryPointer, type MemoryRollbackEvent, type MemoryScanOptions, type MemoryScanResult, type MemoryScanVerdict, type MemorySnapshot, type ModifiedEntry, type Network, type OperationEvent, type OrgSubscription, PRIVATE_CHAIN, PUBLIC_CHAIN, PointerStore, type Provider, type PubkeyValue, type RedactResult, type RollbackMemoryOptions, type SecretKind, type SecretMatch, SignatureVerificationError, type Subscription, type SyncMemoryOptions, type SyncMemoryResult, type TelemetryConfig, type TierInfo, type ToolCallFull, type ToolCallInput, type ToolCallRecord, type ValidatedEndpoint, type Verdict, type WrappedLogger, bootSyncFailureLine, buildAllowedJudgeHosts, canonicalAllow, chainForNetwork, chooseKeyPath, claimHashHex, classifyMemoryRead, classifyMemoryWrite, columnAad, commitMemoryVersion, configureEvents, containsEvasionCharacters, containsSecret, createFileLogger, createMemoryGuardManager, createMemorySnapshot, decryptForOrg, decryptMemoryContent, defaultPluginLogPath, defaultPointerPath, deriveMemoryKey, derivePublicKey, diffMemorySnapshots, encryptForOrg, encryptMemoryContent, encryptedLength, eventsAreOn, flushTelemetry, generateKeypair, getActiveAgentMemory, getActiveMemoryId, getConfigDir, getConfigPath, getMemoryById, getMemoryHistory, getRecentAgentMemory, getRollbackHistory, guardMemoryWrite, isEnvelope, isValidPrivateKey, keyFingerprintOf, keyPathCandidates, loadAgent, loadAgentFromFile, loadUserConfig, normalizeActionForHash, normalizeActionType, normalizeForMatching, normalizeStatus, normalizeVerdict, packEnvelope, parseEnvelope, pubkeyToHex, recordCall, recordDuration, recordEvent, redactJsonStrings, redactSecrets, resolve, resolveKeyPath, rollbackMemory, saveUserConfig, scanMemory, scanMemoryBatch, setupTelemetry, shutdownTelemetry, signEncryptedToolCall, signJudgeAction, signLogToolCall, syncLocalMemory, validateJudgeEndpoint, verifyJudgeResponseSignature, verifySignature };
1994
+ export { type ActionType, type AgentAuth, type AgentLookupOptions, type AgentMemoryEntry, type AgentPolicy, type AnomalySeverity, type AnomalyType, Atbash, AtbashAPIError, type AtbashLogger, type AtbashOptions, type AtbashUserConfig, BOOT_SYNC_HINT, type ChainConfig, type ChainOpts, type ClassifierToolContext, type ClassifierToolEvent, type ClassifyMemoryReadOptions, type ClassifyMemoryWriteOptions, type ClientSource, type CommitMemoryOptions, DEFAULT_BLOCKCHAIN_RID, DEFAULT_CHROMIA_NODE_URLS, DEFAULT_ENDPOINT, DEFAULT_MEMORY_PATH_PATTERNS, DEFAULT_MEMORY_READ_TOOL_NAMES, DEFAULT_MEMORY_WRITE_TOOL_NAMES, type Decision, type DecisionVerdict, EciesDomain, type EncryptedMemory, type Envelope, type FromConfigOptions, type GuardLogger, type GuardMemoryDecision, type GuardMemoryWriteInput, type GuardMemoryWriteResult, type HeldAction, type HeldActionReview, type HookDecision, HttpClient, HttpTransportError, type JudgeEndpointConfig, type JudgeOptions, JudgeRefusalError, type JudgeResult, type JudgmentState, type JudgmentStatus, KEY_FILENAMES, type KeyPair, type LogToolCallOptions, type LogToolCallResult, type MemoryAnomaly, type MemoryDiffResult, type MemoryEntry, MemoryGuardManager, type MemoryGuardManagerOptions, MemoryIntegrityError, type MemoryPointer, type MemoryRollbackEvent, type MemoryScanOptions, type MemoryScanResult, type MemoryScanVerdict, type MemorySnapshot, type ModifiedEntry, type Network, type OperationEvent, type OrgSubscription, PRIVATE_CHAIN, PUBLIC_CHAIN, PointerStore, type Provider, type PubkeyValue, type RedactResult, type RollbackMemoryOptions, type SecretKind, type SecretMatch, SignatureVerificationError, type Subscription, type SyncMemoryOptions, type SyncMemoryResult, type TelemetryConfig, type TierInfo, type ToolCallFull, type ToolCallInput, type ToolCallRecord, type ValidatedEndpoint, type Verdict, type WrappedLogger, bootSyncFailureLine, buildAllowedJudgeHosts, canonicalAllow, chainForNetwork, chooseKeyPath, claimHashHex, classifyMemoryRead, classifyMemoryWrite, columnAad, commitMemoryVersion, configureEvents, configureJailHold, containsEvasionCharacters, containsSecret, createFileLogger, createMemoryGuardManager, createMemorySnapshot, decryptForOrg, decryptMemoryContent, defaultPluginLogPath, defaultPointerPath, deriveMemoryKey, derivePublicKey, diffMemorySnapshots, encryptForOrg, encryptMemoryContent, encryptedLength, eventsAreOn, flushTelemetry, generateKeypair, getActiveAgentMemory, getActiveMemoryId, getConfigDir, getConfigPath, getMemoryById, getMemoryHistory, getRecentAgentMemory, getRollbackHistory, guardMemoryWrite, isEnvelope, isJailHeld, isValidPrivateKey, keyFingerprintOf, keyPathCandidates, loadAgent, loadAgentFromFile, loadUserConfig, memorySlotOf, normalizeActionForHash, normalizeActionType, normalizeForMatching, normalizeStatus, normalizeVerdict, packEnvelope, parseEnvelope, pubkeyToHex, recordCall, recordDuration, recordEvent, redactJsonStrings, redactSecrets, releaseJailHolds, resolve, resolveKeyPath, rollbackMemory, saveUserConfig, scanMemory, scanMemoryBatch, setupTelemetry, shutdownTelemetry, signEncryptedToolCall, signJudgeAction, signLogToolCall, syncLocalMemory, validateJudgeEndpoint, verifyJudgeResponseSignature, verifySignature };