@theokit/sdk 4.48.0 → 4.50.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/dist/index.d.cts CHANGED
@@ -1263,6 +1263,63 @@ declare class Tool {
1263
1263
  static create<T extends ZodType, O extends ZodType = never>(spec: DefineToolSpec<T, O>): CustomTool;
1264
1264
  }
1265
1265
 
1266
+ /**
1267
+ * Audit whether every configuration key can be set from the environment, or says why not.
1268
+ *
1269
+ * A key settable only by editing a file cannot be set in CI, in a container, or for a single
1270
+ * invocation. That is usually an oversight rather than a decision, and it is invisible — nothing
1271
+ * fails, the key simply has no environment path, and nobody notices until someone needs one.
1272
+ *
1273
+ * The opposite failure rots more quietly. An opt-out written for a key that has since gained an
1274
+ * environment path, or for a key that no longer exists, still reads as a considered decision while
1275
+ * exempting nothing. Both questions are answered by one call so a consumer cannot check the gap and
1276
+ * forget the rot: they fail for opposite reasons, and a suite that asks only one looks complete.
1277
+ *
1278
+ * ## Why the framework owns the rule and not the keys
1279
+ *
1280
+ * A framework cannot enumerate a consumer's configuration keys, and should not try. Which keys exist
1281
+ * is that product's vocabulary — the same reason the security floor takes its permissiveness order
1282
+ * as data and the trust posture takes its capability list. So the consumer ranges over its own keys
1283
+ * with this, rather than registering them here.
1284
+ *
1285
+ * That is a narrower claim than "reachability is checked in the framework", and it is the honest
1286
+ * one: the failure still surfaces in the consumer's own suite. What the consumer no longer writes is
1287
+ * the detector, which is where the subtlety lives — the stale-opt-out half is the part everyone
1288
+ * forgets.
1289
+ *
1290
+ * @public
1291
+ */
1292
+ /** A key deliberately left off the environment, with the reason and what would reverse it. @public */
1293
+ interface EnvOptOut {
1294
+ readonly key: string;
1295
+ /** Why an environment variable is the wrong shape for this key. */
1296
+ readonly reason: string;
1297
+ /** What would make this opt-out obsolete. An opt-out with no exit is a permanent excuse. */
1298
+ readonly exitCriterion: string;
1299
+ }
1300
+ /** @public */
1301
+ interface EnvReachabilityInput {
1302
+ /** Every configuration key the product declares. */
1303
+ readonly keys: readonly string[];
1304
+ /** The subset that an environment variable can set. */
1305
+ readonly reachable: readonly string[];
1306
+ /** Documented exemptions for keys that deliberately have no environment path. */
1307
+ readonly optOuts: readonly EnvOptOut[];
1308
+ }
1309
+ /** @public */
1310
+ interface EnvReachabilityAudit {
1311
+ /** Keys with neither an environment path nor a documented opt-out. */
1312
+ readonly unreachable: readonly string[];
1313
+ /** Opt-outs that exempt nothing: the key gained an environment path, or no longer exists. */
1314
+ readonly staleOptOuts: readonly string[];
1315
+ }
1316
+ /**
1317
+ * @returns both axes, in the order the caller declared them — a stable order so a failure message
1318
+ * does not change between runs for reasons unrelated to the code.
1319
+ * @public
1320
+ */
1321
+ declare function auditEnvReachability(input: EnvReachabilityInput): EnvReachabilityAudit;
1322
+
1266
1323
  /**
1267
1324
  * `EventBus` — typed EventEmitter wrapper.
1268
1325
  *
@@ -1962,6 +2019,87 @@ type MutableEnv = Record<string, string | undefined>;
1962
2019
  */
1963
2020
  declare function loadProjectEnv(env?: MutableEnv, load?: (() => void) | undefined): void;
1964
2021
 
