@wrongstack/core 0.309.0 → 0.310.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/chronicle/index.js +113 -41
- package/dist/chronicle/metrics-ingest.d.ts +7 -0
- package/dist/chronicle/metrics-schema.d.ts +4 -1
- package/dist/chronicle/project-server.js +94 -38
- package/dist/chronicle/query.d.ts +1 -0
- package/dist/chronicle/sqlite-journal-schema.d.ts +2 -1
- package/dist/chronicle/types.d.ts +2 -0
- package/dist/{agent-status-helpers.d.ts → coordination/agent-status-helpers.d.ts} +1 -1
- package/dist/{agent-status-tracker.d.ts → coordination/agent-status-tracker.d.ts} +2 -2
- package/dist/{middleware → coordination}/collab-pause.d.ts +1 -1
- package/dist/coordination/director-kanban-queue-helpers.d.ts +1 -1
- package/dist/coordination/director.d.ts +7 -0
- package/dist/coordination/explore-companion.d.ts +9 -6
- package/dist/coordination/fleet-status-tool.d.ts +1 -1
- package/dist/coordination/index.d.ts +5 -1
- package/dist/coordination/index.js +2392 -405
- package/dist/coordination/kanban-dispatch-port.d.ts +30 -0
- package/dist/coordination/kanban-ops-port.d.ts +21 -0
- package/dist/coordination/mailbox-hooks.d.ts +1 -1
- package/dist/coordination/mailbox-project-server.js +14 -9
- package/dist/coordination/mutation-engine.d.ts +5 -3
- package/dist/core/context.d.ts +35 -44
- package/dist/core/conversation-state.d.ts +16 -52
- package/dist/core/index.js +92 -25
- package/dist/core/provider-runner.d.ts +2 -2
- package/dist/core/run-env.d.ts +7 -28
- package/dist/core/streaming-response-builder.d.ts +2 -2
- package/dist/execution/index.js +138 -162
- package/dist/goal/index.js +100 -22
- package/dist/hq/auth-store.d.ts +9 -0
- package/dist/hq/cost-bridge.d.ts +1 -1
- package/dist/hq/index.js +69 -7
- package/dist/index.d.ts +12 -5
- package/dist/index.js +21185 -26807
- package/dist/infrastructure/index.js +232 -135
- package/dist/infrastructure/provider-cache-ledger.d.ts +1 -1
- package/dist/infrastructure/token-counter.d.ts +5 -1
- package/dist/kernel/events/file-events.d.ts +6 -0
- package/dist/kernel/events/provider-events.d.ts +10 -7
- package/dist/kernel/events/session-events.d.ts +4 -4
- package/dist/kernel/events/tool-events.d.ts +12 -2
- package/dist/observability/index.js +1 -1
- package/dist/plugin/index.js +218 -47
- package/dist/prompts/index.js +360 -3
- package/dist/security/auto-approve-policy.d.ts +2 -2
- package/dist/security/index.d.ts +1 -0
- package/dist/security/index.js +224 -68
- package/dist/security/kanban-boundary.d.ts +1 -1
- package/dist/security/kanban-governance-port.d.ts +28 -0
- package/dist/security/permission-helpers.d.ts +11 -0
- package/dist/security/permission-policy.d.ts +10 -1
- package/dist/security/yolo-risk.d.ts +17 -0
- package/dist/session-catalog/index.js +34 -5
- package/dist/session-catalog/project-server.js +34 -5
- package/dist/session-catalog/protocol.d.ts +1 -1
- package/dist/session-catalog/registry.d.ts +1 -1
- package/dist/session-catalog/store-schema.d.ts +1 -1
- package/dist/session-catalog/store.d.ts +1 -1
- package/dist/skills/index.js +39 -6
- package/dist/storage/annotations-store.d.ts +1 -1
- package/dist/storage/board-store-port.d.ts +45 -0
- package/dist/storage/completed-work-checkpoint.d.ts +1 -1
- package/dist/storage/config-loader/types.d.ts +1 -1
- package/dist/storage/event-bus-port.d.ts +27 -0
- package/dist/storage/file-session-writer.d.ts +47 -5
- package/dist/storage/goal-coordination.d.ts +1 -1
- package/dist/storage/goal-store.d.ts +1 -1
- package/dist/storage/index.d.ts +3 -4
- package/dist/storage/index.js +1107 -1462
- package/dist/storage/plan-store.d.ts +1 -1
- package/dist/storage/queue-store.d.ts +1 -1
- package/dist/storage/replay-log-store.d.ts +1 -1
- package/dist/storage/session-recovery.d.ts +10 -0
- package/dist/storage/session-resume-validation.d.ts +13 -1
- package/dist/storage/session-store/events.d.ts +1 -1
- package/dist/storage/session-store/load-session-data.d.ts +1 -1
- package/dist/storage/session-store/rename-session.d.ts +1 -1
- package/dist/storage/session-store/resume-session.d.ts +3 -1
- package/dist/storage/session-store/session-store-index.d.ts +2 -1
- package/dist/storage/session-store/types.d.ts +1 -1
- package/dist/storage/session-store.d.ts +70 -0
- package/dist/storage/session-summary-tracker.d.ts +8 -0
- package/dist/storage/session-write-buffer.d.ts +31 -2
- package/dist/storage/task-store.d.ts +1 -1
- package/dist/storage/todos-checkpoint.d.ts +1 -1
- package/dist/storage/tool-audit-log.d.ts +1 -1
- package/dist/tasking/index.js +100 -22
- package/dist/tasking/task-tracker.d.ts +24 -1
- package/dist/types/compactor.d.ts +2 -2
- package/dist/types/context.d.ts +212 -0
- package/dist/types/conversation-state.d.ts +109 -0
- package/dist/types/error-handler.d.ts +2 -2
- package/dist/types/file-event-record.d.ts +6 -0
- package/dist/types/index.d.ts +3 -3
- package/dist/types/index.js +17 -1
- package/dist/types/permission.d.ts +3 -3
- package/dist/types/plugin.d.ts +3 -3
- package/dist/types/provider-runner.d.ts +2 -2
- package/dist/types/provider.d.ts +10 -0
- package/dist/types/run-env.d.ts +32 -0
- package/dist/types/session.d.ts +3 -0
- package/dist/types/slash-command.d.ts +2 -2
- package/dist/types/token-counter.d.ts +30 -1
- package/dist/types/tool-executor.d.ts +2 -2
- package/dist/types/tool.d.ts +20 -5
- package/dist/utils/context-breakdown.d.ts +2 -2
- package/dist/utils/context-evidence.d.ts +12 -12
- package/dist/utils/crash-shield.d.ts +9 -0
- package/dist/utils/heap-watchdog.js +11 -3
- package/dist/utils/index.d.ts +2 -1
- package/dist/utils/index.js +126 -160
- package/dist/utils/regex-guard.d.ts +7 -30
- package/dist/utils/terminal-sanitize.d.ts +41 -0
- package/dist/utils/todos-format.d.ts +1 -1
- package/dist/utils/tool-subject.d.ts +1 -1
- package/dist/utils/tree-kill.d.ts +2 -0
- package/dist/utils/tree-kill.js +1 -0
- package/instructions/agents/chaos-monkey.md +5 -1
- package/instructions/coordination/subagent-baseline.md +10 -0
- package/instructions/system-lite.md +2 -0
- package/instructions/system-pro.md +40 -0
- package/instructions/system.md +15 -0
- package/package.json +7 -10
- package/dist/defaults/index.d.ts +0 -69
- package/dist/defaults/index.js +0 -37755
- /package/dist/{fleet-notifier.d.ts → coordination/fleet-notifier.d.ts} +0 -0
- /package/dist/{session-registry-atomic-file.d.ts → session-catalog/session-registry-atomic-file.d.ts} +0 -0
- /package/dist/{session-registry-types.d.ts → session-catalog/session-registry-types.d.ts} +0 -0
- /package/dist/{session-registry.d.ts → session-catalog/session-registry.d.ts} +0 -0
package/dist/core/index.js
CHANGED
|
@@ -1751,6 +1751,14 @@ var PATTERNS = [
|
|
|
1751
1751
|
anchor: "sk-ant-"
|
|
1752
1752
|
},
|
|
1753
1753
|
{ type: "openai_key", regex: /(?<![A-Za-z0-9])sk-(?:proj-)?[A-Za-z0-9_-]{20,}(?![A-Za-z0-9])/g, anchor: "sk-" },
|
|
1754
|
+
{
|
|
1755
|
+
// `xai` is a first-class provider in this codebase, but its key shape was
|
|
1756
|
+
// absent here — so the one credential format WrongStack itself hands users
|
|
1757
|
+
// was the one the scrubber could not recognize (audit 2026-08-20).
|
|
1758
|
+
type: "xai_key",
|
|
1759
|
+
regex: /(?<![A-Za-z0-9])xai-[A-Za-z0-9]{20,}(?![A-Za-z0-9])/g,
|
|
1760
|
+
anchor: "xai-"
|
|
1761
|
+
},
|
|
1754
1762
|
{ type: "github_pat", regex: /(?<![A-Za-z0-9])ghp_[A-Za-z0-9]{36,}(?![A-Za-z0-9])/g, anchor: "ghp_" },
|
|
1755
1763
|
{ type: "github_pat_v2", regex: /(?<![A-Za-z0-9])github_pat_[A-Za-z0-9_]{50,}(?![A-Za-z0-9])/g, anchor: "github_pat_" },
|
|
1756
1764
|
{ type: "aws_access_key", regex: /(?<![A-Za-z0-9])AKIA[0-9A-Z]{16}(?![A-Za-z0-9])/g, anchor: "AKIA" },
|
|
@@ -1841,8 +1849,8 @@ var PATTERNS = [
|
|
|
1841
1849
|
// replacement so the separator between adjacent secrets is preserved
|
|
1842
1850
|
// rather than collapsed. Capture groups are therefore: 1=leading
|
|
1843
1851
|
// delimiter, 2=key name, 3=value.
|
|
1844
|
-
regex: /(^|\s)([A-Z_]{4,}(?:KEY|TOKEN|SECRET|PASSWORD|PWD))\s*[:=]\s*['"]?([A-Za-z0-9_/+=-]{20,512})['"]?(?=\s|$)/g,
|
|
1845
|
-
anchor: ["KEY", "TOKEN", "SECRET", "PASSWORD", "PWD"]
|
|
1852
|
+
regex: /(^|\s)([A-Z_]{4,}(?:KEY|TOKEN|SECRET|PASSWORD|PWD|PASSPHRASE))\s*[:=]\s*['"]?([A-Za-z0-9_/+=-]{20,512})['"]?(?=\s|$)/g,
|
|
1853
|
+
anchor: ["KEY", "TOKEN", "SECRET", "PASSWORD", "PWD", "PASSPHRASE"]
|
|
1846
1854
|
},
|
|
1847
1855
|
{
|
|
1848
1856
|
type: "json_credential_key",
|
|
@@ -1959,6 +1967,27 @@ var JSON_CREDENTIAL_REGEX = PATTERNS.find((p) => p.type === "json_credential_key
|
|
|
1959
1967
|
var COMBINED_REPLACEMENTS = SIMPLE_PATTERNS.map((p) => `[REDACTED:${p.type}]`);
|
|
1960
1968
|
var SCRUB_CHUNK_BYTES = 64 * 1024;
|
|
1961
1969
|
var SCRUB_OVERLAP_BYTES = 1024;
|
|
1970
|
+
var PEM_PRIVATE_KEY_BEGIN_RE = /-----BEGIN (?:RSA|EC|OPENSSH|DSA|PGP)? ?PRIVATE KEY-----/;
|
|
1971
|
+
var PEM_END_MARKER = "-----END";
|
|
1972
|
+
var MAX_PEM_BLOCK_BYTES = 64 * 1024;
|
|
1973
|
+
var PEM_END_LINE_TOLERANCE = 64;
|
|
1974
|
+
function extendChunkBoundaryPastPem(text, chunkStart, proposedEnd) {
|
|
1975
|
+
const head = text.slice(chunkStart, proposedEnd);
|
|
1976
|
+
const lastBegin = head.lastIndexOf("-----BEGIN ");
|
|
1977
|
+
if (lastBegin === -1) return proposedEnd;
|
|
1978
|
+
const fromBegin = text.slice(chunkStart + lastBegin);
|
|
1979
|
+
const marker = PEM_PRIVATE_KEY_BEGIN_RE.exec(fromBegin);
|
|
1980
|
+
if (!marker || marker.index !== 0) return proposedEnd;
|
|
1981
|
+
const bodyStart = marker[0].length;
|
|
1982
|
+
const cap = Math.min(text.length, chunkStart + lastBegin + MAX_PEM_BLOCK_BYTES);
|
|
1983
|
+
const closeIdx = fromBegin.indexOf(PEM_END_MARKER, bodyStart);
|
|
1984
|
+
if (closeIdx === -1 || chunkStart + lastBegin + closeIdx >= cap + PEM_END_LINE_TOLERANCE) {
|
|
1985
|
+
return proposedEnd;
|
|
1986
|
+
}
|
|
1987
|
+
const lineEnd = fromBegin.indexOf("\n", closeIdx);
|
|
1988
|
+
const end = lineEnd === -1 ? text.length : chunkStart + lastBegin + lineEnd + 1;
|
|
1989
|
+
return Math.max(proposedEnd, end);
|
|
1990
|
+
}
|
|
1962
1991
|
var PATTERN_ANCHORS = [
|
|
1963
1992
|
...new Set(
|
|
1964
1993
|
PATTERNS.flatMap(
|
|
@@ -1995,6 +2024,7 @@ var DefaultSecretScrubber = class {
|
|
|
1995
2024
|
}
|
|
1996
2025
|
}
|
|
1997
2026
|
end = safe === -1 ? end : safe + 1;
|
|
2027
|
+
end = extendChunkBoundaryPastPem(text, i, end);
|
|
1998
2028
|
}
|
|
1999
2029
|
out.push(this.scrubOne(text.slice(i, end)));
|
|
2000
2030
|
i = end;
|
|
@@ -4732,7 +4762,9 @@ function hasToolUseBlock(message) {
|
|
|
4732
4762
|
return message?.role === "assistant" && Array.isArray(message.content) && message.content.some((block) => block.type === "tool_use");
|
|
4733
4763
|
}
|
|
4734
4764
|
var ConversationState = class {
|
|
4765
|
+
/** Owning context; public for structural typing (Roadmap 10A). */
|
|
4735
4766
|
ctx;
|
|
4767
|
+
/** Subscribers; public for structural typing (Roadmap 10A). */
|
|
4736
4768
|
listeners = /* @__PURE__ */ new Set();
|
|
4737
4769
|
_revision = 0;
|
|
4738
4770
|
constructor(ctx) {
|
|
@@ -4787,9 +4819,8 @@ var ConversationState = class {
|
|
|
4787
4819
|
}
|
|
4788
4820
|
/**
|
|
4789
4821
|
* How many of the oldest messages must be dropped to satisfy both retention
|
|
4790
|
-
* caps — count ({@link
|
|
4791
|
-
*
|
|
4792
|
-
* fits, which is the overwhelmingly common case.
|
|
4822
|
+
* caps — count and size (see {@link AgentContext.messageLimits}). Returns 0
|
|
4823
|
+
* when the history already fits, which is the overwhelmingly common case.
|
|
4793
4824
|
*
|
|
4794
4825
|
* The size pass reads the per-message `_estTokens` cache populated at
|
|
4795
4826
|
* mutation time, so it is a sum over numbers rather than a re-walk of
|
|
@@ -4797,9 +4828,7 @@ var ConversationState = class {
|
|
|
4797
4828
|
* cap determines the starting index for the sum but does not gate it.
|
|
4798
4829
|
*/
|
|
4799
4830
|
overflowCount(arr) {
|
|
4800
|
-
const
|
|
4801
|
-
const maxMessages = contextClass.MAX_MESSAGES;
|
|
4802
|
-
const maxMessageTokens = contextClass.MAX_MESSAGE_TOKENS;
|
|
4831
|
+
const { maxMessages, maxMessageTokens } = this.ctx.messageLimits;
|
|
4803
4832
|
let drop = maxMessages > 0 ? Math.max(0, arr.length - maxMessages) : 0;
|
|
4804
4833
|
if (maxMessageTokens <= 0) return this.protocolSafeDropCount(arr, drop);
|
|
4805
4834
|
let total = 0;
|
|
@@ -5073,6 +5102,10 @@ var Context = class _Context {
|
|
|
5073
5102
|
* so storage operations can include it in `storage.*` events.
|
|
5074
5103
|
*/
|
|
5075
5104
|
traceId;
|
|
5105
|
+
/** Logical provider request whose response produced the current tool calls. */
|
|
5106
|
+
activeLogicalRequestId = void 0;
|
|
5107
|
+
/** Content-addressed prompt composition for {@link activeLogicalRequestId}. */
|
|
5108
|
+
activePromptManifestId = void 0;
|
|
5076
5109
|
/**
|
|
5077
5110
|
* Session id pinned to the currently-executing run. Set by `Agent.run()`
|
|
5078
5111
|
* at run start and cleared when the run ends. Event-emission sites must
|
|
@@ -5098,6 +5131,7 @@ var Context = class _Context {
|
|
|
5098
5131
|
return resolveEventSessionId(this);
|
|
5099
5132
|
}
|
|
5100
5133
|
/** Callbacks fired when `setWorkingDir()` changes the working directory. */
|
|
5134
|
+
/** WorkingDir-change callbacks; public for structural typing (Roadmap 10A). */
|
|
5101
5135
|
_onWorkingDirChanged = [];
|
|
5102
5136
|
/**
|
|
5103
5137
|
* Serializes externally requested provider/model changes. Request creation
|
|
@@ -5353,7 +5387,16 @@ var Context = class _Context {
|
|
|
5353
5387
|
* For hooks that must survive across run boundaries (mailbox heartbeat,
|
|
5354
5388
|
* awareness polling, HQ publisher), prefer `registerAgentHook` instead.
|
|
5355
5389
|
*/
|
|
5390
|
+
/** Run-scoped abort hooks (drained by drainAbortHooks). Public for structural typing (Roadmap 10A). */
|
|
5356
5391
|
abortHooks = /* @__PURE__ */ new Set();
|
|
5392
|
+
/** Retention limits honoring runtime subclass overrides of the statics. */
|
|
5393
|
+
get messageLimits() {
|
|
5394
|
+
const cls = this.constructor;
|
|
5395
|
+
return Object.freeze({
|
|
5396
|
+
maxMessages: cls.MAX_MESSAGES,
|
|
5397
|
+
maxMessageTokens: cls.MAX_MESSAGE_TOKENS
|
|
5398
|
+
});
|
|
5399
|
+
}
|
|
5357
5400
|
registerAbortHook(fn) {
|
|
5358
5401
|
this.abortHooks.add(fn);
|
|
5359
5402
|
return () => this.abortHooks.delete(fn);
|
|
@@ -5378,6 +5421,7 @@ var Context = class _Context {
|
|
|
5378
5421
|
* awareness polling interval, HQ publisher connection, and auto-compaction
|
|
5379
5422
|
* timer — resources that must survive from the first run to the last.
|
|
5380
5423
|
*/
|
|
5424
|
+
/** Session-lifetime teardown hooks (drained by drainAgentHooks). Public for structural typing (Roadmap 10A). */
|
|
5381
5425
|
agentHooks = /* @__PURE__ */ new Set();
|
|
5382
5426
|
registerAgentHook(fn) {
|
|
5383
5427
|
this.agentHooks.add(fn);
|
|
@@ -5558,6 +5602,9 @@ var Context = class _Context {
|
|
|
5558
5602
|
agentName: this.agentName,
|
|
5559
5603
|
provider: typeof this.provider === "object" ? this.provider.id : String(this.provider),
|
|
5560
5604
|
model: this.model,
|
|
5605
|
+
...this.activeLogicalRequestId ? { logicalRequestId: this.activeLogicalRequestId } : {},
|
|
5606
|
+
...this.activePromptManifestId ? { promptManifestId: this.activePromptManifestId } : {},
|
|
5607
|
+
provenanceConfidence: this.activeLogicalRequestId && this.activePromptManifestId ? "explicit" : "unknown",
|
|
5561
5608
|
toolName: input.toolName,
|
|
5562
5609
|
toolUseId: input.toolUseId,
|
|
5563
5610
|
scope,
|
|
@@ -5585,6 +5632,9 @@ var Context = class _Context {
|
|
|
5585
5632
|
agentName: this.agentName,
|
|
5586
5633
|
provider: record.provider,
|
|
5587
5634
|
model: record.model,
|
|
5635
|
+
...record.logicalRequestId ? { logicalRequestId: record.logicalRequestId } : {},
|
|
5636
|
+
...record.promptManifestId ? { promptManifestId: record.promptManifestId } : {},
|
|
5637
|
+
provenanceConfidence: record.provenanceConfidence,
|
|
5588
5638
|
toolName: input.toolName,
|
|
5589
5639
|
toolUseId: input.toolUseId,
|
|
5590
5640
|
scope,
|
|
@@ -6240,6 +6290,7 @@ function maybeAppendPendingNextSteps(ctx, res) {
|
|
|
6240
6290
|
// src/prompts/prompt-journal.ts
|
|
6241
6291
|
import * as fs5 from "node:fs/promises";
|
|
6242
6292
|
import * as path11 from "node:path";
|
|
6293
|
+
var defaultScrubber2 = new DefaultSecretScrubber();
|
|
6243
6294
|
async function ensureGitignore(projectRoot) {
|
|
6244
6295
|
const gitignorePath = path11.join(projectRoot, ".gitignore");
|
|
6245
6296
|
try {
|
|
@@ -6267,7 +6318,9 @@ async function recordPromptJournalEntry(opts) {
|
|
|
6267
6318
|
const monthStr = dateStr.slice(0, 7);
|
|
6268
6319
|
const sessionId = opts.sessionId && opts.sessionId.trim() ? opts.sessionId.trim() : "general";
|
|
6269
6320
|
const id = `pmt_${Date.now()}_${Math.random().toString(36).slice(2, 9)}`;
|
|
6270
|
-
const content = opts.content ?? "";
|
|
6321
|
+
const content = defaultScrubber2.scrub(opts.content ?? "");
|
|
6322
|
+
const rawContent = typeof opts.rawContent === "string" && opts.rawContent.length > 0 ? defaultScrubber2.scrub(opts.rawContent) : opts.rawContent;
|
|
6323
|
+
const decisionReason = typeof opts.decisionReason === "string" && opts.decisionReason.length > 0 ? defaultScrubber2.scrub(opts.decisionReason) : opts.decisionReason;
|
|
6271
6324
|
const lines = content.split("\n");
|
|
6272
6325
|
const characterCount = content.length;
|
|
6273
6326
|
const lineCount = lines.length;
|
|
@@ -6280,7 +6333,7 @@ async function recordPromptJournalEntry(opts) {
|
|
|
6280
6333
|
role: opts.role ?? (opts.category === "system_prompt" ? "system" : "user"),
|
|
6281
6334
|
category: opts.category,
|
|
6282
6335
|
content,
|
|
6283
|
-
rawContent
|
|
6336
|
+
rawContent,
|
|
6284
6337
|
metadata: {
|
|
6285
6338
|
model: opts.model,
|
|
6286
6339
|
provider: opts.provider,
|
|
@@ -6291,7 +6344,7 @@ async function recordPromptJournalEntry(opts) {
|
|
|
6291
6344
|
activeTools: opts.activeTools,
|
|
6292
6345
|
contextFiles: opts.contextFiles,
|
|
6293
6346
|
durationMs: opts.durationMs,
|
|
6294
|
-
decisionReason
|
|
6347
|
+
decisionReason,
|
|
6295
6348
|
tags: opts.tags
|
|
6296
6349
|
}
|
|
6297
6350
|
};
|
|
@@ -6739,7 +6792,12 @@ async function streamProviderToResponse(provider, req, signal, ctx, events, logg
|
|
|
6739
6792
|
const idVal = ev.id;
|
|
6740
6793
|
const nameVal = ev.name;
|
|
6741
6794
|
handleToolUseStart(state, { id: idVal, name: nameVal });
|
|
6742
|
-
const emittedPayload = {
|
|
6795
|
+
const emittedPayload = {
|
|
6796
|
+
sessionId,
|
|
6797
|
+
ctx,
|
|
6798
|
+
id: idVal ?? "unknown",
|
|
6799
|
+
name: nameVal ?? "unknown"
|
|
6800
|
+
};
|
|
6743
6801
|
events.emit("provider.tool_use_start", emittedPayload);
|
|
6744
6802
|
break;
|
|
6745
6803
|
}
|
|
@@ -7042,6 +7100,8 @@ async function runProviderWithRetry(opts) {
|
|
|
7042
7100
|
const { provider, request, signal, ctx, events, retry, logger, tracer } = opts;
|
|
7043
7101
|
const logicalRequestId = randomUUID5();
|
|
7044
7102
|
const promptManifest = createChroniclePromptManifest(request);
|
|
7103
|
+
ctx.activeLogicalRequestId = logicalRequestId;
|
|
7104
|
+
ctx.activePromptManifestId = promptManifest.manifestId;
|
|
7045
7105
|
let attempt = 0;
|
|
7046
7106
|
for (; ; ) {
|
|
7047
7107
|
const attemptId = randomUUID5();
|
|
@@ -7052,6 +7112,7 @@ async function runProviderWithRetry(opts) {
|
|
|
7052
7112
|
...ctx.traceId ? { traceId: ctx.traceId } : {},
|
|
7053
7113
|
...ctx.agentId ? { agentId: ctx.agentId } : {},
|
|
7054
7114
|
logicalRequestId,
|
|
7115
|
+
promptManifestId: promptManifest.manifestId,
|
|
7055
7116
|
attemptId,
|
|
7056
7117
|
attempt,
|
|
7057
7118
|
providerId: provider.id,
|
|
@@ -7075,15 +7136,18 @@ async function runProviderWithRetry(opts) {
|
|
|
7075
7136
|
});
|
|
7076
7137
|
logger.debug(`Provider attempt ${attempt + 1} starting`, providerLogCtx(provider, request));
|
|
7077
7138
|
try {
|
|
7078
|
-
const res = await runWithNetworkTelemetry(
|
|
7079
|
-
|
|
7080
|
-
|
|
7081
|
-
|
|
7082
|
-
|
|
7083
|
-
|
|
7084
|
-
|
|
7085
|
-
|
|
7086
|
-
|
|
7139
|
+
const res = await runWithNetworkTelemetry(
|
|
7140
|
+
{
|
|
7141
|
+
events,
|
|
7142
|
+
sessionId: resolveEventSessionId(ctx),
|
|
7143
|
+
...ctx.traceId ? { traceId: ctx.traceId } : {},
|
|
7144
|
+
...ctx.agentId ? { agentId: ctx.agentId } : {},
|
|
7145
|
+
attemptId,
|
|
7146
|
+
initiator: "provider",
|
|
7147
|
+
operationName: `${provider.id}.complete`
|
|
7148
|
+
},
|
|
7149
|
+
() => provider.capabilities.streaming ? streamProviderToResponse(provider, request, signal, ctx, events, logger) : provider.complete(request, { signal })
|
|
7150
|
+
);
|
|
7087
7151
|
span?.setAttribute("provider.stopReason", res.stopReason);
|
|
7088
7152
|
span?.setAttribute("provider.usage_in", res.usage.input);
|
|
7089
7153
|
span?.setAttribute("provider.usage_out", res.usage.output);
|
|
@@ -8824,6 +8888,8 @@ function createAgentToolHandler(a) {
|
|
|
8824
8888
|
a.events.emit("tool.executed", {
|
|
8825
8889
|
sessionId: resolveEventSessionId(a.ctx),
|
|
8826
8890
|
...a.ctx.traceId ? { traceId: a.ctx.traceId } : {},
|
|
8891
|
+
...a.ctx.activeLogicalRequestId ? { logicalRequestId: a.ctx.activeLogicalRequestId } : {},
|
|
8892
|
+
...a.ctx.activePromptManifestId ? { promptManifestId: a.ctx.activePromptManifestId } : {},
|
|
8827
8893
|
agentId: a.ctx.agentId,
|
|
8828
8894
|
agentName: a.ctx.agentName,
|
|
8829
8895
|
id: toolUseId,
|
|
@@ -8891,10 +8957,7 @@ function createAgentToolHandler(a) {
|
|
|
8891
8957
|
} catch {
|
|
8892
8958
|
}
|
|
8893
8959
|
}
|
|
8894
|
-
if (decision === "
|
|
8895
|
-
const p = a.permission;
|
|
8896
|
-
p.allowOnce?.({ tool: tool.name, pattern: result.suggestedPattern });
|
|
8897
|
-
} else if (decision === "no") {
|
|
8960
|
+
if (decision === "no") {
|
|
8898
8961
|
const p = a.permission;
|
|
8899
8962
|
p.denyOnce?.({ tool: tool.name, pattern: result.suggestedPattern });
|
|
8900
8963
|
}
|
|
@@ -9338,6 +9401,8 @@ var Agent = class {
|
|
|
9338
9401
|
const sessionId = sessionWriter.id;
|
|
9339
9402
|
this.ctx.activeRunSessionWriter = sessionWriter;
|
|
9340
9403
|
this.ctx.activeRunSessionId = sessionId;
|
|
9404
|
+
this.ctx.activeLogicalRequestId = void 0;
|
|
9405
|
+
this.ctx.activePromptManifestId = void 0;
|
|
9341
9406
|
controller.onAbort(() => this.ctx.drainAbortHooks());
|
|
9342
9407
|
controller.onAbort(async () => {
|
|
9343
9408
|
await sessionWriter.flush().catch(() => {
|
|
@@ -9441,6 +9506,8 @@ var Agent = class {
|
|
|
9441
9506
|
} finally {
|
|
9442
9507
|
this.ctx.activeRunSessionId = void 0;
|
|
9443
9508
|
this.ctx.activeRunSessionWriter = void 0;
|
|
9509
|
+
this.ctx.activeLogicalRequestId = void 0;
|
|
9510
|
+
this.ctx.activePromptManifestId = void 0;
|
|
9444
9511
|
this._runInProgress = false;
|
|
9445
9512
|
}
|
|
9446
9513
|
}
|
|
@@ -3,12 +3,12 @@ import type { Logger } from '../types/logger.js';
|
|
|
3
3
|
import type { Tracer } from '../types/observability.js';
|
|
4
4
|
import type { Provider, Request, Response } from '../types/provider.js';
|
|
5
5
|
import type { RetryPolicy } from '../types/retry-policy.js';
|
|
6
|
-
import {
|
|
6
|
+
import type { AgentContext } from '../types/context.js';
|
|
7
7
|
export interface RunProviderOptions {
|
|
8
8
|
provider: Provider;
|
|
9
9
|
request: Request;
|
|
10
10
|
signal: AbortSignal;
|
|
11
|
-
ctx:
|
|
11
|
+
ctx: AgentContext;
|
|
12
12
|
events: EventBus;
|
|
13
13
|
retry: RetryPolicy;
|
|
14
14
|
logger: Logger;
|
package/dist/core/run-env.d.ts
CHANGED
|
@@ -1,9 +1,5 @@
|
|
|
1
|
-
import type { TextBlock } from '../types/blocks.js';
|
|
2
|
-
import type { Provider } from '../types/provider.js';
|
|
3
|
-
import type { SessionWriter } from '../types/session.js';
|
|
4
|
-
import type { TokenCounter } from '../types/token-counter.js';
|
|
5
|
-
import type { Tool } from '../types/tool.js';
|
|
6
1
|
import type { Context } from './context.js';
|
|
2
|
+
import type { RunEnv } from '../types/run-env.js';
|
|
7
3
|
/**
|
|
8
4
|
* Immutable run environment — the set-once dependencies for an agent run.
|
|
9
5
|
*
|
|
@@ -18,32 +14,15 @@ import type { Context } from './context.js';
|
|
|
18
14
|
* references. The opposite direction (set things on Context) still works,
|
|
19
15
|
* and `extractRunEnv` rebuilds the view if you need a snapshot.
|
|
20
16
|
*
|
|
17
|
+
* Roadmap 10A: the interface itself now lives in `types/run-env.ts` (a
|
|
18
|
+
* dependency leaf that never imports `core/`), so the type module graph
|
|
19
|
+
* stays acyclic; this module keeps `extractRunEnv` and re-exports the
|
|
20
|
+
* interface for existing import paths.
|
|
21
|
+
*
|
|
21
22
|
* Migration path: new APIs accept `RunEnv` instead of `Context` when they
|
|
22
23
|
* only need read access. Existing APIs continue to accept `Context` until
|
|
23
24
|
* a full split is scheduled.
|
|
24
25
|
*/
|
|
25
|
-
export
|
|
26
|
-
readonly provider: Provider;
|
|
27
|
-
readonly session: SessionWriter;
|
|
28
|
-
readonly signal: AbortSignal;
|
|
29
|
-
readonly tokenCounter: TokenCounter;
|
|
30
|
-
readonly cwd: string;
|
|
31
|
-
readonly projectRoot: string;
|
|
32
|
-
/** Mutable working directory — starts as `cwd`. */
|
|
33
|
-
readonly workingDir: string;
|
|
34
|
-
readonly model: string;
|
|
35
|
-
readonly systemPrompt: readonly TextBlock[];
|
|
36
|
-
readonly tools: readonly Tool[];
|
|
37
|
-
readonly agentId: string;
|
|
38
|
-
readonly agentName: string;
|
|
39
|
-
}
|
|
40
|
-
/**
|
|
41
|
-
* Build a `RunEnv` view from a Context. The returned object is a shallow
|
|
42
|
-
* frozen view — mutations to `Context` are visible (it's the same
|
|
43
|
-
* references), but the view itself can't be mutated.
|
|
44
|
-
*
|
|
45
|
-
* Use this in subsystems that want to declare "I only need read access to
|
|
46
|
-
* the env" without rewriting their signature to accept the full Context.
|
|
47
|
-
*/
|
|
26
|
+
export type { RunEnv } from '../types/run-env.js';
|
|
48
27
|
export declare function extractRunEnv(ctx: Context): RunEnv;
|
|
49
28
|
//# sourceMappingURL=run-env.d.ts.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { EventBus } from '../kernel/events.js';
|
|
2
2
|
import type { Logger } from '../types/logger.js';
|
|
3
3
|
import type { Provider, Request, Response } from '../types/provider.js';
|
|
4
|
-
import {
|
|
4
|
+
import type { AgentContext } from '../types/context.js';
|
|
5
5
|
interface ThinkingEntry {
|
|
6
6
|
textBuf: string;
|
|
7
7
|
signature?: string | undefined;
|
|
@@ -73,6 +73,6 @@ export declare function handleMessageStop(state: StreamingState, ev: {
|
|
|
73
73
|
stopReason?: Response['stopReason'] | undefined;
|
|
74
74
|
usage?: Response['usage'] | undefined;
|
|
75
75
|
}): void;
|
|
76
|
-
export declare function streamProviderToResponse(provider: Provider, req: Request, signal: AbortSignal, ctx:
|
|
76
|
+
export declare function streamProviderToResponse(provider: Provider, req: Request, signal: AbortSignal, ctx: AgentContext, events: EventBus, logger: Logger): Promise<Response>;
|
|
77
77
|
export {};
|
|
78
78
|
//# sourceMappingURL=streaming-response-builder.d.ts.map
|