@stratusagent/core 0.13.6 → 0.14.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.
@@ -0,0 +1 @@
1
+ {"version":3,"file":"channels.d.ts","sourceRoot":"","sources":["../src/channels.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,eAAe,EACf,cAAc,EACd,eAAe,EACf,QAAQ,EACR,eAAe,EACf,UAAU,EACV,OAAO,EACP,UAAU,EACX,MAAM,YAAY,CAAC;AAEpB;;;GAGG;AACH,MAAM,WAAW,cAAc;IAC7B,kCAAkC;IAClC,OAAO,EAAE,MAAM,CAAC;IAChB,mCAAmC;IACnC,IAAI,EAAE,MAAM,CAAC;IACb,sDAAsD;IACtD,YAAY,EAAE,MAAM,CAAC;IACrB;;;;OAIG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,WAAW,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IAC7C,iEAAiE;IACjE,IAAI,EAAE,MAAM,CAAC;IACb,kEAAkE;IAClE,aAAa,EAAE,OAAO,CAAC;IACvB,sDAAsD;IACtD,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,+DAA+D;AAC/D,MAAM,WAAW,kBAAkB;IACjC,OAAO,EAAE,MAAM,CAAC;IAChB,EAAE,EAAE,MAAM,CAAC;CACZ;AAED;;;;;;;;;;;;GAYG;AACH,MAAM,WAAW,kBAAkB;IACjC,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAAC;IAChD;;;OAGG;IACH,IAAI,CAAC,CAAC,GAAG,EAAE,kBAAkB,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC5D;;;;OAIG;IACH,MAAM,CAAC,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,OAAO,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IACH,mBAAmB,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,GAAG,QAAQ,GAAG,SAAS,CAAC,CAAC;CACxG;AAED,MAAM,WAAW,sBAAsB;IACrC,kCAAkC;IAClC,OAAO,EAAE,MAAM,CAAC;IAChB,iFAAiF;IACjF,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,YAAY,EAAE,MAAM,CAAC;IACrB;;;;OAIG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED;;;;;;;GAOG;AACH,eAAO,MAAM,iBAAiB,GAAI,OAAO,sBAAsB,KAAG,MAMjE,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,MAAM,WAAW,GAAG,QAAQ,GAAG,YAAY,CAAC;AAElD;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,WAAW,YAAY;IAC3B,UAAU,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAC/B,KAAK,CAAC,EAAE,WAAW,CAAC;CACrB;AAED,6DAA6D;AAC7D,eAAO,MAAM,WAAW,GAAI,QAAQ,YAAY,GAAG,SAAS,EAAE,UAAU,MAAM,KAAG,OAClC,CAAC;AAEhD;;;;GAIG;AACH,eAAO,MAAM,YAAY,GAAI,QAAQ,YAAY,GAAG,SAAS,EAAE,UAAU,MAAM,KAAG,OACM,CAAC;AAEzF;;;;;GAKG;AACH,eAAO,MAAM,cAAc,GAAI,QAAQ,YAAY,GAAG,SAAS,EAAE,UAAU,MAAM,KAAG,OAAO,CAAC,UAAU,EAAE,MAAM,GAAG,SAAS,CACtE,CAAC"}
@@ -0,0 +1,31 @@
1
+ /**
2
+ * The stable session id for one conversation: `channel:agent:team:conversation[:thread]`.
3
+ * Stable means resumable — any later message with the same parts lands in
4
+ * the same session, across daemon restarts included. Callers pass
5
+ * `thread_ts ?? ts` as the thread for channel messages (a top-level mention
6
+ * roots its own reply-thread conversation), no thread for a DM's top level,
7
+ * and the thread's root for a reply in a DM thread.
8
+ */
9
+ export const channelSessionKey = (parts) => {
10
+ const segments = [parts.channel, parts.agentId, parts.team, parts.conversation];
11
+ if (parts.thread) {
12
+ segments.push(parts.thread);
13
+ }
14
+ return segments.join(':');
15
+ };
16
+ /** Whether `senderId` is on the policy's principals list. */
17
+ export const isPrincipal = (policy, senderId) => (policy?.principals ?? []).includes(senderId);
18
+ /**
19
+ * Whether a message from `senderId` may start a turn. No policy admits:
20
+ * there is nobody's list to refuse against, which is the answer from
21
+ * before admission existed.
22
+ */
23
+ export const admitsSender = (policy, senderId) => policy === undefined || policy.admit !== 'principals' || isPrincipal(policy, senderId);
24
+ /**
25
+ * The trust label a turn from `senderId` carries (`SENDER_TRUST_METADATA_KEY`
26
+ * in `@stratusagent/core`): `user` for a principal, `unknown` for anyone else.
27
+ * Evaluated per message, never per session: a group conversation keys one
28
+ * session for everyone in it.
29
+ */
30
+ export const senderTrustFor = (policy, senderId) => isPrincipal(policy, senderId) ? 'user' : 'unknown';
31
+ //# sourceMappingURL=channels.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"channels.js","sourceRoot":"","sources":["../src/channels.ts"],"names":[],"mappings":"AAknBA;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,KAA6B,EAAU,EAAE;IACzE,MAAM,QAAQ,GAAG,CAAC,KAAK,CAAC,OAAO,EAAE,KAAK,CAAC,OAAO,EAAE,KAAK,CAAC,IAAI,EAAE,KAAK,CAAC,YAAY,CAAC,CAAC;IAChF,IAAI,KAAK,CAAC,MAAM,EAAE,CAAC;QACjB,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;IAC9B,CAAC;IACD,OAAO,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAC5B,CAAC,CAAC;AAiCF,6DAA6D;AAC7D,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,MAAgC,EAAE,QAAgB,EAAW,EAAE,CACzF,CAAC,MAAM,EAAE,UAAU,IAAI,EAAE,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;AAEhD;;;;GAIG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,MAAgC,EAAE,QAAgB,EAAW,EAAE,CAC1F,MAAM,KAAK,SAAS,IAAI,MAAM,CAAC,KAAK,KAAK,YAAY,IAAI,WAAW,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;AAEzF;;;;;GAKG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,MAAgC,EAAE,QAAgB,EAA2C,EAAE,CAC5H,WAAW,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC"}
@@ -0,0 +1,35 @@
1
+ import { type ExecutionContext, type Executor, type JsonValue, type Session, type Tool, type ToolCall, type ToolResult, type TrustLevel } from './index.ts';
2
+ export interface ExecutorResultCallRef {
3
+ id: string;
4
+ toolName: string;
5
+ }
6
+ export declare const normalizeExecutorError: (error: unknown) => string;
7
+ /**
8
+ * A successful result, labelled. `trust` is what the executor resolved from
9
+ * the tool's producer channels (`createTrustMarking`); a caller building a
10
+ * result by hand with no idea where the content came from should say
11
+ * `unknown` rather than take the default, which is the label for a tool
12
+ * that declared nothing and marked nothing — its own work.
13
+ */
14
+ export declare const successResult: (call: ToolCall | ExecutorResultCallRef, output: JsonValue, trust?: TrustLevel) => ToolResult;
15
+ export declare const failureResult: (call: ToolCall | ExecutorResultCallRef, error: unknown, output?: JsonValue, trust?: TrustLevel) => ToolResult;
16
+ export interface ExecutorDefinition {
17
+ execute(call: ToolCall, tool: Tool, session: Session, context?: ExecutionContext): Promise<ToolResult>;
18
+ }
19
+ export declare const defineExecutor: ({ execute }: ExecutorDefinition) => Executor;
20
+ export interface DirectExecutorErrorContext {
21
+ call: ToolCall;
22
+ tool: Tool;
23
+ session: Session;
24
+ error: unknown;
25
+ }
26
+ export interface DirectExecutorOptions {
27
+ onError?: (context: DirectExecutorErrorContext) => ToolResult | Promise<ToolResult>;
28
+ }
29
+ export declare class DirectExecutor implements Executor {
30
+ private readonly onError?;
31
+ constructor(options?: DirectExecutorOptions);
32
+ execute(call: ToolCall, tool: Tool, session: Session, context?: ExecutionContext): Promise<ToolResult>;
33
+ }
34
+ export declare const createDirectExecutor: (options?: DirectExecutorOptions) => Executor;
35
+ //# sourceMappingURL=executors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"executors.d.ts","sourceRoot":"","sources":["../src/executors.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,gBAAgB,EACrB,KAAK,QAAQ,EACb,KAAK,SAAS,EACd,KAAK,OAAO,EACZ,KAAK,IAAI,EACT,KAAK,QAAQ,EACb,KAAK,UAAU,EACf,KAAK,UAAU,EAChB,MAAM,YAAY,CAAC;AAEpB,MAAM,WAAW,qBAAqB;IACpC,EAAE,EAAE,MAAM,CAAC;IACX,QAAQ,EAAE,MAAM,CAAC;CAClB;AAOD,eAAO,MAAM,sBAAsB,GAAI,OAAO,OAAO,KAAG,MACA,CAAC;AAEzD;;;;;;GAMG;AACH,eAAO,MAAM,aAAa,GACxB,MAAM,QAAQ,GAAG,qBAAqB,EACtC,QAAQ,SAAS,EACjB,QAAO,UAAoB,KAC1B,UASF,CAAC;AAEF,eAAO,MAAM,aAAa,GACxB,MAAM,QAAQ,GAAG,qBAAqB,EACtC,OAAO,OAAO,EACd,SAAQ,SAAgB,EACxB,QAAO,UAAoB,KAC1B,UAUF,CAAC;AAEF,MAAM,WAAW,kBAAkB;IACjC,OAAO,CAAC,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,gBAAgB,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;CACxG;AAED,eAAO,MAAM,cAAc,GAAI,aAAa,kBAAkB,KAAG,QAE/D,CAAC;AAEH,MAAM,WAAW,0BAA0B;IACzC,IAAI,EAAE,QAAQ,CAAC;IACf,IAAI,EAAE,IAAI,CAAC;IACX,OAAO,EAAE,OAAO,CAAC;IACjB,KAAK,EAAE,OAAO,CAAC;CAChB;AAED,MAAM,WAAW,qBAAqB;IACpC,OAAO,CAAC,EAAE,CAAC,OAAO,EAAE,0BAA0B,KAAK,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;CACrF;AAED,qBAAa,cAAe,YAAW,QAAQ;IAC7C,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAmC;gBAEhD,OAAO,GAAE,qBAA0B;IAIzC,OAAO,CAAC,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,gBAAgB,GAAG,OAAO,CAAC,UAAU,CAAC;CAmB7G;AAED,eAAO,MAAM,oBAAoB,GAAI,UAAS,qBAA0B,KAAG,QAC9C,CAAC"}
@@ -0,0 +1,64 @@
1
+ import { createTrustMarking, leastTrusted, } from "./index.js";
2
+ const toCallRef = (call) => ({
3
+ id: call.id,
4
+ toolName: call.toolName,
5
+ });
6
+ export const normalizeExecutorError = (error) => error instanceof Error ? error.message : String(error);
7
+ /**
8
+ * A successful result, labelled. `trust` is what the executor resolved from
9
+ * the tool's producer channels (`createTrustMarking`); a caller building a
10
+ * result by hand with no idea where the content came from should say
11
+ * `unknown` rather than take the default, which is the label for a tool
12
+ * that declared nothing and marked nothing — its own work.
13
+ */
14
+ export const successResult = (call, output, trust = 'agent') => {
15
+ const ref = toCallRef(call);
16
+ return {
17
+ callId: ref.id,
18
+ toolName: ref.toolName,
19
+ ok: true,
20
+ output,
21
+ trust,
22
+ };
23
+ };
24
+ export const failureResult = (call, error, output = null, trust = 'agent') => {
25
+ const ref = toCallRef(call);
26
+ return {
27
+ callId: ref.id,
28
+ toolName: ref.toolName,
29
+ ok: false,
30
+ output,
31
+ error: normalizeExecutorError(error),
32
+ trust,
33
+ };
34
+ };
35
+ export const defineExecutor = ({ execute }) => ({
36
+ execute,
37
+ });
38
+ export class DirectExecutor {
39
+ onError;
40
+ constructor(options = {}) {
41
+ this.onError = options.onError;
42
+ }
43
+ async execute(call, tool, session, context) {
44
+ const marking = createTrustMarking(tool, context);
45
+ try {
46
+ const output = await tool.execute(call.input, session, marking.context);
47
+ return successResult(call, output, marking.resolve());
48
+ }
49
+ catch (error) {
50
+ if (this.onError) {
51
+ // The tool's channels set the floor: a mapper may lower the label
52
+ // further (it knows what it wrapped) but never raise it — the error
53
+ // it is wrapping may quote a server, and `failureResult`'s default
54
+ // is `agent`, which a mapper reaching for the helper would
55
+ // otherwise hand an `external` tool's error text.
56
+ const mapped = await this.onError({ call, tool, session, error });
57
+ return { ...mapped, trust: leastTrusted(marking.resolve(), mapped.trust ?? 'agent') };
58
+ }
59
+ return failureResult(call, error, null, marking.resolve());
60
+ }
61
+ }
62
+ }
63
+ export const createDirectExecutor = (options = {}) => new DirectExecutor(options);
64
+ //# sourceMappingURL=executors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"executors.js","sourceRoot":"","sources":["../src/executors.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kBAAkB,EAClB,YAAY,GASb,MAAM,YAAY,CAAC;AAOpB,MAAM,SAAS,GAAG,CAAC,IAAsC,EAAyB,EAAE,CAAC,CAAC;IACpF,EAAE,EAAE,IAAI,CAAC,EAAE;IACX,QAAQ,EAAE,IAAI,CAAC,QAAQ;CACxB,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAAC,KAAc,EAAU,EAAE,CAC/D,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AAEzD;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,CAC3B,IAAsC,EACtC,MAAiB,EACjB,QAAoB,OAAO,EACf,EAAE;IAC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AC;YACf,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;gBACjB,kEAAkE;gBAClE,oEAAoE;gBACpE,mEAAmE;gBACnE,2DAA2D;gBAC3D,kDAAkD;gBAClD,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC,CAAC;gBAClE,OAAO,EAAE,GAAG,MAAM,EAAE,KAAK,EAAE,YAAY,CAAC,OAAO,CAAC,OAAO,EAAE,EAAE,MAAM,CAAC,KAAK,IAAI,OAAO,CAAC,EAAE,CAAC;YACxF,CAAC;YAED,OAAO,aAAa,CAAC,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC;QAC7D,CAAC;IACH,CAAC;CACF;AAED,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,UAAiC,EAAE,EAAY,EAAE,CACpF,IAAI,cAAc,CAAC,OAAO,CAAC,CAAC"}
package/dist/index.d.ts CHANGED
@@ -1503,6 +1503,21 @@ export type CredentialScope = 'agent' | 'shared';
1503
1503
  export type CredentialDelivery = 'form' | 'link';
1504
1504
  export interface CredentialResolver {
1505
1505
  resolve(agent: AgentDefinition, name: string): Promise<string | undefined>;
1506
+ /**
1507
+ * The environment variables this agent's stored keys were bound to, with
1508
+ * their values, read now: an approver answered a form that said the key
1509
+ * would be readable by this agent's shell as that variable, or an
1510
+ * operator bound it with `stratus credential env`. Only names the agent's
1511
+ * `credentials:` list grants, by `assertCredentialAllowed`'s rule
1512
+ * (skipped rather than thrown), and a bound name with nothing stored is
1513
+ * left out.
1514
+ *
1515
+ * Optional: a host that omits it has no bindings, and its shell commands
1516
+ * see only what the operator's config maps. A plugin is handed it only
1517
+ * when its manifest says `"envBindings": true`, since the values it
1518
+ * returns are names the manifest never listed.
1519
+ */
1520
+ envBindings?(agent: AgentDefinition): Promise<Record<string, string>>;
1506
1521
  }
1507
1522
  export interface ScopedCredentials {
1508
1523
  get(name: string): Promise<string>;
@@ -1590,6 +1605,21 @@ export interface UsageRecord extends TokenUsage {
1590
1605
  turnId: string;
1591
1606
  provider: string;
1592
1607
  model?: string;
1608
+ /**
1609
+ * Unique to this one provider call, assigned when the record is made and
1610
+ * saved with it. What lets a consumer that meters spend outside the
1611
+ * session (a usage ledger) count each call exactly once however many
1612
+ * times it sees it: from the `session.usage` announcement, and again from
1613
+ * the saved session after a crash that came between the save and the
1614
+ * announcement. Absent on records saved before it existed.
1615
+ */
1616
+ id?: string;
1617
+ /**
1618
+ * When the call's usage was recorded, ISO 8601. A consumer that learns of
1619
+ * a call late (reconciling a session after a crash) still files it under
1620
+ * the day it was spent. Absent on records saved before it existed.
1621
+ */
1622
+ at?: string;
1593
1623
  }
1594
1624
  /**
1595
1625
  * `TokenUsage.inputTokens` for a vendor that reports its prompt count
@@ -1814,6 +1844,18 @@ export interface ProviderRequest {
1814
1844
  * turn that actually succeeded goes uncounted.
1815
1845
  */
1816
1846
  onUsage?: (usage: ProviderCallUsage) => void;
1847
+ /**
1848
+ * For a provider that makes another model call inside one `generate` on
1849
+ * its own decision, the fallback wrapper's switch being the live example:
1850
+ * await this before that call, naming the provider about to answer. The
1851
+ * runner announces the usage reported so far, then asks the host's
1852
+ * `ProviderCallGuard`s, so a budget the first call just spent is read
1853
+ * before the next one starts. It resolves to allow the call and throws to
1854
+ * refuse it; let the error propagate, because a refusal ends the turn.
1855
+ *
1856
+ * Not for a harness's own inner calls, which this interface never sees.
1857
+ */
1858
+ guardCall?: (provider: string) => Promise<void>;
1817
1859
  /**
1818
1860
  * For a provider that runs its own tool loop (the harness runtimes): ask,
1819
1861
  * when its inner budget runs out mid-work, whether to carry on with a
@@ -1851,8 +1893,46 @@ export interface ProviderResponse {
1851
1893
  }
1852
1894
  export interface ModelProvider {
1853
1895
  name: string;
1896
+ /**
1897
+ * For a provider that hands a session's calls to another provider while
1898
+ * keeping its own `name` (the fallback wrapper, once a session has
1899
+ * switched): the name of the provider that answers this session's next
1900
+ * call. The `ProviderCallGuard`s are told it, so a rule about one model
1901
+ * holds whichever wrapper it sits behind. Absent means `name`.
1902
+ */
1903
+ nameFor?(session: Session): string;
1854
1904
  generate(request: ProviderRequest): Promise<ProviderResponse>;
1855
1905
  }
1906
+ /** Who is about to spend a provider call: what a `ProviderCallGuard` is asked about. */
1907
+ export interface ProviderCallCheck {
1908
+ agentId: string;
1909
+ sessionId: string;
1910
+ /**
1911
+ * The provider about to answer, by name: the runner's provider, or the
1912
+ * one it says answers this session (`ModelProvider.nameFor`). Under a
1913
+ * configured fallback that is the primary until the session switches and
1914
+ * the fallback after. A switch inside a call asks again before the
1915
+ * fallback's call, naming the fallback (`ProviderRequest.guardCall`).
1916
+ */
1917
+ provider: string;
1918
+ }
1919
+ /**
1920
+ * A host's say over each provider call before it is made: a token budget
1921
+ * is the case it exists for. Resolving allows the call. Throwing refuses
1922
+ * it and fails the turn: a `HostRefusalError` for a refusal made on purpose,
1923
+ * whose message is a sentence for the person in the conversation, and any
1924
+ * other error for a guard that could not decide, which refuses as well,
1925
+ * because a budget that cannot be read is not a budget that said yes.
1926
+ *
1927
+ * Asked once per `ModelProvider.generate`, which is one model call for the
1928
+ * kernel-loop adapters and one Stratus turn for a harness running its own
1929
+ * inner loop, and again before any further call a provider makes inside one
1930
+ * `generate` and asks about through `ProviderRequest.guardCall` (the
1931
+ * fallback model's call after the primary fails). The usage of every
1932
+ * earlier call has been announced (`session.usage`) before a guard is asked
1933
+ * about the next one.
1934
+ */
1935
+ export type ProviderCallGuard = (check: ProviderCallCheck) => Promise<void> | void;
1856
1936
  /**
1857
1937
  * What a scrubbed subprocess inherits by name when its operator granted
1858
1938
  * nothing else — the replacement-environment treatment `tool-shell`
@@ -1870,7 +1950,9 @@ export declare const DEFAULT_SUBPROCESS_PASS_ENV: readonly string[];
1870
1950
  /**
1871
1951
  * Ambient context for one tool execution. The abort signal is the turn's:
1872
1952
  * executors kill in-flight subprocesses on abort, and long-running tools
1873
- * should observe it too.
1953
+ * should observe it too. One that does not is left behind a short grace
1954
+ * after the abort (`untilStoppedFor`), still running, with a result that
1955
+ * says so.
1874
1956
  */
1875
1957
  export interface ExecutionContext {
1876
1958
  signal?: AbortSignal;
@@ -2583,6 +2665,8 @@ export type StratusEvent = {
2583
2665
  via?: CredentialDelivery;
2584
2666
  /** A new value for a key the agent already holds, swapped in place. Always a form, never a link. */
2585
2667
  replace?: boolean;
2668
+ /** The variable the agent's shell commands will read the key from once it is added. */
2669
+ env?: string;
2586
2670
  metadata?: JsonObject;
2587
2671
  }
2588
2672
  /**
@@ -2606,6 +2690,8 @@ export type StratusEvent = {
2606
2690
  actor?: string;
2607
2691
  /** The value replaced one already stored, rather than being added. */
2608
2692
  replace?: boolean;
2693
+ /** The variable the agent's shell commands now read the key from. */
2694
+ env?: string;
2609
2695
  /** Set when the key was stored but could not be added to the soul. */
2610
2696
  grantError?: string;
2611
2697
  } | {
@@ -2626,6 +2712,36 @@ export type StratusEvent = {
2626
2712
  type: 'session.failed';
2627
2713
  sessionId: string;
2628
2714
  error: string;
2715
+ /**
2716
+ * True when the host stopped the turn on purpose (`HostRefusalError`):
2717
+ * `error` is then a sentence meant for the person in the conversation,
2718
+ * and a renderer shows it as it is rather than as a malfunction.
2719
+ */
2720
+ refused?: true;
2721
+ }
2722
+ /**
2723
+ * Usage a provider call just reported, as it lands: the records added to
2724
+ * the session since the last announcement, in the order they were
2725
+ * recorded. A harness reporting inner calls through the sink is announced
2726
+ * as each report arrives, while its `generate` is still running, so a
2727
+ * daemon that dies mid-call has already told a ledger what was spent.
2728
+ *
2729
+ * Per call rather than once per turn because a turn can make many calls,
2730
+ * and a host enforcing a budget has to know what the call before this one
2731
+ * spent before it allows the next. `session.completed` arrives too late
2732
+ * for that and is never sent for a turn that failed. Emitted for a failed
2733
+ * attempt too, whenever it reported anything: the tokens of a call that
2734
+ * threw were still spent. `agentId` rides along so a consumer
2735
+ * attributing spend to an agent needs no store read.
2736
+ *
2737
+ * Counts and attribution only, the same records `session.completed`
2738
+ * carries, ids included.
2739
+ */
2740
+ | {
2741
+ type: 'session.usage';
2742
+ sessionId: string;
2743
+ agentId: string;
2744
+ records: UsageRecord[];
2629
2745
  }
2630
2746
  /**
2631
2747
  * The session's trust label went down. `source` names what lowered it —
@@ -2768,11 +2884,11 @@ export interface ProviderContribution {
2768
2884
  streams?: boolean;
2769
2885
  }
2770
2886
  /**
2771
- * The slice of a channel adapter the kernel holds: structurally
2772
- * `@stratusagent/channels`' `ChannelAdapter`, kept structural here so core
2773
- * carries no dependency on the channels package — the same reason the
2774
- * gateway declares its own copy. `name` is the channel kind (`slack`,
2775
- * `discord`); the gateway it is started with is the host's.
2887
+ * The slice of a channel adapter the kernel holds: structurally the
2888
+ * `ChannelAdapter` in `channels.ts`, declared on its own because it
2889
+ * predates that contract moving into core (the gateway keeps a copy for
2890
+ * the same reason). `name` is the channel kind (`slack`, `discord`); the
2891
+ * gateway it is started with is the host's.
2776
2892
  */
2777
2893
  export interface ChannelAdapterLike {
2778
2894
  name: string;
@@ -2786,7 +2902,7 @@ export interface ChannelAdapterLike {
2786
2902
  }): Promise<{
2787
2903
  post(text: string): Promise<unknown>;
2788
2904
  }>;
2789
- /** See `@stratusagent/channels`' `ChannelAdapter.readConversation`. */
2905
+ /** See `ChannelAdapter.readConversation`. */
2790
2906
  readConversation?(request: {
2791
2907
  agentId: string;
2792
2908
  conversation: string;
@@ -2794,6 +2910,7 @@ export interface ChannelAdapterLike {
2794
2910
  after?: string;
2795
2911
  before?: string;
2796
2912
  limit: number;
2913
+ sessionId?: string;
2797
2914
  }): Promise<{
2798
2915
  messages: Array<{
2799
2916
  id: string;
@@ -2806,11 +2923,40 @@ export interface ChannelAdapterLike {
2806
2923
  files?: string[];
2807
2924
  }>;
2808
2925
  more: boolean;
2926
+ bookmarks?: Array<{
2927
+ title: string;
2928
+ link: string;
2929
+ }>;
2930
+ bookmarksUnavailable?: string;
2931
+ bookmarksOmitted?: number;
2932
+ }>;
2933
+ /** See `ChannelAdapter.createConversation`. */
2934
+ createConversation?(request: {
2935
+ agentId: string;
2936
+ name: string;
2937
+ private?: boolean;
2938
+ topic?: string;
2939
+ purpose?: string;
2940
+ invite?: string[];
2941
+ }): Promise<{
2942
+ conversation: string;
2943
+ name: string;
2944
+ invited: string[];
2945
+ notInvited: Array<{
2946
+ who: string;
2947
+ reason: string;
2948
+ }>;
2949
+ notSet: Array<{
2950
+ field: 'topic' | 'purpose';
2951
+ reason: string;
2952
+ }>;
2809
2953
  }>;
2810
- /** See `@stratusagent/channels`' `ChannelAdapter.accountFor`. */
2954
+ /** See `ChannelAdapter.accountFor`. */
2811
2955
  accountFor?(agentId: string): string | undefined;
2812
- /** See `@stratusagent/channels`' `ChannelAdapter.conversationKindFor`. */
2956
+ /** See `ChannelAdapter.conversationKindFor`. */
2813
2957
  conversationKindFor?(agentId: string, conversation: string): Promise<'channel' | 'direct' | undefined>;
2958
+ /** See `ChannelAdapter.sessionConversation`. */
2959
+ sessionConversation?(agentId: string, sessionId: string): string | undefined;
2814
2960
  }
2815
2961
  /**
2816
2962
  * A channel contributed by a plugin: the adapter plus the agents it
@@ -3269,6 +3415,18 @@ export interface PluginContext {
3269
3415
  * `setup` naming it.
3270
3416
  */
3271
3417
  fleet?: FleetReader;
3418
+ /**
3419
+ * Registers a guard the host asks before every provider call. See
3420
+ * {@link ProviderCallGuard}. A host passing it enforces what is
3421
+ * registered for every agent it runs, sub-agents included. A host that
3422
+ * omits it cannot enforce one, and a plugin that needs it (a budget) must
3423
+ * fail its `setup` naming it: a limit nothing enforces must not report
3424
+ * itself loaded.
3425
+ */
3426
+ providerCalls?: ProviderCallGuardHandle;
3427
+ }
3428
+ export interface ProviderCallGuardHandle {
3429
+ register(guard: ProviderCallGuard): void;
3272
3430
  }
3273
3431
  export interface Plugin {
3274
3432
  name: string;
@@ -3616,12 +3774,23 @@ export declare const isLanguageTag: (value: unknown) => value is string;
3616
3774
  *
3617
3775
  * The accuracy rules are here for the same reason, each after an incident:
3618
3776
  * an agent with no Slack tool insisted it had no Slack connection, and
3619
- * agents reported work as done that had only been drafted. The language
3620
- * rule is here because the default persona is not: a custom soul replaces
3621
- * it, and an agent wrote "favour" and "licence" into American website copy
3622
- * because nothing shared said which English. A pasted British paragraph is
3623
- * not a setting, so the rule says a task or a client's style guide decides
3624
- * one deliverable and nothing is inferred from source text.
3777
+ * agents reported work as done that had only been drafted. The
3778
+ * look-before-you-ask pair is there because a conversation's session holds
3779
+ * its own messages and a slice of memory, nothing more: when work moved to
3780
+ * a new channel, the agent's session there asked the person what its own
3781
+ * earlier thread and files already said. Pointers, not a brief at session
3782
+ * open, because the thread and the file were both in reach and nothing said
3783
+ * to look. What it finds is linked, or asked about before it is repeated,
3784
+ * unless it can tell everyone in the room could already see it. The room
3785
+ * context gives only this room's kind and size, and a read returns no
3786
+ * membership, so the agent cannot check another conversation's audience; a
3787
+ * link is checked by the channel itself, and a file cannot be linked, so it
3788
+ * asks. The language rule is here because the default persona is not: a
3789
+ * custom soul replaces it, and an agent wrote "favour" and "licence" into
3790
+ * American website copy because nothing shared said which English. A pasted
3791
+ * British paragraph is not a setting, so the rule says a task or a client's
3792
+ * style guide decides one deliverable and nothing is inferred from source
3793
+ * text.
3625
3794
  *
3626
3795
  * The last sentence lets the soul and the person override length, format,
3627
3796
  * and language, and deliberately nothing else: a style preference never
@@ -3924,6 +4093,29 @@ export interface ObserveInput {
3924
4093
  * shorten. A provider that never throws this behaves exactly as it did.
3925
4094
  */
3926
4095
  export declare class ContextOverflowError extends Error {
4096
+ /** Recognized across copies of core: a provider package carries its own. */
4097
+ static [Symbol.hasInstance](value: unknown): boolean;
4098
+ constructor(message: string);
4099
+ }
4100
+ /**
4101
+ * A turn the host stopped on purpose (a spent token budget) rather than
4102
+ * one that broke.
4103
+ *
4104
+ * A kernel type because layers that know nothing of budgets have to treat
4105
+ * it differently from every other failure. A fallback provider must not
4106
+ * answer instead: the limit applies to the agent, not to one model, and a
4107
+ * silent switch would spend what the limit exists to stop while hiding
4108
+ * that it was reached. And a channel must not frame it as something going
4109
+ * wrong: the message is a sentence written for the person reading it,
4110
+ * naming what ran out and what changes it, and `session.failed` says so
4111
+ * with `refused`.
4112
+ *
4113
+ * Thrown by a `ProviderCallGuard`, or subclassed by whoever refuses; the
4114
+ * kernel only ever asks `instanceof`.
4115
+ */
4116
+ export declare class HostRefusalError extends Error {
4117
+ /** Recognized across copies of core: a plugin package refuses with its own. */
4118
+ static [Symbol.hasInstance](value: unknown): boolean;
3927
4119
  constructor(message: string);
3928
4120
  }
3929
4121
  /**
@@ -3984,10 +4176,33 @@ export declare const raiseContextFloor: (session: Session) => boolean;
3984
4176
  * Thrown when a run is stopped by its abort signal. The session ends up
3985
4177
  * `failed` with this error's message as `lastError`, so an aborted turn is
3986
4178
  * distinguishable from a genuine failure.
4179
+ *
4180
+ * Except a keyed turn aborted with `resumable`: see `RunAbortedError.resumable`.
3987
4181
  */
3988
4182
  export declare class RunAbortedError extends Error {
3989
- constructor(message?: string);
4183
+ /** Recognized across copies of core: a channel package aborts with its own. */
4184
+ static [Symbol.hasInstance](value: unknown): boolean;
4185
+ /**
4186
+ * The aborter is going away and the turn can be picked up after it: a
4187
+ * host's planned stop or restart. A turn whose message carries an
4188
+ * idempotency key is then not failed but left `running`, as a crash
4189
+ * leaves it, for the next start to continue once (`continueTurn`); the
4190
+ * abort still ends everything it was running. Not for a turn already
4191
+ * continued once (`Message.continuedAfterCrash`) or one that could have
4192
+ * reached a harness (`Message.hostedLoop`), which are failed, and never
4193
+ * for an unkeyed turn, whose caller was promised nothing and is told now.
4194
+ */
4195
+ readonly resumable: boolean;
4196
+ constructor(message?: string, options?: {
4197
+ resumable?: boolean;
4198
+ });
3990
4199
  }
4200
+ /**
4201
+ * Whether an abort leaves this session's turn for the next start rather
4202
+ * than failing it; see `RunAbortedError.resumable`. Exported for the host,
4203
+ * which tells the turn's caller the same thing the runner decided.
4204
+ */
4205
+ export declare const leftForNextStart: (session: Pick<Session, "messages">, error: unknown) => boolean;
3991
4206
  /**
3992
4207
  * The abort that stopped a run, as the runner records it.
3993
4208
  *
@@ -4065,6 +4280,13 @@ export interface AgentRunnerOptions {
4065
4280
  * runs, tests) keep the simpler non-streaming provider path.
4066
4281
  */
4067
4282
  streaming?: boolean;
4283
+ /**
4284
+ * Asked, in order, before every provider call; see `ProviderCallGuard`.
4285
+ * Read on each call, so a host may add to the list after constructing
4286
+ * the runner. A host that omits it puts no limit on model calls beyond
4287
+ * `maxTurns`.
4288
+ */
4289
+ providerCallGuards?: readonly ProviderCallGuard[];
4068
4290
  }
4069
4291
  export declare const inputProblem: (schema: JsonObject | undefined, input: JsonValue, where?: string, depth?: number) => string | undefined;
4070
4292
  export declare const DEFAULT_MAX_TURNS = 40;
@@ -4178,6 +4400,18 @@ export declare class AgentRunner {
4178
4400
  * retried call to be counted once, twice, or not at all.
4179
4401
  */
4180
4402
  private recordUsage;
4403
+ /**
4404
+ * Emit `session.usage` for the records added to the session since
4405
+ * `recordedBefore`.
4406
+ *
4407
+ * The loop drains these before the next provider call, which is the
4408
+ * point: a host that meters spend from this event has seen every earlier
4409
+ * call's tokens before a guard is asked to allow another one. Copies, so
4410
+ * a subscriber cannot edit the session's accounting through the event.
4411
+ */
4412
+ private announceUsage;
4413
+ /** Ask every guard about the call about to be made; the first refusal throws. */
4414
+ private guardProviderCall;
4181
4415
  /**
4182
4416
  * The allowlist entries this session's agent is held to, or undefined for
4183
4417
  * no limit. Entries, not a name set: `fs.*` is an entry, and matching is
@@ -4265,4 +4499,6 @@ export declare class AgentRunner {
4265
4499
  private checkpointPendingApproval;
4266
4500
  private executeToolCall;
4267
4501
  }
4502
+ export { createDirectExecutor, defineExecutor, DirectExecutor, failureResult, normalizeExecutorError, successResult, type DirectExecutorErrorContext, type DirectExecutorOptions, type ExecutorDefinition, type ExecutorResultCallRef, } from './executors.ts';
4503
+ export { admitsSender, channelSessionKey, isPrincipal, senderTrustFor, type AdmitPolicy, type ChannelAdapter, type ChannelCredentialRequest, type ChannelSessionKeyParts, type ConversationBookmark, type ConversationCreateRequest, type ConversationCreateResult, type ConversationMessage, type ConversationReadRequest, type ConversationReadResult, type GatewayLike, type InboundMessage, type OutboundAddress, type OutboundConnection, type OutboundMessageRef, type SenderPolicy, type SessionRouting, } from './channels.ts';
4268
4504
  //# sourceMappingURL=index.d.ts.map