2022
+ /**
2023
+ * Decide which session artifacts may be deleted — and never delete them.
2024
+ *
2025
+ * This package creates session artifacts (transcripts, locks, temp files) and cleans up only what is
2026
+ * in flight in the operation doing the cleaning: a lock it just released, a `.tmp` from a failed
2027
+ * atomic write. Nothing collects the rest, so every consumer either writes its own collector or lets
2028
+ * the directory grow without bound — and a hand-rolled collector on the path that deletes a user's
2029
+ * transcript is the worst place for each product to learn the same lessons separately.
2030
+ *
2031
+ * ## Planning is not deleting, deliberately
2032
+ *
2033
+ * A function that decided AND deleted could not be tested without a filesystem, and the case that
2034
+ * matters most — "we could not establish whether this session is live" — would have to be simulated
2035
+ * rather than asserted. Here the decision is pure: the plan IS the dry run, and executing it is a
2036
+ * separate act on a value someone can read first. That separation is the dry-run guarantee, rather
2037
+ * than a flag that has to be remembered.
2038
+ *
2039
+ * ## The tri-state
2040
+ *
2041
+ * `keep`, `reap`, `undetermined`. An artifact whose liveness could not be established is never
2042
+ * reaped and never quietly counted as dead. Collapsing "could not determine" into "not there" is how
2043
+ * a collector deletes a session running on another machine, or behind a mount that answered slowly.
2044
+ * The third bucket costs a branch and buys the only guarantee worth having on this path.
2045
+ *
2046
+ * @public
2047
+ */
2048
+
2049
+ /** Raised when a retention policy cannot be honoured as written. @public */
2050
+ declare class RetentionPolicyError extends TheokitAgentError {
2051
+ readonly name = "RetentionPolicyError";
2052
+ }
2053
+ /** @public */
2054
+ interface ReapableArtifact {
2055
+ readonly id: string;
2056
+ /** Epoch milliseconds. Compared against an injected `nowMs`, never against a read clock. */
2057
+ readonly lastModifiedMs: number;
2058
+ /**
2059
+ * Whether a writer still holds this artifact. `"unknown"` when the caller could not establish it —
2060
+ * a stale lock behind a slow mount, a PID on another host — and it is honoured as a third answer
2061
+ * rather than folded into `false`.
2062
+ */
2063
+ readonly live: boolean | "unknown";
2064
+ }
2065
+ /** @public */
2066
+ interface RetentionPolicy {
2067
+ /** Artifacts strictly older than this are candidates. The boundary itself is kept. */
2068
+ readonly maxAgeMs: number;
2069
+ /**
2070
+ * A FLOOR on how many artifacts survive: "you will always have your last N sessions". When
2071
+ * liveness and the retention window already spare N or more, this changes nothing; when they
2072
+ * spare fewer, the newest of the remainder are spared until the count reaches N.
2073
+ *
2074
+ * Undetermined artifacts do NOT count toward the floor. Their liveness was never established, so
2075
+ * counting them would let a transient mount failure satisfy the floor with artifacts nobody
2076
+ * confirmed exist as sessions — and quietly delete the ones that do.
2077
+ */
2078
+ readonly keepLast: number;
2079
+ }
2080
+ /** Why an artifact survived. @public */
2081
+ type KeepReason = "live" | "within-retention" | "keep-last";
2082
+ /** @public */
2083
+ interface KeptArtifact extends ReapableArtifact {
2084
+ readonly reason: KeepReason;
2085
+ }
2086
+ /** @public */
2087
+ interface ReapPlan {
2088
+ /** Safe to delete. Everything here was decided, not defaulted. */
2089
+ readonly reap: readonly ReapableArtifact[];
2090
+ readonly keep: readonly KeptArtifact[];
2091
+ /** Liveness could not be established. Never deleted, never counted as kept. */
2092
+ readonly undetermined: readonly ReapableArtifact[];
2093
+ }
2094
+ /** @public */
2095
+ interface ReapPlanInput {
2096
+ readonly artifacts: readonly ReapableArtifact[];
2097
+ readonly retention: RetentionPolicy;
2098
+ /** Injected so the plan is reproducible and testable; this module never reads a clock. */
2099
+ readonly nowMs: number;
2100
+ }
2101
+ declare function planReaping(input: ReapPlanInput): ReapPlan;
2102
+
1965
2103
  /** The internal JSON-Schema shape the synthetic `output` tool consumes. */
1966
2104
  type NormalizedJsonSchema = Record<string, unknown>;
1967
2105
  /**
@@ -2835,4 +2973,4 @@ interface WiringRecordInput<K extends string> {
2835
2973
  */
2836
2974
  declare function recordWiring<K extends string>(input: WiringRecordInput<K>): Readonly<Record<K, WiredEntity>>;
2837
2975
 
