@theokit/sdk 4.44.0 → 4.45.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
@@ -1977,6 +1977,64 @@ declare class Security {
1977
1977
  static addPattern(re: RegExp): void;
1978
1978
  }
1979
1979
 
1980
+ /**
1981
+ * Resolve a security-relevant setting across configuration layers, where a lower-trust layer may
1982
+ * TIGHTEN it and never loosen it.
1983
+ *
1984
+ * Layered configuration usually resolves last-wins, and for the keys that decide confinement — a
1985
+ * sandbox mode, an approval policy — last-wins is a hole. With plain precedence a project layer
1986
+ * outranks the user's own file, so a cloned repository can hand itself the most permissive setting
1987
+ * and the operator's global choice loses silently, at the moment the directory is opened. Nothing
1988
+ * fails; the confinement is simply gone.
1989
+ *
1990
+ * ## What is generic here, and what is not
1991
+ *
1992
+ * The RULE is generic: named layers may only move the value in the confining direction, while one
1993
+ * designated layer — the operator's explicit flag — wins in both. The VOCABULARY is not: which
1994
+ * values count as more permissive, what the layers are called, and which one is the operator's are
1995
+ * all the consumer's, and are parameters.
1996
+ *
1997
+ * That distinction is what makes this extractable when a keypress router was not. Here the
1998
+ * vocabulary is DATA — two lists and a name — so a second product supplies its own without
1999
+ * inheriting the first's words. An interface shaped by one product's states would have given the
2000
+ * second consumer something to route around.
2001
+ *
2002
+ * ## Why the override is not validated
2003
+ *
2004
+ * `override` is returned verbatim, even when it is outside `permissiveness`. Validating the
2005
+ * operator's flag is the consumer's job: it owns the vocabulary, the error message and the exit
2006
+ * code. Silently dropping an unrecognised flag would be worse than passing it through — the
2007
+ * operator would see their explicit instruction ignored with no explanation.
2008
+ *
2009
+ * A value outside the vocabulary in a RESTRICTED layer is different and IS ignored: a typo in a
2010
+ * repository's config must neither become the effective setting nor be treated as maximally
2011
+ * permissive.
2012
+ *
2013
+ * @public
2014
+ */
2015
+ /** @public */
2016
+ interface SecurityFloorInput {
2017
+ /**
2018
+ * The vocabulary, ordered from most confined to least. Index is permissiveness, so
2019
+ * `["read-only", "workspace-write", "danger-full-access"]` says read-only confines the most.
2020
+ */
2021
+ readonly permissiveness: readonly string[];
2022
+ /** Layers that may only tighten — typically anything a repository or environment can supply. */
2023
+ readonly restricted: readonly string[];
2024
+ /** The layer that wins outright in both directions — the operator's explicit flag. */
2025
+ readonly override: string;
2026
+ /**
2027
+ * Values per layer. Layers absent from `restricted` are unconstrained, which is how a `user`
2028
+ * layer loosens its own `defaults`.
2029
+ */
2030
+ readonly layers: Readonly<Record<string, string | undefined>>;
2031
+ }
2032
+ /**
2033
+ * @returns the resolved value, or `undefined` when no layer supplied one.
2034
+ * @public
2035
+ */
2036
+ declare function applySecurityFloor(input: SecurityFloorInput): string | undefined;
2037
+
1980
2038
  /**
1981
2039
  * M3 #62 — scoped session state.
1982
2040
  *
@@ -2575,4 +2633,4 @@ declare function toShareGptTrajectory(result: BatchResult, options?: {
2575
2633
  model?: string;
2576
2634
  }): ShareGptTrajectory | null;
2577
2635
 
2578
- 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 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, 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 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, UnicodeNormalizer, type UnicodeNormalizerOptions, UsageAccumulator, chargeAndCheckThresholds, computeCost, createCounterBudgetTracker, estimateTokens, extractRawId, getPricingEntry, inferApiMode, isValidTaskId, loadProjectEnv, migrateSqliteToLance, mkMemoryId, normalizeSchema, normalizeUsage, preflightCheck, runGoalLoop, scopedConversationId, sessionScopePrefix, setDiagnosticsSink, toShareGptTrajectory, withCwdMutex };
2636
+ 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 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, 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, UnicodeNormalizer, type UnicodeNormalizerOptions, UsageAccumulator, applySecurityFloor, chargeAndCheckThresholds, computeCost, createCounterBudgetTracker, estimateTokens, extractRawId, getPricingEntry, inferApiMode, isValidTaskId, loadProjectEnv, migrateSqliteToLance, mkMemoryId, normalizeSchema, normalizeUsage, preflightCheck, runGoalLoop, scopedConversationId, sessionScopePrefix, setDiagnosticsSink, toShareGptTrajectory, withCwdMutex };
package/dist/index.d.ts CHANGED
@@ -1977,6 +1977,64 @@ declare class Security {
1977
1977
  static addPattern(re: RegExp): void;
1978
1978
  }
1979
1979
 
1980
+ /**
1981
+ * Resolve a security-relevant setting across configuration layers, where a lower-trust layer may
1982
+ * TIGHTEN it and never loosen it.
1983
+ *
1984
+ * Layered configuration usually resolves last-wins, and for the keys that decide confinement — a
1985
+ * sandbox mode, an approval policy — last-wins is a hole. With plain precedence a project layer
1986
+ * outranks the user's own file, so a cloned repository can hand itself the most permissive setting
1987
+ * and the operator's global choice loses silently, at the moment the directory is opened. Nothing
1988
+ * fails; the confinement is simply gone.
1989
+ *
1990
+ * ## What is generic here, and what is not
1991
+ *
1992
+ * The RULE is generic: named layers may only move the value in the confining direction, while one
1993
+ * designated layer — the operator's explicit flag — wins in both. The VOCABULARY is not: which
1994
+ * values count as more permissive, what the layers are called, and which one is the operator's are
1995
+ * all the consumer's, and are parameters.
1996
+ *
1997
+ * That distinction is what makes this extractable when a keypress router was not. Here the
1998
+ * vocabulary is DATA — two lists and a name — so a second product supplies its own without
1999
+ * inheriting the first's words. An interface shaped by one product's states would have given the
2000
+ * second consumer something to route around.
2001
+ *
2002
+ * ## Why the override is not validated
2003
+ *
2004
+ * `override` is returned verbatim, even when it is outside `permissiveness`. Validating the
2005
+ * operator's flag is the consumer's job: it owns the vocabulary, the error message and the exit
2006
+ * code. Silently dropping an unrecognised flag would be worse than passing it through — the
2007
+ * operator would see their explicit instruction ignored with no explanation.
2008
+ *
2009
+ * A value outside the vocabulary in a RESTRICTED layer is different and IS ignored: a typo in a
2010
+ * repository's config must neither become the effective setting nor be treated as maximally
2011
+ * permissive.
2012
+ *
2013
+ * @public
2014
+ */
2015
+ /** @public */
2016
+ interface SecurityFloorInput {
2017
+ /**
2018
+ * The vocabulary, ordered from most confined to least. Index is permissiveness, so
2019
+ * `["read-only", "workspace-write", "danger-full-access"]` says read-only confines the most.
2020
+ */
2021
+ readonly permissiveness: readonly string[];
2022
+ /** Layers that may only tighten — typically anything a repository or environment can supply. */
2023
+ readonly restricted: readonly string[];
2024
+ /** The layer that wins outright in both directions — the operator's explicit flag. */
2025
+ readonly override: string;
2026
+ /**
2027
+ * Values per layer. Layers absent from `restricted` are unconstrained, which is how a `user`
2028
+ * layer loosens its own `defaults`.
2029
+ */
2030
+ readonly layers: Readonly<Record<string, string | undefined>>;
2031
+ }
2032
+ /**
2033
+ * @returns the resolved value, or `undefined` when no layer supplied one.
2034
+ * @public
2035
+ */
2036
+ declare function applySecurityFloor(input: SecurityFloorInput): string | undefined;
2037
+
1980
2038
  /**
1981
2039
  * M3 #62 — scoped session state.
1982
2040
  *
@@ -2575,4 +2633,4 @@ declare function toShareGptTrajectory(result: BatchResult, options?: {
2575
2633
  model?: string;
2576
2634
  }): ShareGptTrajectory | null;
2577
2635
 
2578
- 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 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, 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 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, UnicodeNormalizer, type UnicodeNormalizerOptions, UsageAccumulator, chargeAndCheckThresholds, computeCost, createCounterBudgetTracker, estimateTokens, extractRawId, getPricingEntry, inferApiMode, isValidTaskId, loadProjectEnv, migrateSqliteToLance, mkMemoryId, normalizeSchema, normalizeUsage, preflightCheck, runGoalLoop, scopedConversationId, sessionScopePrefix, setDiagnosticsSink, toShareGptTrajectory, withCwdMutex };
2636
+ 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 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, 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, UnicodeNormalizer, type UnicodeNormalizerOptions, UsageAccumulator, applySecurityFloor, chargeAndCheckThresholds, computeCost, createCounterBudgetTracker, estimateTokens, extractRawId, getPricingEntry, inferApiMode, isValidTaskId, loadProjectEnv, migrateSqliteToLance, mkMemoryId, normalizeSchema, normalizeUsage, preflightCheck, runGoalLoop, scopedConversationId, sessionScopePrefix, setDiagnosticsSink, toShareGptTrajectory, withCwdMutex };
package/dist/index.js CHANGED
@@ -1624,6 +1624,39 @@ var Security = class {
1624
1624
  }
1625
1625
  };
1626
1626
 
1627
+ // src/security-floor.ts
1628
+ function permissivenessOf(order, value) {
1629
+ if (value === void 0) return -1;
1630
+ return order.indexOf(value);
1631
+ }
1632
+ function baseline(input) {
1633
+ const { restricted, override, layers } = input;
1634
+ let value;
1635
+ for (const [name, candidate] of Object.entries(layers)) {
1636
+ if (name === override || restricted.includes(name)) continue;
1637
+ if (candidate !== void 0) value = candidate;
1638
+ }
1639
+ return value;
1640
+ }
1641
+ function tightenOnly(input, start) {
1642
+ const { permissiveness, restricted, layers } = input;
1643
+ let resolved = start;
1644
+ let ceiling = permissivenessOf(permissiveness, start);
1645
+ for (const layer of restricted) {
1646
+ const candidate = layers[layer];
1647
+ if (candidate === void 0) continue;
1648
+ const level = permissivenessOf(permissiveness, candidate);
1649
+ if (level < 0) continue;
1650
+ if (ceiling >= 0 && level > ceiling) continue;
1651
+ resolved = candidate;
1652
+ ceiling = level;
1653
+ }
1654
+ return resolved;
1655
+ }
1656
+ function applySecurityFloor(input) {
1657
+ return input.layers[input.override] ?? tightenOnly(input, baseline(input));
1658
+ }
1659
+
1627
1660
  // src/session-scope.ts
1628
1661
  function scopedConversationId(scope, id) {
1629
1662
  return `${scope}__${id}`;
@@ -2122,6 +2155,6 @@ function safeStringify(v) {
2122
2155
  }
2123
2156
  }
2124
2157
 
2125
- export { AgentFactory, Budget, EventBus, JobQueue, Memory, NoopMemoryProvider, PermissionEngine, PermissionPlugin, Plugin, Provider, SOVEREIGN_ENV_KEYS, Security, Skill, SkillReadTool, Squad, Task, Theokit, TokenLimiter, UnicodeNormalizer, applyMode, chargeAndCheckThresholds, createCounterBudgetTracker, estimateTokens, extractRawId, inferApiMode, loadProjectEnv, migrateSqliteToLance2 as migrateSqliteToLance, mkMemoryId, normalizeSchema, normalizeUsage, preflightCheck, runGoalLoop, scopedConversationId, sessionScopePrefix, toShareGptTrajectory };
2158
+ export { AgentFactory, Budget, EventBus, JobQueue, Memory, NoopMemoryProvider, PermissionEngine, PermissionPlugin, Plugin, Provider, SOVEREIGN_ENV_KEYS, Security, Skill, SkillReadTool, Squad, Task, Theokit, TokenLimiter, UnicodeNormalizer, applyMode, applySecurityFloor, chargeAndCheckThresholds, createCounterBudgetTracker, estimateTokens, extractRawId, inferApiMode, loadProjectEnv, migrateSqliteToLance2 as migrateSqliteToLance, mkMemoryId, normalizeSchema, normalizeUsage, preflightCheck, runGoalLoop, scopedConversationId, sessionScopePrefix, toShareGptTrajectory };
2126
2159
  //# sourceMappingURL=index.js.map
2127
2160
  //# sourceMappingURL=index.js.map