@swifty.js/swifty 0.0.31 → 0.0.33
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/README.md +110 -3
- package/dist/acp-5WRTN2LL.js +14 -0
- package/dist/agent-3CAPJCPD.js +4 -0
- package/dist/anthropic-FXRRA63E.js +4 -0
- package/dist/{bwrap-TPE6G4BM.js → bwrap-ZTS67W2K.js} +1 -1
- package/dist/checker-3O7QF7XV.js +4 -0
- package/dist/chunk-2U4IWZ6E.js +4 -0
- package/dist/chunk-35X3GW25.js +4 -0
- package/dist/chunk-4C3KJLJV.js +4 -0
- package/dist/chunk-4HSQBZBI.js +4 -0
- package/dist/{chunk-AGJYBJ5M.js → chunk-4PQYUHSN.js} +1 -1
- package/dist/chunk-6I3HEMIE.js +4 -0
- package/dist/{chunk-C3WGLVVZ.js → chunk-7JQHFZRD.js} +2 -2
- package/dist/chunk-C5WLP3DH.js +5 -0
- package/dist/chunk-FUKVR3XO.js +608 -0
- package/dist/chunk-FZORZF22.js +16 -0
- package/dist/chunk-G2TE2QZM.js +4 -0
- package/dist/chunk-I7XJSLRI.js +4 -0
- package/dist/{chunk-OQCEP2F5.js → chunk-IKQTIDRL.js} +1 -1
- package/dist/chunk-IZ7QOBSB.js +4 -0
- package/dist/chunk-LC7ZWLIH.js +4 -0
- package/dist/chunk-LHSUYZO5.js +4 -0
- package/dist/chunk-M4D66APS.js +67 -0
- package/dist/chunk-NAAAN2TD.js +60 -0
- package/dist/chunk-NCZR3AGA.js +65 -0
- package/dist/{server-BNT2IIKB.js → chunk-PXQD6GWP.js} +15 -22
- package/dist/{chunk-FPQ2LBL4.js → chunk-QQVDL4QT.js} +1 -1
- package/dist/{chunk-TCQ4EB4G.js → chunk-TNF3EHFY.js} +1 -1
- package/dist/chunk-XGUH7SGV.js +4 -0
- package/dist/chunk-YIKI3EPG.js +150 -0
- package/dist/chunk-YKWIZE5D.js +4 -0
- package/dist/{devtools-OJ75EP3T.js → devtools-WJM4UVVT.js} +1 -1
- package/dist/esm-46WSO26W.js +4 -0
- package/dist/esm-4DBD7ONK.js +229 -0
- package/dist/esm-6EDGM6QS.js +4 -0
- package/dist/esm-D6BB3FBR.js +4 -0
- package/dist/esm-P2KEXEEK.js +4 -0
- package/dist/esm-XYKZYVLV.js +4 -0
- package/dist/esm-YJVVI2QX.js +4 -0
- package/dist/getMachineId-bsd-NBOQ3GRQ.js +4 -0
- package/dist/getMachineId-darwin-6VBNSUFR.js +5 -0
- package/dist/getMachineId-linux-RQ33NIOO.js +4 -0
- package/dist/getMachineId-unsupported-IWOYPUHZ.js +4 -0
- package/dist/getMachineId-win-ITT3WXP6.js +4 -0
- package/dist/lib/agent-NNYCUIOF.js +10 -0
- package/dist/lib/{anthropic-R6DMXE7U.js → anthropic-B33M2AVN.js} +4 -4
- package/dist/lib/{checker-M7RKMKJQ.js → checker-UPY4CXUL.js} +3 -3
- package/dist/lib/{chunk-OQIQOU5S.js → chunk-3OFLDUAW.js} +121 -1
- package/dist/lib/{chunk-EY7HE52Q.js → chunk-3XCGUKGJ.js} +18 -24
- package/dist/lib/{chunk-J6AV7SIF.js → chunk-AFYPVA5C.js} +261 -25
- package/dist/lib/{chunk-FZ4Y6MBN.js → chunk-BCBD34D2.js} +1 -1
- package/dist/lib/{chunk-A4MXZA5Q.js → chunk-CFYAZWDA.js} +10 -4
- package/dist/lib/{chunk-4MDCRPVV.js → chunk-FODSMOWP.js} +6 -6
- package/dist/lib/chunk-GTHYQZRL.js +31 -0
- package/dist/lib/{chunk-EWE5IWZE.js → chunk-LDWFI6MR.js} +15 -4
- package/dist/lib/{chunk-OEPCNATU.js → chunk-TJLAJGG4.js} +2 -2
- package/dist/lib/index.d.ts +2339 -1581
- package/dist/lib/index.js +12210 -10961
- package/dist/lib/{openai-5N42ZYIJ.js → openai-C2PZFGJ2.js} +3 -3
- package/dist/lib/providers-UJEWP7C7.js +419 -0
- package/dist/lib/{tool-filter-XG2GXFVN.js → tool-filter-BFEINZIA.js} +1 -1
- package/dist/main.js +190 -183
- package/dist/{node-4LTSRXL2.js → node-A6KBFKOV.js} +1 -1
- package/dist/{openai-NQYARTT6.js → openai-WPEICAZ4.js} +1 -1
- package/dist/providers-WNYZUMZ3.js +6 -0
- package/dist/seatbelt-PSPJ5LBR.js +5 -0
- package/dist/server-YPBLBRDN.js +4 -0
- package/dist/src-3A5BCUSZ.js +4 -0
- package/dist/src-CRYFVH7Y.js +12 -0
- package/dist/src-Y77IB66J.js +4 -0
- package/dist/src-ZCW4GCG2.js +4 -0
- package/dist/{tool-filter-5NDJMSTD.js → tool-filter-X6IYME2K.js} +1 -1
- package/dist/turndown.es-WNOSVZF6.js +83 -0
- package/package.json +38 -15
- package/dist/agent-O6C4FCQY.js +0 -4
- package/dist/anthropic-CFM2DXMB.js +0 -4
- package/dist/checker-A6PGACKZ.js +0 -4
- package/dist/chunk-4ABFUBO4.js +0 -601
- package/dist/chunk-AQ3A5CF4.js +0 -5
- package/dist/chunk-MVVSONAE.js +0 -4
- package/dist/chunk-OTVZGPHD.js +0 -121
- package/dist/chunk-X3UA5OZL.js +0 -4
- package/dist/chunk-Y2UUXOQA.js +0 -4
- package/dist/chunk-YAXZ2OUD.js +0 -150
- package/dist/lib/agent-YRTROHXU.js +0 -10
- package/dist/seatbelt-YXUQ5XR3.js +0 -5
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import {
|
|
2
2
|
normalizeToolResultContentBlock
|
|
3
3
|
} from "./chunk-XT67KGWE.js";
|
|
4
|
+
import {
|
|
5
|
+
McpCallTool
|
|
6
|
+
} from "./chunk-BCBD34D2.js";
|
|
4
7
|
import {
|
|
5
8
|
ContextTooLongError,
|
|
6
9
|
DEFAULT_CONTEXT_WINDOW,
|
|
7
10
|
DEFAULT_MAX_OUTPUT_TOKENS,
|
|
8
11
|
REJECTED_TOOL_RESULT,
|
|
9
12
|
RateLimitError
|
|
10
|
-
} from "./chunk-
|
|
11
|
-
import {
|
|
12
|
-
McpCallTool
|
|
13
|
-
} from "./chunk-FZ4Y6MBN.js";
|
|
13
|
+
} from "./chunk-3OFLDUAW.js";
|
|
14
14
|
import {
|
|
15
15
|
asErrorString,
|
|
16
16
|
asRecord,
|
|
@@ -18,7 +18,211 @@ import {
|
|
|
18
18
|
createChildLogger,
|
|
19
19
|
isObject,
|
|
20
20
|
strArg
|
|
21
|
-
} from "./chunk-
|
|
21
|
+
} from "./chunk-3XCGUKGJ.js";
|
|
22
|
+
|
|
23
|
+
// src/telemetry/instrumentation.ts
|
|
24
|
+
import { createHash } from "crypto";
|
|
25
|
+
|
|
26
|
+
// src/telemetry/index.ts
|
|
27
|
+
var noopObservation = {
|
|
28
|
+
end: () => void 0,
|
|
29
|
+
recordException: () => void 0,
|
|
30
|
+
startChild: () => noopObservation,
|
|
31
|
+
update: () => void 0
|
|
32
|
+
};
|
|
33
|
+
var noopRuntime = {
|
|
34
|
+
captureError: () => void 0,
|
|
35
|
+
emitLog: () => void 0,
|
|
36
|
+
flush: () => Promise.resolve(),
|
|
37
|
+
recordMetric: () => void 0,
|
|
38
|
+
setMode: () => void 0,
|
|
39
|
+
shutdown: () => Promise.resolve(),
|
|
40
|
+
startObservation: () => noopObservation
|
|
41
|
+
};
|
|
42
|
+
var runtime = noopRuntime;
|
|
43
|
+
var initialization = null;
|
|
44
|
+
var shutdown = null;
|
|
45
|
+
function getTelemetryRuntime() {
|
|
46
|
+
return runtime;
|
|
47
|
+
}
|
|
48
|
+
function captureTelemetryError(error, context) {
|
|
49
|
+
runtime.captureError(error, context);
|
|
50
|
+
}
|
|
51
|
+
async function shutdownTelemetry() {
|
|
52
|
+
if (shutdown) {
|
|
53
|
+
return shutdown;
|
|
54
|
+
}
|
|
55
|
+
shutdown = (async () => {
|
|
56
|
+
await initialization;
|
|
57
|
+
await runtime.shutdown();
|
|
58
|
+
runtime = noopRuntime;
|
|
59
|
+
})();
|
|
60
|
+
return shutdown;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// src/telemetry/instrumentation.ts
|
|
64
|
+
var llmMetadata = /* @__PURE__ */ new WeakMap();
|
|
65
|
+
function elapsedMilliseconds(startedAt) {
|
|
66
|
+
return performance.now() - startedAt;
|
|
67
|
+
}
|
|
68
|
+
function sessionHash(sessionId) {
|
|
69
|
+
if (!sessionId) {
|
|
70
|
+
return void 0;
|
|
71
|
+
}
|
|
72
|
+
return createHash("sha256").update(sessionId).digest("hex").slice(0, 16);
|
|
73
|
+
}
|
|
74
|
+
function metadataFor(client) {
|
|
75
|
+
return llmMetadata.get(client) ?? {
|
|
76
|
+
model: "unknown",
|
|
77
|
+
protocol: client.protocol ?? "unknown"
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
function recordUsage(usage, attributes) {
|
|
81
|
+
const runtime2 = getTelemetryRuntime();
|
|
82
|
+
const values = {
|
|
83
|
+
cache_creation: usage.cacheCreationInputTokens,
|
|
84
|
+
cache_read: usage.cacheReadInputTokens,
|
|
85
|
+
input: usage.inputTokens,
|
|
86
|
+
output: usage.outputTokens
|
|
87
|
+
};
|
|
88
|
+
for (const [tokenType, value] of Object.entries(values)) {
|
|
89
|
+
if (value > 0) {
|
|
90
|
+
runtime2.recordMetric("swifty.llm.tokens", "counter", value, {
|
|
91
|
+
...attributes,
|
|
92
|
+
"token.type": tokenType
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
function registerLlmClient(client, metadata) {
|
|
98
|
+
llmMetadata.set(client, metadata);
|
|
99
|
+
return client;
|
|
100
|
+
}
|
|
101
|
+
function startAgentTelemetry(sessionId, client) {
|
|
102
|
+
const runtime2 = getTelemetryRuntime();
|
|
103
|
+
const metadata = metadataFor(client);
|
|
104
|
+
const hashedSessionId = sessionHash(sessionId);
|
|
105
|
+
const attributes = {
|
|
106
|
+
protocol: metadata.protocol,
|
|
107
|
+
...hashedSessionId ? { "session.hash": hashedSessionId } : {}
|
|
108
|
+
};
|
|
109
|
+
runtime2.recordMetric("swifty.agent.runs", "counter", 1, {
|
|
110
|
+
protocol: metadata.protocol
|
|
111
|
+
});
|
|
112
|
+
return {
|
|
113
|
+
observation: runtime2.startObservation("agent", "swifty.agent.run", attributes),
|
|
114
|
+
protocol: metadata.protocol,
|
|
115
|
+
startedAt: performance.now()
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
function endAgentTelemetry(telemetry, outcome) {
|
|
119
|
+
const runtime2 = getTelemetryRuntime();
|
|
120
|
+
telemetry.observation.update({ metadata: { outcome } });
|
|
121
|
+
telemetry.observation.end();
|
|
122
|
+
runtime2.recordMetric(
|
|
123
|
+
"swifty.agent.duration",
|
|
124
|
+
"histogram",
|
|
125
|
+
elapsedMilliseconds(telemetry.startedAt),
|
|
126
|
+
{ outcome, protocol: telemetry.protocol }
|
|
127
|
+
);
|
|
128
|
+
}
|
|
129
|
+
async function* observeLlmStream(client, stream, parent) {
|
|
130
|
+
const runtime2 = getTelemetryRuntime();
|
|
131
|
+
const metadata = metadataFor(client);
|
|
132
|
+
const attributes = {
|
|
133
|
+
model: metadata.model,
|
|
134
|
+
protocol: metadata.protocol
|
|
135
|
+
};
|
|
136
|
+
const observation = parent.observation.startChild(
|
|
137
|
+
"generation",
|
|
138
|
+
"swifty.llm.generate",
|
|
139
|
+
attributes
|
|
140
|
+
);
|
|
141
|
+
const startedAt = performance.now();
|
|
142
|
+
let completionStartTime;
|
|
143
|
+
let outcome = "incomplete";
|
|
144
|
+
runtime2.recordMetric("swifty.llm.requests", "counter", 1, attributes);
|
|
145
|
+
try {
|
|
146
|
+
for await (const event of stream) {
|
|
147
|
+
if (!completionStartTime && event.type !== "stream_end") {
|
|
148
|
+
completionStartTime = /* @__PURE__ */ new Date();
|
|
149
|
+
runtime2.recordMetric(
|
|
150
|
+
"swifty.llm.time_to_first_token",
|
|
151
|
+
"histogram",
|
|
152
|
+
elapsedMilliseconds(startedAt),
|
|
153
|
+
attributes
|
|
154
|
+
);
|
|
155
|
+
}
|
|
156
|
+
if (event.type === "stream_end") {
|
|
157
|
+
outcome = "completed";
|
|
158
|
+
const usageDetails = {
|
|
159
|
+
cacheCreationInput: event.usage.cacheCreationInputTokens,
|
|
160
|
+
cacheReadInput: event.usage.cacheReadInputTokens,
|
|
161
|
+
input: event.usage.inputTokens,
|
|
162
|
+
output: event.usage.outputTokens
|
|
163
|
+
};
|
|
164
|
+
observation.update({
|
|
165
|
+
completionStartTime,
|
|
166
|
+
metadata: {
|
|
167
|
+
outcome,
|
|
168
|
+
protocol: metadata.protocol,
|
|
169
|
+
stopReason: event.stopReason
|
|
170
|
+
},
|
|
171
|
+
model: metadata.model,
|
|
172
|
+
usageDetails
|
|
173
|
+
});
|
|
174
|
+
recordUsage(event.usage, attributes);
|
|
175
|
+
}
|
|
176
|
+
yield event;
|
|
177
|
+
}
|
|
178
|
+
} catch (error) {
|
|
179
|
+
outcome = "error";
|
|
180
|
+
observation.recordException(error);
|
|
181
|
+
observation.update({ metadata: { outcome, protocol: metadata.protocol } });
|
|
182
|
+
runtime2.emitLog("swifty.llm.error", "error", {
|
|
183
|
+
"error.type": error instanceof Error ? error.name : typeof error,
|
|
184
|
+
...attributes
|
|
185
|
+
});
|
|
186
|
+
throw error;
|
|
187
|
+
} finally {
|
|
188
|
+
observation.end();
|
|
189
|
+
runtime2.recordMetric("swifty.llm.duration", "histogram", elapsedMilliseconds(startedAt), {
|
|
190
|
+
...attributes,
|
|
191
|
+
outcome
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
async function observeToolExecution(toolName, operation, parent) {
|
|
196
|
+
const runtime2 = getTelemetryRuntime();
|
|
197
|
+
const attributes = { tool: toolName };
|
|
198
|
+
const observation = parent.observation.startChild("tool", "swifty.tool.execute", attributes);
|
|
199
|
+
const startedAt = performance.now();
|
|
200
|
+
let outcome = "error";
|
|
201
|
+
runtime2.recordMetric("swifty.tool.calls", "counter", 1, attributes);
|
|
202
|
+
try {
|
|
203
|
+
const result = await operation();
|
|
204
|
+
outcome = result.isError ? "error" : "completed";
|
|
205
|
+
observation.update({
|
|
206
|
+
level: result.isError ? "ERROR" : "DEFAULT",
|
|
207
|
+
metadata: { outcome, tool: toolName },
|
|
208
|
+
...result.isError ? { statusMessage: "Tool returned an error" } : {}
|
|
209
|
+
});
|
|
210
|
+
return result;
|
|
211
|
+
} catch (error) {
|
|
212
|
+
observation.recordException(error);
|
|
213
|
+
runtime2.emitLog("swifty.tool.error", "error", {
|
|
214
|
+
"error.type": error instanceof Error ? error.name : typeof error,
|
|
215
|
+
tool: toolName
|
|
216
|
+
});
|
|
217
|
+
throw error;
|
|
218
|
+
} finally {
|
|
219
|
+
observation.end();
|
|
220
|
+
runtime2.recordMetric("swifty.tool.duration", "histogram", elapsedMilliseconds(startedAt), {
|
|
221
|
+
outcome,
|
|
222
|
+
tool: toolName
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
}
|
|
22
226
|
|
|
23
227
|
// src/agent/streaming-executor.ts
|
|
24
228
|
var log = createChildLogger({ module: "agent" });
|
|
@@ -26,9 +230,11 @@ var StreamingExecutor = class {
|
|
|
26
230
|
pending = [];
|
|
27
231
|
registry;
|
|
28
232
|
ctx;
|
|
29
|
-
|
|
233
|
+
telemetry;
|
|
234
|
+
constructor(registry, ctx, telemetry) {
|
|
30
235
|
this.registry = registry;
|
|
31
236
|
this.ctx = ctx;
|
|
237
|
+
this.telemetry = telemetry;
|
|
32
238
|
}
|
|
33
239
|
submit(toolId, toolName, args) {
|
|
34
240
|
this.pending.push({ toolId, toolName, arguments: args });
|
|
@@ -59,7 +265,11 @@ var StreamingExecutor = class {
|
|
|
59
265
|
};
|
|
60
266
|
}
|
|
61
267
|
try {
|
|
62
|
-
const result = await
|
|
268
|
+
const result = await observeToolExecution(
|
|
269
|
+
call.toolName,
|
|
270
|
+
() => tool.execute({ ...this.ctx, toolCallId: call.toolId }, call.arguments),
|
|
271
|
+
this.telemetry
|
|
272
|
+
);
|
|
63
273
|
return {
|
|
64
274
|
toolId: call.toolId,
|
|
65
275
|
toolName: call.toolName,
|
|
@@ -443,7 +653,7 @@ function recordsToCamelUses(recs) {
|
|
|
443
653
|
return recs?.map((tu) => ({
|
|
444
654
|
toolUseId: tu.tool_use_id,
|
|
445
655
|
toolName: tu.tool_name,
|
|
446
|
-
arguments: tu.arguments,
|
|
656
|
+
arguments: tu.arguments ?? {},
|
|
447
657
|
providerItemId: tu.provider_item_id
|
|
448
658
|
}));
|
|
449
659
|
}
|
|
@@ -1264,7 +1474,7 @@ Direct bounded research, implementation, and verification; synthesize evidence a
|
|
|
1264
1474
|
|
|
1265
1475
|
## Delegation
|
|
1266
1476
|
- Give each worker a purpose, self-contained context, paths, scope, edit permissions, expected output, and checks. Synthesize findings before assigning follow-up work.
|
|
1267
|
-
- One-shot Agent calls return
|
|
1477
|
+
- One-shot Agent calls return inline by default. With run_in_background=true they return a task ID immediately and report completion through a task notification.
|
|
1268
1478
|
- Persistent async workers use TeamCreate plus Agent's team_name. In this restricted mode TeamCreate is unavailable; Agent with team_name can create the team on demand. Without team_name, expect a one-shot result.
|
|
1269
1479
|
- Parallelize independent tasks. Assign one writer per shared file set and sequence dependent changes. Worktrees isolate changes but require explicit integration.
|
|
1270
1480
|
- Delegate Git operations only within user authorization. Never require unsolicited commits or pushes; preserve unrelated work and respect permission/hook denials.
|
|
@@ -1276,7 +1486,7 @@ After launching persistent work, give a brief user update and wait for notificat
|
|
|
1276
1486
|
|
|
1277
1487
|
## Verification
|
|
1278
1488
|
Require observed evidence: changed paths, checks run, results, and blockers. Implementation workers should run relevant tests; use independent review when warranted, not as a mandatory extra phase. Exercise actual behavior, investigate failures, and distinguish verified outcomes from worker claims. Report what remains unverified.`;
|
|
1279
|
-
var coordinatorSparseReminder = `Coordinator mode: you cannot read files, run commands, or edit code. Tools: Agent, SendMessage, TaskStop, SyntheticOutput, TeamDelete.
|
|
1489
|
+
var coordinatorSparseReminder = `Coordinator mode: you cannot read files, run commands, or edit code. Tools: Agent, SendMessage, TaskStop, SyntheticOutput, TeamDelete. Foreground Agent calls return inline; background Agent calls return a task ID and report via task-notification; persistent team workers report via team-notification (from= name). Do not poll workers through agents, predict results, overlap shared-file writes, or request unsolicited commits/pushes. Synthesize and verify evidence before reporting.`;
|
|
1280
1490
|
var REMINDER_INTERVAL = 5;
|
|
1281
1491
|
function coordinatorReminder(iteration = 1) {
|
|
1282
1492
|
if (iteration <= 1 || (iteration - 1) % REMINDER_INTERVAL === 0) {
|
|
@@ -1529,6 +1739,7 @@ ${body}`)
|
|
|
1529
1739
|
this.conversation.injectLongTermMemory(this.instructions, this.memoryContent, skills);
|
|
1530
1740
|
}
|
|
1531
1741
|
async *run() {
|
|
1742
|
+
const telemetry = startAgentTelemetry(this.sessionId, this.client);
|
|
1532
1743
|
this.restoreContext();
|
|
1533
1744
|
const toolSchemas = this.registry.getAllSchemas(
|
|
1534
1745
|
this.client.protocol ?? "anthropic",
|
|
@@ -1625,7 +1836,11 @@ ${body}`)
|
|
|
1625
1836
|
return;
|
|
1626
1837
|
}
|
|
1627
1838
|
try {
|
|
1628
|
-
const stream =
|
|
1839
|
+
const stream = observeLlmStream(
|
|
1840
|
+
this.client,
|
|
1841
|
+
this.client.stream(this.conversation, toolSchemas, this.abortSignal),
|
|
1842
|
+
telemetry
|
|
1843
|
+
);
|
|
1629
1844
|
for await (const event of stream) {
|
|
1630
1845
|
if (this.abortSignal?.aborted) {
|
|
1631
1846
|
looping = false;
|
|
@@ -1803,7 +2018,7 @@ ${body}`)
|
|
|
1803
2018
|
);
|
|
1804
2019
|
}
|
|
1805
2020
|
if (toolUses.length > 0) {
|
|
1806
|
-
const results = await this.executeTools(toolUses);
|
|
2021
|
+
const results = await this.executeTools(toolUses, telemetry);
|
|
1807
2022
|
for (const r of results) {
|
|
1808
2023
|
yield r;
|
|
1809
2024
|
}
|
|
@@ -1887,7 +2102,11 @@ ${body}`)
|
|
|
1887
2102
|
}
|
|
1888
2103
|
}
|
|
1889
2104
|
} finally {
|
|
1890
|
-
|
|
2105
|
+
try {
|
|
2106
|
+
await this.fireLifecycle("session_end");
|
|
2107
|
+
} finally {
|
|
2108
|
+
endAgentTelemetry(telemetry, this.abortSignal?.aborted ? "interrupted" : "completed");
|
|
2109
|
+
}
|
|
1891
2110
|
}
|
|
1892
2111
|
}
|
|
1893
2112
|
// Fire a lifecycle hook event and queue any non-empty hook output as a
|
|
@@ -1926,13 +2145,14 @@ ${body}`)
|
|
|
1926
2145
|
this.abortSignal?.addEventListener("abort", onAbort, { once: true });
|
|
1927
2146
|
});
|
|
1928
2147
|
}
|
|
1929
|
-
async executeTools(toolUses) {
|
|
2148
|
+
async executeTools(toolUses, telemetry) {
|
|
1930
2149
|
const events = [];
|
|
1931
2150
|
const batches = this.partitionToolCalls(toolUses);
|
|
1932
2151
|
for (const batch of batches) {
|
|
1933
2152
|
const batchEvents = await this.executeBatch(
|
|
1934
2153
|
batch.blocks,
|
|
1935
|
-
batch.concurrent && batch.blocks.length > 1
|
|
2154
|
+
batch.concurrent && batch.blocks.length > 1,
|
|
2155
|
+
telemetry
|
|
1936
2156
|
);
|
|
1937
2157
|
events.push(...batchEvents);
|
|
1938
2158
|
}
|
|
@@ -1954,16 +2174,20 @@ ${body}`)
|
|
|
1954
2174
|
// executeBatch runs a set of tool calls through permission checks, hooks,
|
|
1955
2175
|
// and the streaming executor. When parallel is true all calls run
|
|
1956
2176
|
// concurrently; otherwise they run one at a time.
|
|
1957
|
-
async executeBatch(toolUses, parallel) {
|
|
2177
|
+
async executeBatch(toolUses, parallel, telemetry) {
|
|
1958
2178
|
const events = [];
|
|
1959
|
-
const executor = new StreamingExecutor(
|
|
1960
|
-
|
|
1961
|
-
|
|
1962
|
-
|
|
1963
|
-
|
|
1964
|
-
|
|
1965
|
-
|
|
1966
|
-
|
|
2179
|
+
const executor = new StreamingExecutor(
|
|
2180
|
+
this.registry,
|
|
2181
|
+
{
|
|
2182
|
+
workDir: this.workDir,
|
|
2183
|
+
abortSignal: this.abortSignal,
|
|
2184
|
+
fileHistory: this.fileHistory,
|
|
2185
|
+
fileStateCache: this.fileStateCache,
|
|
2186
|
+
permissionChecker: this.checker,
|
|
2187
|
+
onPermissionRequest: this.onPermissionRequest
|
|
2188
|
+
},
|
|
2189
|
+
telemetry
|
|
2190
|
+
);
|
|
1967
2191
|
for (const tu of toolUses) {
|
|
1968
2192
|
if (this.abortSignal?.aborted) {
|
|
1969
2193
|
events.push({
|
|
@@ -2050,7 +2274,12 @@ ${body}`)
|
|
|
2050
2274
|
if (decision.effect === "ask" && this.onPermissionRequest) {
|
|
2051
2275
|
let response;
|
|
2052
2276
|
try {
|
|
2053
|
-
response = await this.onPermissionRequest(
|
|
2277
|
+
response = await this.onPermissionRequest(
|
|
2278
|
+
tu.toolName,
|
|
2279
|
+
tu.arguments,
|
|
2280
|
+
decision,
|
|
2281
|
+
tu.toolUseId
|
|
2282
|
+
);
|
|
2054
2283
|
if (response === "allowAlways" && !this.abortSignal?.aborted) {
|
|
2055
2284
|
this.checker.allowAlways(tu.toolName, tu.arguments);
|
|
2056
2285
|
}
|
|
@@ -2174,7 +2403,14 @@ function parseRetryAfter(header) {
|
|
|
2174
2403
|
}
|
|
2175
2404
|
|
|
2176
2405
|
export {
|
|
2406
|
+
captureTelemetryError,
|
|
2407
|
+
shutdownTelemetry,
|
|
2408
|
+
registerLlmClient,
|
|
2177
2409
|
StreamingExecutor,
|
|
2410
|
+
SUMMARY_INSTRUCTIONS,
|
|
2411
|
+
buildSummaryInstructions,
|
|
2412
|
+
buildSummaryPrompt,
|
|
2413
|
+
buildCompactionSummaryMessage,
|
|
2178
2414
|
ConversationManager,
|
|
2179
2415
|
COMPACT_BOUNDARY,
|
|
2180
2416
|
toolUsesToRecords,
|
|
@@ -1,21 +1,22 @@
|
|
|
1
1
|
import {
|
|
2
2
|
mcpCallPermissionContent
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-BCBD34D2.js";
|
|
4
4
|
import {
|
|
5
5
|
createChildLogger,
|
|
6
6
|
isRecord,
|
|
7
7
|
strArg
|
|
8
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-3XCGUKGJ.js";
|
|
9
9
|
|
|
10
10
|
// src/permissions/checker.ts
|
|
11
11
|
import { readFileSync, writeFileSync, mkdirSync, statSync } from "fs";
|
|
12
|
-
import { homedir, tmpdir } from "os";
|
|
12
|
+
import { homedir as homedir2, tmpdir } from "os";
|
|
13
13
|
import { join as join2, resolve as resolve2, dirname as dirname2 } from "path";
|
|
14
14
|
import yaml from "js-yaml";
|
|
15
15
|
import z, { parse } from "zod";
|
|
16
16
|
|
|
17
17
|
// src/utils/paths.ts
|
|
18
18
|
import { realpathSync } from "fs";
|
|
19
|
+
import { homedir } from "os";
|
|
19
20
|
import { basename, dirname, isAbsolute, join, relative, resolve, sep } from "path";
|
|
20
21
|
function canonicalPath(path) {
|
|
21
22
|
let current = resolve(path);
|
|
@@ -40,6 +41,10 @@ function isPathWithin(root, path) {
|
|
|
40
41
|
const child = relative(root, path);
|
|
41
42
|
return child === "" || child !== ".." && !child.startsWith(`..${sep}`) && !isAbsolute(child);
|
|
42
43
|
}
|
|
44
|
+
function compactPath(path) {
|
|
45
|
+
const home = homedir();
|
|
46
|
+
return path === home ? "~" : path.startsWith(`${home}/`) ? `~/${path.slice(home.length + 1)}` : path;
|
|
47
|
+
}
|
|
43
48
|
|
|
44
49
|
// src/permissions/checker.ts
|
|
45
50
|
var log = createChildLogger({ module: "permissions" });
|
|
@@ -373,7 +378,7 @@ var RuleEngine = class {
|
|
|
373
378
|
projectPath;
|
|
374
379
|
cache = /* @__PURE__ */ new Map();
|
|
375
380
|
constructor(workDir) {
|
|
376
|
-
this.userPath = join2(
|
|
381
|
+
this.userPath = join2(homedir2(), ".swifty", "permissions.yaml");
|
|
377
382
|
this.projectPath = join2(workDir, ".swifty", "permissions.yaml");
|
|
378
383
|
}
|
|
379
384
|
// Read a single rules file; skips disk I/O and parsing on cache hit.
|
|
@@ -621,6 +626,7 @@ var PermissionChecker = class _PermissionChecker {
|
|
|
621
626
|
export {
|
|
622
627
|
canonicalPath,
|
|
623
628
|
isPathWithin,
|
|
629
|
+
compactPath,
|
|
624
630
|
extractContent,
|
|
625
631
|
PathSandbox,
|
|
626
632
|
evaluateRules,
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
2
|
normalizeToolResultContentBlock
|
|
3
3
|
} from "./chunk-XT67KGWE.js";
|
|
4
|
+
import {
|
|
5
|
+
MCP_TOOL_PREFIX,
|
|
6
|
+
isMcpToolLike
|
|
7
|
+
} from "./chunk-BCBD34D2.js";
|
|
4
8
|
import {
|
|
5
9
|
AuthenticationError,
|
|
6
10
|
ContextTooLongError,
|
|
@@ -17,11 +21,7 @@ import {
|
|
|
17
21
|
thinkingBudgetForLevel,
|
|
18
22
|
toAnthropicThinkingEffort,
|
|
19
23
|
toReasoningEffort
|
|
20
|
-
} from "./chunk-
|
|
21
|
-
import {
|
|
22
|
-
MCP_TOOL_PREFIX,
|
|
23
|
-
isMcpToolLike
|
|
24
|
-
} from "./chunk-FZ4Y6MBN.js";
|
|
24
|
+
} from "./chunk-3OFLDUAW.js";
|
|
25
25
|
import {
|
|
26
26
|
asErrorString,
|
|
27
27
|
asRecord,
|
|
@@ -30,7 +30,7 @@ import {
|
|
|
30
30
|
createChildLogger,
|
|
31
31
|
isRecord,
|
|
32
32
|
strArg
|
|
33
|
-
} from "./chunk-
|
|
33
|
+
} from "./chunk-3XCGUKGJ.js";
|
|
34
34
|
|
|
35
35
|
// src/llm/anthropic.ts
|
|
36
36
|
import Anthropic from "@anthropic-ai/sdk";
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// src/version.ts
|
|
2
|
+
import { readFileSync } from "fs";
|
|
3
|
+
import path from "path";
|
|
4
|
+
import { fileURLToPath } from "url";
|
|
5
|
+
import { z } from "zod";
|
|
6
|
+
var PackageJsonSchema = z.object({
|
|
7
|
+
version: z.string()
|
|
8
|
+
});
|
|
9
|
+
function resolveVersion() {
|
|
10
|
+
if (true) {
|
|
11
|
+
return "0.0.33";
|
|
12
|
+
}
|
|
13
|
+
const here = path.dirname(fileURLToPath(import.meta.url));
|
|
14
|
+
for (const levels of ["..", "../.."]) {
|
|
15
|
+
const candidate = path.resolve(here, levels, "package.json");
|
|
16
|
+
try {
|
|
17
|
+
const raw = JSON.parse(readFileSync(candidate, "utf-8"));
|
|
18
|
+
const parsed = PackageJsonSchema.safeParse(raw);
|
|
19
|
+
if (parsed.success) {
|
|
20
|
+
return parsed.data.version;
|
|
21
|
+
}
|
|
22
|
+
} catch {
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
throw new Error("Could not resolve package version");
|
|
26
|
+
}
|
|
27
|
+
var version = resolveVersion();
|
|
28
|
+
|
|
29
|
+
export {
|
|
30
|
+
version
|
|
31
|
+
};
|
|
@@ -21,6 +21,15 @@ var ToolRegistry = class {
|
|
|
21
21
|
register(tool) {
|
|
22
22
|
this.tools.set(tool.name, tool);
|
|
23
23
|
}
|
|
24
|
+
/**
|
|
25
|
+
* Removes a tool and forgets its discovery state, so a re-registered tool
|
|
26
|
+
* with the same name starts deferred again. Used by /mcp reload to drop
|
|
27
|
+
* tools of servers that disappeared from the config.
|
|
28
|
+
*/
|
|
29
|
+
unregister(name) {
|
|
30
|
+
this.tools.delete(name);
|
|
31
|
+
this.discovered.delete(name);
|
|
32
|
+
}
|
|
24
33
|
get(name) {
|
|
25
34
|
return this.tools.get(name);
|
|
26
35
|
}
|
|
@@ -124,13 +133,15 @@ var ToolRegistry = class {
|
|
|
124
133
|
};
|
|
125
134
|
|
|
126
135
|
// src/subagent/tool-filter.ts
|
|
127
|
-
var MAIN_AGENT_ONLY_TOOLS = /* @__PURE__ */ new Set([
|
|
136
|
+
var MAIN_AGENT_ONLY_TOOLS = /* @__PURE__ */ new Set([
|
|
137
|
+
"ComputerUse",
|
|
138
|
+
"AskUserQuestion",
|
|
139
|
+
"ExitPlanMode"
|
|
140
|
+
]);
|
|
128
141
|
var SUBAGENT_DISALLOWED_TOOLS = /* @__PURE__ */ new Set([
|
|
129
|
-
|
|
142
|
+
...MAIN_AGENT_ONLY_TOOLS,
|
|
130
143
|
"Agent",
|
|
131
144
|
// Prevents recursive spawning of subagents
|
|
132
|
-
"AskUserQuestion",
|
|
133
|
-
...MAIN_AGENT_ONLY_TOOLS,
|
|
134
145
|
"TaskStop"
|
|
135
146
|
]);
|
|
136
147
|
var TEAMMATE_DISALLOWED_TOOLS = /* @__PURE__ */ new Set(["TeamCreate", "TeamDelete"]);
|
|
@@ -11,7 +11,7 @@ import {
|
|
|
11
11
|
getThinkingLevel,
|
|
12
12
|
resolveAPIKey,
|
|
13
13
|
toReasoningEffort
|
|
14
|
-
} from "./chunk-
|
|
14
|
+
} from "./chunk-3OFLDUAW.js";
|
|
15
15
|
import {
|
|
16
16
|
asRecord,
|
|
17
17
|
asString,
|
|
@@ -19,7 +19,7 @@ import {
|
|
|
19
19
|
createChildLogger,
|
|
20
20
|
isRecord,
|
|
21
21
|
strArg
|
|
22
|
-
} from "./chunk-
|
|
22
|
+
} from "./chunk-3XCGUKGJ.js";
|
|
23
23
|
|
|
24
24
|
// src/llm/openai.ts
|
|
25
25
|
import OpenAI from "openai";
|