2838
- export { Agent, AgentBuilder, AgentDefinition, AgentDescription, AgentFactory, AgentOperationOptions, AgentOptions, type AgentPromptResult, type AgentRegistryOptions, type BatchItem, type BatchOptions, type BatchProgress, type BatchResult, Budget, BudgetHandle, BudgetOptions, BudgetSnapshot, BudgetTracker, CloudOptions, ContextSettings, type CounterBudgetTrackerOptions, CustomTool, type DeclaredLayer, type DeepPartial, type DefineProviderOptions, type DefineToolSpec, type DiagnosticsSink, type DreamingSweepOptions, type DreamingSweepResult, ErrorMetadata, EventBus, type EvictReason, GOAL_CONTINUATION_MARKER, GenerateObjectError, type GenerateObjectOptions, type GenerateObjectResult, GetAgentOptions, GetRunOptions, GoalEvent, type GoalLoopAgent, GoalOptions, GoalResult, InlineSkill, JobQueue, type JobQueueOptions, JudgeCredentialError, JudgeResult, LayerOrderError, type LayerValues, ListAgentsOptions, ListResult, ListRunsOptions, LiveAgentRegistry, LocalOptions, McpServerConfig, Memory, MemoryId, MemoryProvider, MemorySettings, type MigrateOptions, type MigrateResult, type ModelListItem, type ModelParameterDefinition, ModelSelection, type ModelVariant, NoopMemoryProvider, type NormalizedJsonSchema, PermissionEngine, type PermissionGate, type PermissionGateContext, type PermissionGateDecision, PermissionMode, PermissionPlugin, type PermissionPluginOptions, Plugin, PluginsSettings, PreToolCallDecision, Processor, Provider, ProviderProfile, ProviderRoutingSettings, Run, RunEventSink, RunResult, SDKAgent, SDKAgentInfo, SDKMessage, type SDKModel, SDKProvider, type SDKRepository, type SDKUser, SOVEREIGN_ENV_KEYS, Security, type SecurityFloorInput, type SessionMessage, type SessionMessagePart, type SessionScope, type ShareGptMessage, type ShareGptTrajectory, SkillReadTool, SkillsSettings, type SovereignEnvKey, Squad, type SquadOptions, type SquadRun, StreamObjectError, type StreamObjectEvent, type StreamObjectOptions, SystemPromptResolver, TASK_RESERVED_PREFIXES, Task, type TaskCancelResult, type TaskConfigureOptions, type TaskEvent, type TaskFilter, type TaskHandle, type TaskKind, type TaskState, type TaskStoreOptions, type TaskSubmitOptions, type TaskWorkContext, type TaskWorkFn, Theokit, TheokitAgentError, type TheokitRequestOptions, TokenLimiter, type TokenLimiterOptions, Tool, ToolError, ToolResultContentBlock, type TrustLevel, type TrustPosture, type TrustPostureInput, type TrustSource, UngatedCapabilityError, UnicodeNormalizer, type UnicodeNormalizerOptions, UsageAccumulator, type WiredEntity, type WiringRecordInput, applySecurityFloor, chargeAndCheckThresholds, computeCost, createCounterBudgetTracker, estimateTokens, extractRawId, foldLayers, getPricingEntry, inferApiMode, isValidTaskId, loadProjectEnv, migrateSqliteToLance, mkMemoryId, normalizeSchema, normalizeUsage, preflightCheck, recordWiring, resolveTrustPosture, runGoalLoop, scopedConversationId, sessionScopePrefix, setDiagnosticsSink, toShareGptTrajectory, verifyLayerOrdering, withCwdMutex };
2976
+ export { Agent, AgentBuilder, AgentDefinition, AgentDescription, AgentFactory, AgentOperationOptions, AgentOptions, type AgentPromptResult, type AgentRegistryOptions, type BatchItem, type BatchOptions, type BatchProgress, type BatchResult, Budget, BudgetHandle, BudgetOptions, BudgetSnapshot, BudgetTracker, CloudOptions, ContextSettings, type CounterBudgetTrackerOptions, CustomTool, type DeclaredLayer, type DeepPartial, type DefineProviderOptions, type DefineToolSpec, type DiagnosticsSink, type DreamingSweepOptions, type DreamingSweepResult, type EnvOptOut, type EnvReachabilityAudit, type EnvReachabilityInput, ErrorMetadata, EventBus, type EvictReason, GOAL_CONTINUATION_MARKER, GenerateObjectError, type GenerateObjectOptions, type GenerateObjectResult, GetAgentOptions, GetRunOptions, GoalEvent, type GoalLoopAgent, GoalOptions, GoalResult, InlineSkill, JobQueue, type JobQueueOptions, JudgeCredentialError, JudgeResult, type KeepReason, type KeptArtifact, LayerOrderError, type LayerValues, ListAgentsOptions, ListResult, ListRunsOptions, LiveAgentRegistry, LocalOptions, McpServerConfig, Memory, MemoryId, MemoryProvider, MemorySettings, type MigrateOptions, type MigrateResult, type ModelListItem, type ModelParameterDefinition, ModelSelection, type ModelVariant, NoopMemoryProvider, type NormalizedJsonSchema, PermissionEngine, type PermissionGate, type PermissionGateContext, type PermissionGateDecision, PermissionMode, PermissionPlugin, type PermissionPluginOptions, Plugin, PluginsSettings, PreToolCallDecision, Processor, Provider, ProviderProfile, ProviderRoutingSettings, type ReapPlan, type ReapPlanInput, type ReapableArtifact, type RetentionPolicy, RetentionPolicyError, Run, RunEventSink, RunResult, SDKAgent, SDKAgentInfo, SDKMessage, type SDKModel, SDKProvider, type SDKRepository, type SDKUser, SOVEREIGN_ENV_KEYS, Security, type SecurityFloorInput, type SessionMessage, type SessionMessagePart, type SessionScope, type ShareGptMessage, type ShareGptTrajectory, SkillReadTool, SkillsSettings, type SovereignEnvKey, Squad, type SquadOptions, type SquadRun, StreamObjectError, type StreamObjectEvent, type StreamObjectOptions, SystemPromptResolver, TASK_RESERVED_PREFIXES, Task, type TaskCancelResult, type TaskConfigureOptions, type TaskEvent, type TaskFilter, type TaskHandle, type TaskKind, type TaskState, type TaskStoreOptions, type TaskSubmitOptions, type TaskWorkContext, type TaskWorkFn, Theokit, TheokitAgentError, type TheokitRequestOptions, TokenLimiter, type TokenLimiterOptions, Tool, ToolError, ToolResultContentBlock, type TrustLevel, type TrustPosture, type TrustPostureInput, type TrustSource, UngatedCapabilityError, UnicodeNormalizer, type UnicodeNormalizerOptions, UsageAccumulator, type WiredEntity, type WiringRecordInput, applySecurityFloor, auditEnvReachability, chargeAndCheckThresholds, computeCost, createCounterBudgetTracker, estimateTokens, extractRawId, foldLayers, getPricingEntry, inferApiMode, isValidTaskId, loadProjectEnv, migrateSqliteToLance, mkMemoryId, normalizeSchema, normalizeUsage, planReaping, preflightCheck, recordWiring, resolveTrustPosture, runGoalLoop, scopedConversationId, sessionScopePrefix, setDiagnosticsSink, toShareGptTrajectory, verifyLayerOrdering, withCwdMutex };
package/dist/index.d.ts CHANGED
@@ -1263,6 +1263,63 @@ declare class Tool {
1263
1263
  static create<T extends ZodType, O extends ZodType = never>(spec: DefineToolSpec<T, O>): CustomTool;
1264
1264
  }
1265
1265
 
1266
+ /**
1267
+ * Audit whether every configuration key can be set from the environment, or says why not.
1268
+ *
1269
+ * A key settable only by editing a file cannot be set in CI, in a container, or for a single
1270
+ * invocation. That is usually an oversight rather than a decision, and it is invisible — nothing
1271
+ * fails, the key simply has no environment path, and nobody notices until someone needs one.
1272
+ *
1273
+ * The opposite failure rots more quietly. An opt-out written for a key that has since gained an
1274
+ * environment path, or for a key that no longer exists, still reads as a considered decision while
1275
+ * exempting nothing. Both questions are answered by one call so a consumer cannot check the gap and
1276
+ * forget the rot: they fail for opposite reasons, and a suite that asks only one looks complete.
1277
+ *
1278
+ * ## Why the framework owns the rule and not the keys
1279
+ *
1280
+ * A framework cannot enumerate a consumer's configuration keys, and should not try. Which keys exist
1281
+ * is that product's vocabulary — the same reason the security floor takes its permissiveness order
1282
+ * as data and the trust posture takes its capability list. So the consumer ranges over its own keys
1283
+ * with this, rather than registering them here.
1284
+ *
1285
+ * That is a narrower claim than "reachability is checked in the framework", and it is the honest
1286
+ * one: the failure still surfaces in the consumer's own suite. What the consumer no longer writes is
1287
+ * the detector, which is where the subtlety lives — the stale-opt-out half is the part everyone
1288
+ * forgets.
1289
+ *
1290
+ * @public
1291
+ */
1292
+ /** A key deliberately left off the environment, with the reason and what would reverse it. @public */
1293
+ interface EnvOptOut {
1294
+ readonly key: string;
1295
+ /** Why an environment variable is the wrong shape for this key. */
1296
+ readonly reason: string;
1297
+ /** What would make this opt-out obsolete. An opt-out with no exit is a permanent excuse. */
1298
+ readonly exitCriterion: string;
1299
+ }
1300
+ /** @public */
1301
+ interface EnvReachabilityInput {
1302
+ /** Every configuration key the product declares. */
1303
+ readonly keys: readonly string[];
1304
+ /** The subset that an environment variable can set. */
1305
+ readonly reachable: readonly string[];
1306
+ /** Documented exemptions for keys that deliberately have no environment path. */
1307
+ readonly optOuts: readonly EnvOptOut[];
1308
+ }
1309
+ /** @public */
1310
+ interface EnvReachabilityAudit {
1311
+ /** Keys with neither an environment path nor a documented opt-out. */
1312
+ readonly unreachable: readonly string[];
1313
+ /** Opt-outs that exempt nothing: the key gained an environment path, or no longer exists. */
1314
+ readonly staleOptOuts: readonly string[];
1315
+ }
1316
+ /**
1317
+ * @returns both axes, in the order the caller declared them — a stable order so a failure message
1318
+ * does not change between runs for reasons unrelated to the code.
1319
+ * @public
1320
+ */
1321
+ declare function auditEnvReachability(input: EnvReachabilityInput): EnvReachabilityAudit;
1322
+
1266
1323
  /**
1267
1324
  * `EventBus` — typed EventEmitter wrapper.
1268
1325
  *
@@ -1962,6 +2019,87 @@ type MutableEnv = Record<string, string | undefined>;
1962
2019
  */
1963
2020
  declare function loadProjectEnv(env?: MutableEnv, load?: (() => void) | undefined): void;
1964
2021
 
2022
+ /**
2023
+ * Decide which session artifacts may be deleted — and never delete them.
2024
+ *
2025
+ * This package creates session artifacts (transcripts, locks, temp files) and cleans up only what is
2026
+ * in flight in the operation doing the cleaning: a lock it just released, a `.tmp` from a failed
2027
+ * atomic write. Nothing collects the rest, so every consumer either writes its own collector or lets
2028
+ * the directory grow without bound — and a hand-rolled collector on the path that deletes a user's
2029
+ * transcript is the worst place for each product to learn the same lessons separately.
2030
+ *
2031
+ * ## Planning is not deleting, deliberately
2032
+ *
2033
+ * A function that decided AND deleted could not be tested without a filesystem, and the case that
2034
+ * matters most — "we could not establish whether this session is live" — would have to be simulated
2035
+ * rather than asserted. Here the decision is pure: the plan IS the dry run, and executing it is a
2036
+ * separate act on a value someone can read first. That separation is the dry-run guarantee, rather
2037
+ * than a flag that has to be remembered.
2038
+ *
2039
+ * ## The tri-state
2040
+ *
2041
+ * `keep`, `reap`, `undetermined`. An artifact whose liveness could not be established is never
2042
+ * reaped and never quietly counted as dead. Collapsing "could not determine" into "not there" is how
2043
+ * a collector deletes a session running on another machine, or behind a mount that answered slowly.
2044
+ * The third bucket costs a branch and buys the only guarantee worth having on this path.
2045
+ *
2046
+ * @public
2047
+ */
2048
+
2049
+ /** Raised when a retention policy cannot be honoured as written. @public */
2050
+ declare class RetentionPolicyError extends TheokitAgentError {
2051
+ readonly name = "RetentionPolicyError";
2052
+ }
2053
+ /** @public */
2054
+ interface ReapableArtifact {
2055
+ readonly id: string;
2056
+ /** Epoch milliseconds. Compared against an injected `nowMs`, never against a read clock. */
2057
+ readonly lastModifiedMs: number;
2058
+ /**
2059
+ * Whether a writer still holds this artifact. `"unknown"` when the caller could not establish it —
2060
+ * a stale lock behind a slow mount, a PID on another host — and it is honoured as a third answer
2061
+ * rather than folded into `false`.
2062
+ */
2063
+ readonly live: boolean | "unknown";
2064
+ }
2065
+ /** @public */
2066
+ interface RetentionPolicy {
2067
+ /** Artifacts strictly older than this are candidates. The boundary itself is kept. */
2068
+ readonly maxAgeMs: number;
2069
+ /**
2070
+ * A FLOOR on how many artifacts survive: "you will always have your last N sessions". When
2071
+ * liveness and the retention window already spare N or more, this changes nothing; when they
2072
+ * spare fewer, the newest of the remainder are spared until the count reaches N.
2073
+ *
2074
+ * Undetermined artifacts do NOT count toward the floor. Their liveness was never established, so
2075
+ * counting them would let a transient mount failure satisfy the floor with artifacts nobody
2076
+ * confirmed exist as sessions — and quietly delete the ones that do.
2077
+ */
2078
+ readonly keepLast: number;
2079
+ }
2080
+ /** Why an artifact survived. @public */
2081
+ type KeepReason = "live" | "within-retention" | "keep-last";
2082
+ /** @public */
2083
+ interface KeptArtifact extends ReapableArtifact {
2084
+ readonly reason: KeepReason;
2085
+ }
2086
+ /** @public */
2087
+ interface ReapPlan {
2088
+ /** Safe to delete. Everything here was decided, not defaulted. */
2089
+ readonly reap: readonly ReapableArtifact[];
2090
+ readonly keep: readonly KeptArtifact[];
2091
+ /** Liveness could not be established. Never deleted, never counted as kept. */
2092
+ readonly undetermined: readonly ReapableArtifact[];
2093
+ }
2094
+ /** @public */
2095
+ interface ReapPlanInput {
2096
+ readonly artifacts: readonly ReapableArtifact[];
2097
+ readonly retention: RetentionPolicy;
2098
+ /** Injected so the plan is reproducible and testable; this module never reads a clock. */
2099
+ readonly nowMs: number;
2100
+ }
2101
+ declare function planReaping(input: ReapPlanInput): ReapPlan;
2102
+
1965
2103
  /** The internal JSON-Schema shape the synthetic `output` tool consumes. */
1966
2104
  type NormalizedJsonSchema = Record<string, unknown>;
1967
2105
  /**
@@ -2835,4 +2973,4 @@ interface WiringRecordInput<K extends string> {
2835
2973
  */
2836
2974
  declare function recordWiring<K extends string>(input: WiringRecordInput<K>): Readonly<Record<K, WiredEntity>>;
2837
2975
 
2838
- export { Agent, AgentBuilder, AgentDefinition, AgentDescription, AgentFactory, AgentOperationOptions, AgentOptions, type AgentPromptResult, type AgentRegistryOptions, type BatchItem, type BatchOptions, type BatchProgress, type BatchResult, Budget, BudgetHandle, BudgetOptions, BudgetSnapshot, BudgetTracker, CloudOptions, ContextSettings, type CounterBudgetTrackerOptions, CustomTool, type DeclaredLayer, type DeepPartial, type DefineProviderOptions, type DefineToolSpec, type DiagnosticsSink, type DreamingSweepOptions, type DreamingSweepResult, ErrorMetadata, EventBus, type EvictReason, GOAL_CONTINUATION_MARKER, GenerateObjectError, type GenerateObjectOptions, type GenerateObjectResult, GetAgentOptions, GetRunOptions, GoalEvent, type GoalLoopAgent, GoalOptions, GoalResult, InlineSkill, JobQueue, type JobQueueOptions, JudgeCredentialError, JudgeResult, LayerOrderError, type LayerValues, ListAgentsOptions, ListResult, ListRunsOptions, LiveAgentRegistry, LocalOptions, McpServerConfig, Memory, MemoryId, MemoryProvider, MemorySettings, type MigrateOptions, type MigrateResult, type ModelListItem, type ModelParameterDefinition, ModelSelection, type ModelVariant, NoopMemoryProvider, type NormalizedJsonSchema, PermissionEngine, type PermissionGate, type PermissionGateContext, type PermissionGateDecision, PermissionMode, PermissionPlugin, type PermissionPluginOptions, Plugin, PluginsSettings, PreToolCallDecision, Processor, Provider, ProviderProfile, ProviderRoutingSettings, Run, RunEventSink, RunResult, SDKAgent, SDKAgentInfo, SDKMessage, type SDKModel, SDKProvider, type SDKRepository, type SDKUser, SOVEREIGN_ENV_KEYS, Security, type SecurityFloorInput, type SessionMessage, type SessionMessagePart, type SessionScope, type ShareGptMessage, type ShareGptTrajectory, SkillReadTool, SkillsSettings, type SovereignEnvKey, Squad, type SquadOptions, type SquadRun, StreamObjectError, type StreamObjectEvent, type StreamObjectOptions, SystemPromptResolver, TASK_RESERVED_PREFIXES, Task, type TaskCancelResult, type TaskConfigureOptions, type TaskEvent, type TaskFilter, type TaskHandle, type TaskKind, type TaskState, type TaskStoreOptions, type TaskSubmitOptions, type TaskWorkContext, type TaskWorkFn, Theokit, TheokitAgentError, type TheokitRequestOptions, TokenLimiter, type TokenLimiterOptions, Tool, ToolError, ToolResultContentBlock, type TrustLevel, type TrustPosture, type TrustPostureInput, type TrustSource, UngatedCapabilityError, UnicodeNormalizer, type UnicodeNormalizerOptions, UsageAccumulator, type WiredEntity, type WiringRecordInput, applySecurityFloor, chargeAndCheckThresholds, computeCost, createCounterBudgetTracker, estimateTokens, extractRawId, foldLayers, getPricingEntry, inferApiMode, isValidTaskId, loadProjectEnv, migrateSqliteToLance, mkMemoryId, normalizeSchema, normalizeUsage, preflightCheck, recordWiring, resolveTrustPosture, runGoalLoop, scopedConversationId, sessionScopePrefix, setDiagnosticsSink, toShareGptTrajectory, verifyLayerOrdering, withCwdMutex };
2976
+ export { Agent, AgentBuilder, AgentDefinition, AgentDescription, AgentFactory, AgentOperationOptions, AgentOptions, type AgentPromptResult, type AgentRegistryOptions, type BatchItem, type BatchOptions, type BatchProgress, type BatchResult, Budget, BudgetHandle, BudgetOptions, BudgetSnapshot, BudgetTracker, CloudOptions, ContextSettings, type CounterBudgetTrackerOptions, CustomTool, type DeclaredLayer, type DeepPartial, type DefineProviderOptions, type DefineToolSpec, type DiagnosticsSink, type DreamingSweepOptions, type DreamingSweepResult, type EnvOptOut, type EnvReachabilityAudit, type EnvReachabilityInput, ErrorMetadata, EventBus, type EvictReason, GOAL_CONTINUATION_MARKER, GenerateObjectError, type GenerateObjectOptions, type GenerateObjectResult, GetAgentOptions, GetRunOptions, GoalEvent, type GoalLoopAgent, GoalOptions, GoalResult, InlineSkill, JobQueue, type JobQueueOptions, JudgeCredentialError, JudgeResult, type KeepReason, type KeptArtifact, LayerOrderError, type LayerValues, ListAgentsOptions, ListResult, ListRunsOptions, LiveAgentRegistry, LocalOptions, McpServerConfig, Memory, MemoryId, MemoryProvider, MemorySettings, type MigrateOptions, type MigrateResult, type ModelListItem, type ModelParameterDefinition, ModelSelection, type ModelVariant, NoopMemoryProvider, type NormalizedJsonSchema, PermissionEngine, type PermissionGate, type PermissionGateContext, type PermissionGateDecision, PermissionMode, PermissionPlugin, type PermissionPluginOptions, Plugin, PluginsSettings, PreToolCallDecision, Processor, Provider, ProviderProfile, ProviderRoutingSettings, type ReapPlan, type ReapPlanInput, type ReapableArtifact, type RetentionPolicy, RetentionPolicyError, Run, RunEventSink, RunResult, SDKAgent, SDKAgentInfo, SDKMessage, type SDKModel, SDKProvider, type SDKRepository, type SDKUser, SOVEREIGN_ENV_KEYS, Security, type SecurityFloorInput, type SessionMessage, type SessionMessagePart, type SessionScope, type ShareGptMessage, type ShareGptTrajectory, SkillReadTool, SkillsSettings, type SovereignEnvKey, Squad, type SquadOptions, type SquadRun, StreamObjectError, type StreamObjectEvent, type StreamObjectOptions, SystemPromptResolver, TASK_RESERVED_PREFIXES, Task, type TaskCancelResult, type TaskConfigureOptions, type TaskEvent, type TaskFilter, type TaskHandle, type TaskKind, type TaskState, type TaskStoreOptions, type TaskSubmitOptions, type TaskWorkContext, type TaskWorkFn, Theokit, TheokitAgentError, type TheokitRequestOptions, TokenLimiter, type TokenLimiterOptions, Tool, ToolError, ToolResultContentBlock, type TrustLevel, type TrustPosture, type TrustPostureInput, type TrustSource, UngatedCapabilityError, UnicodeNormalizer, type UnicodeNormalizerOptions, UsageAccumulator, type WiredEntity, type WiringRecordInput, applySecurityFloor, auditEnvReachability, chargeAndCheckThresholds, computeCost, createCounterBudgetTracker, estimateTokens, extractRawId, foldLayers, getPricingEntry, inferApiMode, isValidTaskId, loadProjectEnv, migrateSqliteToLance, mkMemoryId, normalizeSchema, normalizeUsage, planReaping, preflightCheck, recordWiring, resolveTrustPosture, runGoalLoop, scopedConversationId, sessionScopePrefix, setDiagnosticsSink, toShareGptTrajectory, verifyLayerOrdering, withCwdMutex };
package/dist/index.js CHANGED
@@ -664,6 +664,17 @@ var SkillReadTool = class {
664
664
  }
665
665
  };
666
666
 
667
+ // src/env-reachability.ts
668
+ function auditEnvReachability(input) {
669
+ const reachable = new Set(input.reachable);
670
+ const exempt = new Set(input.optOuts.map((o) => o.key));
671
+ const declared = new Set(input.keys);
672
+ return {
673
+ unreachable: input.keys.filter((k) => !reachable.has(k) && !exempt.has(k)),
674
+ staleOptOuts: input.optOuts.filter((o) => !declared.has(o.key) || reachable.has(o.key)).map((o) => o.key)
675
+ };
676
+ }
677
+
667
678
  // src/event-bus.ts
668
679
  var EventBus = class {
669
680
  handlers = /* @__PURE__ */ new Map();
@@ -1563,6 +1574,60 @@ function loadProjectEnv(env = process.env, load = typeof process.loadEnvFile ===
1563
1574
  }
1564
1575
  }
1565
1576
 
1577
+ // src/reap-plan.ts
1578
+ var RetentionPolicyError = class extends TheokitAgentError {
1579
+ name = "RetentionPolicyError";
1580
+ };
1581
+ function assertPolicy(retention) {
1582
+ const { maxAgeMs, keepLast } = retention;
1583
+ if (!Number.isFinite(maxAgeMs) || maxAgeMs < 0) {
1584
+ throw new RetentionPolicyError(
1585
+ `retention.maxAgeMs must be a non-negative number of milliseconds, got ${String(maxAgeMs)}`
1586
+ );
1587
+ }
1588
+ if (!Number.isInteger(keepLast) || keepLast < 0) {
1589
+ throw new RetentionPolicyError(
1590
+ `retention.keepLast must be a non-negative integer, got ${String(keepLast)}`
1591
+ );
1592
+ }
1593
+ }
1594
+ function classifyByOwnReason(input) {
1595
+ const keep = [];
1596
+ const atRisk = [];
1597
+ for (const artifact of input.artifacts) {
1598
+ if (artifact.live === "unknown") continue;
1599
+ if (artifact.live === true) {
1600
+ keep.push({ ...artifact, reason: "live" });
1601
+ continue;
1602
+ }
1603
+ if (input.nowMs - artifact.lastModifiedMs <= input.retention.maxAgeMs) {
1604
+ keep.push({ ...artifact, reason: "within-retention" });
1605
+ continue;
1606
+ }
1607
+ atRisk.push(artifact);
1608
+ }
1609
+ return { keep, atRisk };
1610
+ }
1611
+ function applyFloor(kept, atRisk, keepLast) {
1612
+ const shortfall = Math.max(0, keepLast - kept.length);
1613
+ const newestFirst = [...atRisk].sort((a, b) => b.lastModifiedMs - a.lastModifiedMs);
1614
+ const spared = new Set(newestFirst.slice(0, shortfall).map((a) => a.id));
1615
+ const rescued = [];
1616
+ const reap = [];
1617
+ for (const artifact of atRisk) {
1618
+ if (spared.has(artifact.id)) rescued.push({ ...artifact, reason: "keep-last" });
1619
+ else reap.push(artifact);
1620
+ }
1621
+ return { rescued, reap };
1622
+ }
1623
+ function planReaping(input) {
1624
+ assertPolicy(input.retention);
1625
+ const undetermined = input.artifacts.filter((a) => a.live === "unknown");
1626
+ const { keep, atRisk } = classifyByOwnReason(input);
1627
+ const { rescued, reap } = applyFloor(keep, atRisk, input.retention.keepLast);
1628
+ return { reap, keep: [...keep, ...rescued], undetermined };
1629
+ }
1630
+
1566
1631
  // src/schema-normalizer.ts
1567
1632
  function isJsonSchemaObject(s) {
1568
1633
  if (typeof s !== "object" || s === null) return false;
@@ -2223,6 +2288,6 @@ function recordWiring(input) {
2223
2288
  return record;
2224
2289
  }
2225
2290
 
2226
- export { AgentFactory, Budget, EventBus, JobQueue, LayerOrderError, Memory, NoopMemoryProvider, PermissionEngine, PermissionPlugin, Plugin, Provider, SOVEREIGN_ENV_KEYS, Security, Skill, SkillReadTool, Squad, Task, Theokit, TokenLimiter, UngatedCapabilityError, UnicodeNormalizer, applyMode, applySecurityFloor, chargeAndCheckThresholds, createCounterBudgetTracker, estimateTokens, extractRawId, foldLayers, inferApiMode, loadProjectEnv, migrateSqliteToLance2 as migrateSqliteToLance, mkMemoryId, normalizeSchema, normalizeUsage, preflightCheck, recordWiring, resolveTrustPosture, runGoalLoop, scopedConversationId, sessionScopePrefix, toShareGptTrajectory, verifyLayerOrdering };
2291
+ export { AgentFactory, Budget, EventBus, JobQueue, LayerOrderError, Memory, NoopMemoryProvider, PermissionEngine, PermissionPlugin, Plugin, Provider, RetentionPolicyError, SOVEREIGN_ENV_KEYS, Security, Skill, SkillReadTool, Squad, Task, Theokit, TokenLimiter, UngatedCapabilityError, UnicodeNormalizer, applyMode, applySecurityFloor, auditEnvReachability, chargeAndCheckThresholds, createCounterBudgetTracker, estimateTokens, extractRawId, foldLayers, inferApiMode, loadProjectEnv, migrateSqliteToLance2 as migrateSqliteToLance, mkMemoryId, normalizeSchema, normalizeUsage, planReaping, preflightCheck, recordWiring, resolveTrustPosture, runGoalLoop, scopedConversationId, sessionScopePrefix, toShareGptTrajectory, verifyLayerOrdering };
2227
2292
  //# sourceMappingURL=index.js.map
2228
2293
  //# sourceMappingURL=index.js.map