@akanjs/cli 3.1.0-rc.9 → 3.1.1-rc.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/.build-stamp +1 -1
- package/{CodeAgent-rkjyxgec.js → CodeAgent-4pnxwptq.js} +2 -2
- package/{CodeAgentRpcHost-p7h6n2hp.js → CodeAgentRpcHost-9g27hmer.js} +1 -1
- package/{CodeTui-h7pyj6xa.js → CodeTui-hhndze8h.js} +47 -4
- package/README.ko.md +1 -1
- package/README.md +1 -1
- package/TunnelShare-zmq6bbar.js +14 -0
- package/{agent.command-3qxf4xcj.js → agent.command-p02330r6.js} +5 -5
- package/akanCode.js +7 -5
- package/{application.command-m1kcd7jf.js → application.command-ywks5ywm.js} +35 -9
- package/{applicationBuildRunner-dj0xkrep.js → applicationBuildRunner-9cnnsdm5.js} +23 -8
- package/buildBatch.proc.js +9 -9
- package/{cloud.command-9cp1t0f5.js → cloud.command-1tzkvje1.js} +13 -13
- package/cloud.script-8g83xqdg.js +24 -0
- package/{code.command-0ad6gw2a.js → code.command-16pm1p2v.js} +25 -12
- package/commandManifest.json +1 -1
- package/{context.command-0qx447mb.js → context.command-6ys86sqf.js} +16 -16
- package/context.runner-3jrypwe3.js +25 -0
- package/{guideline.command-cv5bmrx2.js → guideline.command-3zay3d8g.js} +2 -2
- package/guidelines/agentRule/agentRule.instruction.md +25 -10
- package/guidelines/conventions/conventions.instruction.md +71 -24
- package/guidelines/fieldRule/fieldRule.instruction.md +17 -0
- package/guidelines/mcpRule/mcpRule.instruction.md +93 -48
- package/guidelines/modelDocument/modelDocument.instruction.md +2 -1
- package/guidelines/modelStore/modelStore.instruction.md +7 -0
- package/guidelines/pageRule/pageRule.instruction.md +55 -8
- package/guidelines/queryRule/queryRule.instruction.md +24 -10
- package/guidelines/runtimeRule/runtimeRule.instruction.md +12 -4
- package/guidelines/ssrRule/ssrRule.instruction.md +9 -6
- package/guidelines/transportRule/transportRule.instruction.md +36 -5
- package/guidelines/workspaceOnboarding/workspaceOnboarding.instruction.md +5 -3
- package/guidelines/workspaceRecipes/workspaceRecipes.instruction.md +28 -8
- package/incrementalBuilder.proc.js +3 -3
- package/{index-cpb3nvma.js → index-1f33g2z5.js} +2 -2
- package/{index-tamvyvj3.js → index-1mfyyxh5.js} +3 -3
- package/{index-wa5jbxj1.js → index-2mrn1mrg.js} +1 -0
- package/{index-8fp3b47h.js → index-4w3skd33.js} +281 -46
- package/{index-bspm21y1.js → index-68c3gzvg.js} +7 -7
- package/{index-20bxxyvn.js → index-9hbhm6cs.js} +40 -2
- package/{index-d2242ksy.js → index-at7bz0xq.js} +3 -0
- package/{index-fmzcs8v6.js → index-b5vptvnt.js} +4 -4
- package/{index-d72hfmdm.js → index-bb4hj03s.js} +8 -8
- package/{index-9z426msb.js → index-e9e9cebg.js} +78 -27
- package/{index-vk0pa0mn.js → index-ekpp5tax.js} +2 -1
- package/{index-35hc95h5.js → index-fmder14z.js} +1 -1
- package/{index-86jt2a0e.js → index-g2s33373.js} +1 -1
- package/{index-4mhy6qme.js → index-jaa81e9r.js} +4 -4
- package/{index-192ha4xh.js → index-jgs8z8xb.js} +3 -3
- package/{index-qwa5k1j8.js → index-kcbq2qcf.js} +1 -1
- package/{index-w44cy4vs.js → index-ngpn9hzy.js} +6 -4
- package/{index-jw1zm273.js → index-p4dnj2wc.js} +54 -10
- package/index-q8age5az.js +643 -0
- package/{index-j4mkhz93.js → index-qfzfaq96.js} +3 -3
- package/{index-pydbnfez.js → index-qkcwsg6r.js} +35 -9
- package/{index-d47ypebv.js → index-qtkycaqn.js} +75 -19
- package/{index-va06nr10.js → index-rr7jk14m.js} +65 -20
- package/{index-1xj2t7cb.js → index-sh9mmp5v.js} +7 -7
- package/{index-1p98exm2.js → index-sng3vt0p.js} +2 -2
- package/{index-j237xtew.js → index-tk3jg2bm.js} +25 -8
- package/{index-fyq1z6kt.js → index-vg28jsf9.js} +3 -3
- package/{index-trpasv9q.js → index-ynqxpwx6.js} +1 -1
- package/{index-5edzv8fn.js → index-z6v7k9sb.js} +2 -2
- package/{index-g1mbppa9.js → index-z9xepn8t.js} +5 -5
- package/{index-awbdfcf2.js → index-zn6bn1s2.js} +4 -4
- package/index.js +40 -22
- package/{library.command-erp2f56n.js → library.command-a8n9h8j4.js} +3 -3
- package/{localRegistry.command-y176p558.js → localRegistry.command-1e6m7w2f.js} +12 -12
- package/{module.command-gs2r615e.js → module.command-b6f1p1xa.js} +5 -5
- package/{package.command-j10r76ax.js → package.command-tc27ftmy.js} +3 -3
- package/package.json +16 -16
- package/{page.command-4h4a8pnh.js → page.command-m5wyqfkd.js} +3 -3
- package/{pipeline.command-a2nrk26m.js → pipeline.command-4qxyafpz.js} +2 -2
- package/{primitive.command-w6t0asqz.js → primitive.command-9yaatk0d.js} +6 -6
- package/{projectTypecheck-f534enqj.js → projectTypecheck-87k6z6ab.js} +1 -1
- package/{quality.command-77x7vbbx.js → quality.command-ht1wjhv8.js} +2 -2
- package/{repair.command-y6sstev7.js → repair.command-evg9g911.js} +5 -5
- package/{routeSourceValidator-7ycnfz0e.js → routeSourceValidator-6jd0q6r6.js} +47 -14
- package/{scalar.command-20b8cy0k.js → scalar.command-xsejjeq1.js} +4 -4
- package/skills/akan-code/SKILL.md +4 -0
- package/skills/akan-store/SKILL.md +4 -2
- package/{subspace.command-5c7yasd7.js → subspace.command-ps12q5y7.js} +8 -17
- package/templates/migration/__migrationId__.ts +23 -0
- package/templates/server.ts +8 -1
- package/templates/workspaceRoot/biome.json.template +1 -1
- package/{tunnel.command-2kw8vt9g.js → tunnel.command-khzgvrj8.js} +7 -7
- package/{workflow.command-2djwmpqf.js → workflow.command-qpyq0ya5.js} +10 -10
- package/{workspace.command-ms84ykse.js → workspace.command-3dq7e9g2.js} +30 -28
- package/TunnelShare-661cxz5e.js +0 -14
- package/cloud.script-dgstqt1m.js +0 -24
- package/context.runner-1vsjztjg.js +0 -25
- package/index-665zp9rs.js +0 -271
|
@@ -142,7 +142,19 @@ export class TaskService extends serve(db.task, ({ plug }) => ({
|
|
|
142
142
|
}
|
|
143
143
|
```
|
|
144
144
|
|
|
145
|
-
|
|
145
|
+
To reach the file itself (a `Bun.file()` response with ranges, a CLI tool, a size check), ask the role where it
|
|
146
|
+
lives: `this.storage.resolveLocalPath?.(path, access)` (`access` optional) answers the absolute disk path
|
|
147
|
+
`BlobStorage` uses, picking the root as its writes do with `access` and by the `private/` prefix without it. It
|
|
148
|
+
answers `null` for a key that is rooted, holds a NUL, or leaves that root — refuse that key, never fall back to
|
|
149
|
+
`readData()` for it. Fall back only when the adaptor has no `resolveLocalPath` at all (object storage). **A key
|
|
150
|
+
that reaches you from a request passes `access: "public"`**: without it a `private/` key resolves under the private
|
|
151
|
+
root, so a public route would serve private files. Never cast the role to reach `root` / `privateRoot`.
|
|
152
|
+
|
|
153
|
+
For a custom adapter class (not a predefined role), pass the class itself, e.g. `ipfsApi: plug(IpfsApi)`. Two framework
|
|
154
|
+
adapters are plugged that way: `rateLimit: plug(RateLimit)` to count a business key, and
|
|
155
|
+
`endpointCache: plug(EndpointCacheControl)` to drop an endpoint's `{ cache }` answers after the write that made them
|
|
156
|
+
stale: `await this.endpointCache.invalidate("bannerListInPublic")`, plus `"bannerInsightInPublic"` for a slice's
|
|
157
|
+
count.
|
|
146
158
|
Injecting a file/image field is usually simpler than calling
|
|
147
159
|
storage directly: declare `image: field(File).optional()` (or `images: field([File])`) on the model and let the
|
|
148
160
|
store's generated `upload<Field>On<Model>(fileList)` action handle the upload. Add `{ cascade: "removeRef" }` to that
|
|
@@ -286,7 +298,11 @@ async startTask(taskId: string) {
|
|
|
286
298
|
|
|
287
299
|
// 6. <Model>.Util.tsx — Reusable button component
|
|
288
300
|
export const Start = ({ taskId }: { taskId: string }) => (
|
|
289
|
-
<button
|
|
301
|
+
<button
|
|
302
|
+
type="button"
|
|
303
|
+
className={buttonRecipe({ variant: "primary", size: "xs" })}
|
|
304
|
+
onClick={() => st.do.startTask(taskId)}
|
|
305
|
+
>
|
|
290
306
|
Start
|
|
291
307
|
</button>
|
|
292
308
|
);
|
|
@@ -410,9 +426,9 @@ export default page()
|
|
|
410
426
|
.config({ transition: "stack" })
|
|
411
427
|
.head(({ projectId }) => <title>{projectId}</title>)
|
|
412
428
|
.prompt("briefProject", "Brief one project: its status and what is due.")
|
|
413
|
-
.render(
|
|
429
|
+
.render(({ projectId, tab }) => {
|
|
414
430
|
const { l } = usePage();
|
|
415
|
-
const { projectView } =
|
|
431
|
+
const { projectView } = fetch.viewProject(projectId);
|
|
416
432
|
return <Project.Zone.View view={projectView} tab={tab} />;
|
|
417
433
|
});
|
|
418
434
|
```
|
|
@@ -435,7 +451,7 @@ export default page()
|
|
|
435
451
|
|
|
436
452
|
Rules the loader and `akan sync` enforce: a chain module has no other export; `page()` belongs in a page file and
|
|
437
453
|
`layout()` / `rootLayout()` in a `_layout.tsx`; a page names every `[x]` of its path, a layout may name a subset;
|
|
438
|
-
`.param()` and `.
|
|
454
|
+
`.param()`, `.prompt()` and `.app()` names are string literals; `import "./styles.css"` stays the first line of a root layout;
|
|
439
455
|
`_overrides.tsx` is untouched. MCP: `prompts/get` now runs the page's body under the caller's token and hands the
|
|
440
456
|
model the description, what the page fetched, and the tools of those modules — see `mcpRule`.
|
|
441
457
|
|
|
@@ -537,7 +553,7 @@ akan sync automatically generates APIs across all layers. Only write custom logi
|
|
|
537
553
|
| Auto-Generated | Description |
|
|
538
554
|
|---------------|-------------|
|
|
539
555
|
| `this.<model>Model` | Auto-injected model adaptor |
|
|
540
|
-
| `get<Model>(id)`, `load<Model>(id)` | Single document lookup |
|
|
556
|
+
| `get<Model>(id)`, `load<Model>(id)` | Single document lookup: `get` throws `NoDocumentError` for a missing or removed id, answered 404 `base.error.documentNotFound`; `load` returns `null` |
|
|
541
557
|
| `create<Model>(data)`, `update<Model>(id, data)`, `remove<Model>(id)` | CRUD operations — named after the model, e.g. `createTask`/`updateTask`/`removeTask` (there is no literal `createModel`) |
|
|
542
558
|
| `list<Query>(args)`, `find<Query>(args)`, `pick<Query>(args)` | Filter-based queries |
|
|
543
559
|
| `exists<Query>(args)`, `count<Query>(args)`, `insight<Query>(args)` | Filter-based helpers |
|
|
@@ -554,7 +570,10 @@ akan sync automatically generates APIs across all layers. Only write custom logi
|
|
|
554
570
|
| `new[Model](partial)`, `edit[Model](model)`, `view[Model](model)` | Form/view state actions |
|
|
555
571
|
| `[slice]List`, `[slice]InitList`, `[slice]Insight`, `[slice]Selection`, `hasMoreOf[Slice]` | Slice states |
|
|
556
572
|
| `init[Slice](args)`, `refresh[Slice]()`, `setPageOf[Slice](page)`, `loadMoreOf[Slice]()` | Slice actions |
|
|
573
|
+
| `invalidate[Model]()` | Marks every slice stale without a request, so the next `Load.Units` / `Load.View` mount refetches — for a custom mutation whose changed rows the store never received |
|
|
557
574
|
| `set[Field]On[Model](value)` | Auto-setters for each model field |
|
|
575
|
+
| `upload[Field]On[Model](fileList, idx?)` | Upload into a `File` field, scoped to the form that started it |
|
|
576
|
+
| `[model]FormUploading` | Pending uploads per `File` field (`{}` when idle); submits save nothing until empty |
|
|
558
577
|
|
|
559
578
|
**Rule**: Write custom store actions only for toast messages (`msg.loading`/`msg.success`) or multi-step workflows. State fields and CRUD actions are already auto-generated.
|
|
560
579
|
|
|
@@ -568,8 +587,9 @@ akan sync automatically generates APIs across all layers. Only write custom logi
|
|
|
568
587
|
| `exists[Query](args)`, `count[Query](args)` | Existence check and count |
|
|
569
588
|
| `insight[Query](args)`, `query[Query](args)` | Insight and raw query |
|
|
570
589
|
| `remove[Query](args)`, `removeOne[Query](args)` | Query-level soft remove — all matches, or the newest one (`createdAt` desc, not caller-chosen) |
|
|
590
|
+
| `purge[Query](args)` | Hard delete of every match, removed rows too, returning the count — no undo |
|
|
571
591
|
| `update[Query](args).set(patch)`, `updateOne[Query](args).set(patch)` | Query-level update — the patch lands on a terminal `.set()`, because a filter's trailing args may be optional |
|
|
572
592
|
|
|
573
|
-
**Rule**: Define `Filter` with `.query()` conditions in `document.ts`. akan sync auto-generates all
|
|
593
|
+
**Rule**: Define `Filter` with `.query()` conditions in `document.ts`. akan sync auto-generates all 15 query helper methods per filter. Write `Document` chain methods only for state transitions with validation.
|
|
574
594
|
|
|
575
|
-
**The
|
|
595
|
+
**The five query-level writes fire no hooks**, so no `_pre`/`_postRemove` and no cascade run — same as `updateManyByQuery`. Reach for them when the model carries no removal side effect; otherwise remove documents one at a time. A filter keyed after its own model (filter `chat` on model `chat`) is rejected at boot, because `removeChat`/`updateChat` would otherwise shadow the generated single-document CRUD.
|
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
CodegenLock,
|
|
9
9
|
WorkspaceExecutor,
|
|
10
10
|
AppExecutor
|
|
11
|
-
} from "./index-
|
|
11
|
+
} from "./index-rr7jk14m.js";
|
|
12
12
|
import"./index-52w0fvh8.js";
|
|
13
13
|
import {
|
|
14
14
|
GraphClientEntryDiscovery,
|
|
@@ -19,10 +19,10 @@ import {
|
|
|
19
19
|
DevChangePlanner,
|
|
20
20
|
DevGeneratedIndexSync,
|
|
21
21
|
SsrDevBundler
|
|
22
|
-
} from "./index-
|
|
22
|
+
} from "./index-ngpn9hzy.js";
|
|
23
23
|
import {
|
|
24
24
|
ServerGraphFile
|
|
25
|
-
} from "./index-
|
|
25
|
+
} from "./index-jgs8z8xb.js";
|
|
26
26
|
import {
|
|
27
27
|
prepareDevWatchBatch
|
|
28
28
|
} from "./index-a5vmm6x4.js";
|
|
@@ -9,10 +9,10 @@ import {
|
|
|
9
9
|
NativePublicEnv,
|
|
10
10
|
UpdatePackFolder,
|
|
11
11
|
NativeApp
|
|
12
|
-
} from "./index-
|
|
12
|
+
} from "./index-z9xepn8t.js";
|
|
13
13
|
import {
|
|
14
14
|
ExitCodeError
|
|
15
|
-
} from "./index-
|
|
15
|
+
} from "./index-p4dnj2wc.js";
|
|
16
16
|
import {
|
|
17
17
|
ConfigLock
|
|
18
18
|
} from "./index-bqbf654f.js";
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import {
|
|
3
3
|
runner,
|
|
4
4
|
script
|
|
5
|
-
} from "./index-
|
|
5
|
+
} from "./index-p4dnj2wc.js";
|
|
6
6
|
import {
|
|
7
7
|
AGENT_BLOCK_START,
|
|
8
8
|
AGENT_BLOCK_END,
|
|
@@ -13,14 +13,14 @@ import {
|
|
|
13
13
|
CLAUDE_COMMENT_RULE,
|
|
14
14
|
AppExecutor,
|
|
15
15
|
LibExecutor
|
|
16
|
-
} from "./index-
|
|
16
|
+
} from "./index-rr7jk14m.js";
|
|
17
17
|
import {
|
|
18
18
|
collectRecipeSources2,
|
|
19
19
|
scanRecipes2
|
|
20
20
|
} from "./index-hj6w4ka1.js";
|
|
21
21
|
import {
|
|
22
22
|
AkanContextAnalyzer
|
|
23
|
-
} from "./index-
|
|
23
|
+
} from "./index-z6v7k9sb.js";
|
|
24
24
|
import {
|
|
25
25
|
Prompter2
|
|
26
26
|
} from "./index-zzvvc845.js";
|
|
@@ -250,6 +250,7 @@ class CodeTuiCommands2 {
|
|
|
250
250
|
{ name: "effort", desc: "how hard the model thinks before it answers", arg: "<level>" },
|
|
251
251
|
{ name: "thinking", desc: "show the model's reasoning, or fold it away again" },
|
|
252
252
|
{ name: "compact", desc: "summarise the conversation to free the window", arg: "[notes]" },
|
|
253
|
+
{ name: "autocompact", desc: "how full the window gets before it is summarised", arg: "[<percent>]" },
|
|
253
254
|
{ name: "abort", desc: "stop the running turn" },
|
|
254
255
|
{ name: "clear", desc: "wipe the screen; the model keeps the conversation" },
|
|
255
256
|
{ name: "name", desc: "name this session", arg: "<text>" },
|
|
@@ -3,8 +3,9 @@ import {
|
|
|
3
3
|
SubagentPool2,
|
|
4
4
|
akanCodePaths2,
|
|
5
5
|
McpServerConfig,
|
|
6
|
-
McpSignIn
|
|
7
|
-
|
|
6
|
+
McpSignIn,
|
|
7
|
+
AkanCodeCompaction2
|
|
8
|
+
} from "./index-9hbhm6cs.js";
|
|
8
9
|
import {
|
|
9
10
|
stripAnsi
|
|
10
11
|
} from "./index-7md2g9vw.js";
|
|
@@ -254,7 +255,7 @@ class AkanCodeServices2 {
|
|
|
254
255
|
enableInstallTelemetry: false,
|
|
255
256
|
enableAnalytics: false,
|
|
256
257
|
quietStartup: true,
|
|
257
|
-
compaction: { reserveTokens:
|
|
258
|
+
compaction: { reserveTokens: AkanCodeCompaction2.reserveFloor }
|
|
258
259
|
});
|
|
259
260
|
}
|
|
260
261
|
static async runtime(workspaceRoot, proxy = null) {
|
|
@@ -318,7 +319,7 @@ import {
|
|
|
318
319
|
DefaultResourceLoader
|
|
319
320
|
} from "@earendil-works/pi-coding-agent";
|
|
320
321
|
import {
|
|
321
|
-
codeAgentClip as
|
|
322
|
+
codeAgentClip as codeAgentClip6,
|
|
322
323
|
codeAgentLabelChars as codeAgentLabelChars2,
|
|
323
324
|
codeAgentRenderAnswer,
|
|
324
325
|
codeAgentSessionName as codeAgentSessionName2
|
|
@@ -808,7 +809,7 @@ class AkanToolPack2 {
|
|
|
808
809
|
return { name: "akan-tools", factory: async (pi) => await this.#register(pi) };
|
|
809
810
|
}
|
|
810
811
|
async names() {
|
|
811
|
-
const { ContextRunner } = await import("./context.runner-
|
|
812
|
+
const { ContextRunner } = await import("./context.runner-3jrypwe3.js");
|
|
812
813
|
return [
|
|
813
814
|
...new ContextRunner().listMcpTools(this.#options.mode).map((tool) => tool.name),
|
|
814
815
|
AkanToolPack2.verifyToolName
|
|
@@ -816,7 +817,7 @@ class AkanToolPack2 {
|
|
|
816
817
|
}
|
|
817
818
|
static verifyToolName = "akan_verify";
|
|
818
819
|
async#register(pi) {
|
|
819
|
-
const { ContextRunner } = await import("./context.runner-
|
|
820
|
+
const { ContextRunner } = await import("./context.runner-3jrypwe3.js");
|
|
820
821
|
const runner = new ContextRunner;
|
|
821
822
|
const guidelineNames = await AkanToolPack2.#guidelineNames();
|
|
822
823
|
for (const tool of runner.listMcpTools(this.#options.mode, { guidelineNames })) {
|
|
@@ -1395,11 +1396,121 @@ class SessionToolPack2 {
|
|
|
1395
1396
|
}
|
|
1396
1397
|
|
|
1397
1398
|
// pkgs/@akanjs/devkit/codeAgent/tools/WebToolPack.ts
|
|
1398
|
-
import {
|
|
1399
|
+
import { lookup } from "dns/promises";
|
|
1400
|
+
import { isIP } from "net";
|
|
1401
|
+
import { codeAgentClip as codeAgentClip4 } from "akanjs/common";
|
|
1399
1402
|
import { Type as Type6 } from "typebox";
|
|
1400
1403
|
|
|
1404
|
+
// pkgs/@akanjs/devkit/codeAgent/tools/DeepSeekWeb.ts
|
|
1405
|
+
import { codeAgentClip as codeAgentClip3 } from "akanjs/common";
|
|
1406
|
+
|
|
1407
|
+
class DeepSeekWeb {
|
|
1408
|
+
static baseUrl = "https://api.deepseek.com/v1/tools";
|
|
1409
|
+
static maxQueryChars = 128;
|
|
1410
|
+
static summaryChars = 600;
|
|
1411
|
+
static #retryable = {
|
|
1412
|
+
search: [408, 429, 500, 502, 503, 504],
|
|
1413
|
+
fetch: [429]
|
|
1414
|
+
};
|
|
1415
|
+
static #attempts = 3;
|
|
1416
|
+
#key;
|
|
1417
|
+
#baseUrl;
|
|
1418
|
+
constructor(key, baseUrl = DeepSeekWeb.baseUrl) {
|
|
1419
|
+
this.#key = key;
|
|
1420
|
+
this.#baseUrl = baseUrl;
|
|
1421
|
+
}
|
|
1422
|
+
static async fromRuntime(runtime, proxied) {
|
|
1423
|
+
if (proxied)
|
|
1424
|
+
return;
|
|
1425
|
+
const key = (await runtime.getAuth("deepseek").catch(() => {
|
|
1426
|
+
return;
|
|
1427
|
+
}))?.auth.apiKey;
|
|
1428
|
+
return key ? new DeepSeekWeb(key) : undefined;
|
|
1429
|
+
}
|
|
1430
|
+
async search(query, count, signal) {
|
|
1431
|
+
if ([...query].length > DeepSeekWeb.maxQueryChars)
|
|
1432
|
+
throw new Error(`DeepSeek search takes at most ${DeepSeekWeb.maxQueryChars} characters; shorten the query.`);
|
|
1433
|
+
const body = await this.#call("search", { query, count }, 20000, signal);
|
|
1434
|
+
const byUrl = new Map;
|
|
1435
|
+
for (const result of body.results ?? []) {
|
|
1436
|
+
const url = DeepSeekWeb.#cleanUrl(result.url);
|
|
1437
|
+
if (!byUrl.has(url))
|
|
1438
|
+
byUrl.set(url, { ...result, url });
|
|
1439
|
+
}
|
|
1440
|
+
return [...byUrl.values()].map((result) => {
|
|
1441
|
+
const date = result.date ? ` \xB7 ${result.date.slice(0, 10)}` : "";
|
|
1442
|
+
const summary = DeepSeekWeb.unescape(result.summary || result.snippet || "").replace(/\s+/g, " ").trim();
|
|
1443
|
+
return `- ${result.title}
|
|
1444
|
+
${result.url}${date}
|
|
1445
|
+
${codeAgentClip3(summary, DeepSeekWeb.summaryChars)}`;
|
|
1446
|
+
}).join(`
|
|
1447
|
+
`);
|
|
1448
|
+
}
|
|
1449
|
+
async fetch(url, signal) {
|
|
1450
|
+
const page = await this.#call("fetch", { url }, 30000, signal);
|
|
1451
|
+
return { title: page.title ?? "", content: DeepSeekWeb.unescape(page.content ?? "") };
|
|
1452
|
+
}
|
|
1453
|
+
static unescape(markdown) {
|
|
1454
|
+
const escaped = markdown.match(/\\[!-/:-@[-`{-~]/g)?.length ?? 0;
|
|
1455
|
+
const punctuation = markdown.match(/[!-/:-@[-`{-~]/g)?.length ?? 0;
|
|
1456
|
+
if (!escaped || escaped < (punctuation - escaped) / 2)
|
|
1457
|
+
return markdown;
|
|
1458
|
+
return markdown.replace(/\\([!-/:-@[-`{-~])/g, "$1");
|
|
1459
|
+
}
|
|
1460
|
+
async#call(tool, body, timeoutMs, signal) {
|
|
1461
|
+
for (let attempt = 1;; attempt++) {
|
|
1462
|
+
const response = await fetch(`${this.#baseUrl}/${tool}`, {
|
|
1463
|
+
method: "POST",
|
|
1464
|
+
headers: { authorization: `Bearer ${this.#key}`, "content-type": "application/json" },
|
|
1465
|
+
body: JSON.stringify(body),
|
|
1466
|
+
signal: signal ? AbortSignal.any([signal, AbortSignal.timeout(timeoutMs)]) : AbortSignal.timeout(timeoutMs)
|
|
1467
|
+
});
|
|
1468
|
+
if (response.ok)
|
|
1469
|
+
return await response.json();
|
|
1470
|
+
if (!DeepSeekWeb.#retryable[tool].includes(response.status) || attempt >= DeepSeekWeb.#attempts) {
|
|
1471
|
+
const error = await response.json().catch(() => {
|
|
1472
|
+
return;
|
|
1473
|
+
});
|
|
1474
|
+
throw new Error(`DeepSeek ${tool} answered ${response.status}: ${error?.error?.message ?? response.statusText}`);
|
|
1475
|
+
}
|
|
1476
|
+
await DeepSeekWeb.#wait(DeepSeekWeb.#delayOf(response, attempt), signal);
|
|
1477
|
+
}
|
|
1478
|
+
}
|
|
1479
|
+
static #delayOf(response, attempt) {
|
|
1480
|
+
const retryAfter = Number(response.headers.get("retry-after"));
|
|
1481
|
+
return Number.isFinite(retryAfter) && retryAfter > 0 ? Math.min(retryAfter, 5) * 1000 : 1000 * 2 ** (attempt - 1);
|
|
1482
|
+
}
|
|
1483
|
+
static #wait(ms, signal) {
|
|
1484
|
+
return new Promise((resolve) => {
|
|
1485
|
+
const timer = setTimeout(resolve, ms);
|
|
1486
|
+
signal?.addEventListener("abort", () => {
|
|
1487
|
+
clearTimeout(timer);
|
|
1488
|
+
resolve();
|
|
1489
|
+
}, { once: true });
|
|
1490
|
+
});
|
|
1491
|
+
}
|
|
1492
|
+
static #cleanUrl(url) {
|
|
1493
|
+
try {
|
|
1494
|
+
const parsed = new URL(url);
|
|
1495
|
+
for (const name of [...parsed.searchParams.keys()])
|
|
1496
|
+
if (name.startsWith("utm_"))
|
|
1497
|
+
parsed.searchParams.delete(name);
|
|
1498
|
+
if (/^#\d+$/.test(parsed.hash))
|
|
1499
|
+
parsed.hash = "";
|
|
1500
|
+
return parsed.toString();
|
|
1501
|
+
} catch {
|
|
1502
|
+
return url;
|
|
1503
|
+
}
|
|
1504
|
+
}
|
|
1505
|
+
}
|
|
1506
|
+
|
|
1507
|
+
// pkgs/@akanjs/devkit/codeAgent/tools/WebToolPack.ts
|
|
1401
1508
|
class WebToolPack2 {
|
|
1509
|
+
static pageChars = 1e4;
|
|
1510
|
+
static maxResults = 10;
|
|
1511
|
+
static #rememberedPages = 16;
|
|
1402
1512
|
#options;
|
|
1513
|
+
#pages = new Map;
|
|
1403
1514
|
constructor(options) {
|
|
1404
1515
|
this.#options = options;
|
|
1405
1516
|
}
|
|
@@ -1438,7 +1549,7 @@ class WebToolPack2 {
|
|
|
1438
1549
|
const names = [];
|
|
1439
1550
|
if (this.#options.profile.tools.web.fetch)
|
|
1440
1551
|
names.push("web_fetch");
|
|
1441
|
-
if (this.#options.profile.tools.web.search &&
|
|
1552
|
+
if (this.#options.profile.tools.web.search && this.#searcher())
|
|
1442
1553
|
names.push("web_search");
|
|
1443
1554
|
return names;
|
|
1444
1555
|
}
|
|
@@ -1450,58 +1561,146 @@ class WebToolPack2 {
|
|
|
1450
1561
|
#register(pi) {
|
|
1451
1562
|
if (this.#options.profile.tools.web.fetch)
|
|
1452
1563
|
this.#registerFetch(pi);
|
|
1453
|
-
const
|
|
1454
|
-
if (this.#options.profile.tools.web.search &&
|
|
1455
|
-
this.#registerSearch(pi,
|
|
1564
|
+
const searcher = this.#searcher();
|
|
1565
|
+
if (this.#options.profile.tools.web.search && searcher)
|
|
1566
|
+
this.#registerSearch(pi, searcher);
|
|
1456
1567
|
}
|
|
1457
1568
|
#registerFetch(pi) {
|
|
1458
1569
|
const allowHosts = this.#options.profile.network.allowHosts;
|
|
1459
1570
|
pi.registerTool({
|
|
1460
1571
|
name: "web_fetch",
|
|
1461
1572
|
label: "Fetch",
|
|
1462
|
-
description:
|
|
1573
|
+
description: `Fetch a URL and return its readable text, ${WebToolPack2.pageChars} characters at a time. A longer page ends with the offset that continues it.`,
|
|
1463
1574
|
promptSnippet: "web_fetch: fetch a URL and return its readable text",
|
|
1464
|
-
parameters: Type6.Object({
|
|
1465
|
-
|
|
1575
|
+
parameters: Type6.Object({
|
|
1576
|
+
url: Type6.String({ description: "Absolute http(s) URL." }),
|
|
1577
|
+
offset: Type6.Optional(Type6.Number({ description: "Character offset a previous call named, to read on." }))
|
|
1578
|
+
}),
|
|
1579
|
+
execute: async (_id, params, signal) => {
|
|
1466
1580
|
const refusal = WebToolPack2.#refuseHost(params.url, allowHosts);
|
|
1467
1581
|
if (refusal)
|
|
1468
1582
|
return { content: [{ type: "text", text: refusal }], details: undefined, isError: true };
|
|
1469
|
-
const
|
|
1470
|
-
const
|
|
1583
|
+
const offset = Math.max(0, Math.floor(params.offset ?? 0));
|
|
1584
|
+
const cached = offset ? this.#pages.get(params.url) : undefined;
|
|
1585
|
+
const page = cached ?? await this.#read(params.url, signal);
|
|
1586
|
+
if (page.ok)
|
|
1587
|
+
this.#remember(params.url, page);
|
|
1471
1588
|
return {
|
|
1472
|
-
content: [
|
|
1473
|
-
{ type: "text", text: `${response.status} ${params.url}
|
|
1474
|
-
|
|
1475
|
-
${codeAgentClip3(text, codeAgentOutputChars3)}` }
|
|
1476
|
-
],
|
|
1589
|
+
content: [{ type: "text", text: WebToolPack2.#window(params.url, page, offset) }],
|
|
1477
1590
|
details: undefined,
|
|
1478
|
-
isError: !
|
|
1591
|
+
isError: !page.ok
|
|
1479
1592
|
};
|
|
1480
1593
|
}
|
|
1481
1594
|
});
|
|
1482
1595
|
}
|
|
1483
|
-
#registerSearch(pi,
|
|
1596
|
+
#registerSearch(pi, searcher) {
|
|
1597
|
+
const hint = searcher.name === "deepseek" ? ` Keep the query within ${DeepSeekWeb.maxQueryChars} characters; site:, -site: and quoted phrases work.` : "";
|
|
1484
1598
|
pi.registerTool({
|
|
1485
1599
|
name: "web_search",
|
|
1486
1600
|
label: "Search",
|
|
1487
|
-
description: `Search the web (${
|
|
1601
|
+
description: `Search the web (${searcher.name}) and return the top results as title, url and summary.${hint}`,
|
|
1488
1602
|
promptSnippet: "web_search: search the web and return titles, urls and snippets",
|
|
1489
1603
|
parameters: Type6.Object({
|
|
1490
1604
|
query: Type6.String(),
|
|
1491
|
-
count: Type6.Optional(Type6.Number({ description:
|
|
1605
|
+
count: Type6.Optional(Type6.Number({ description: `How many results, default 5, at most ${WebToolPack2.maxResults}.` }))
|
|
1492
1606
|
}),
|
|
1493
|
-
execute: async (_id, params) => {
|
|
1494
|
-
const
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1607
|
+
execute: async (_id, params, signal) => {
|
|
1608
|
+
const count = Math.min(Math.max(Math.round(params.count ?? 5), 1), WebToolPack2.maxResults);
|
|
1609
|
+
try {
|
|
1610
|
+
const results = await searcher.search(params.query, count, signal);
|
|
1611
|
+
return {
|
|
1612
|
+
content: [{ type: "text", text: codeAgentClip4(results || "(no results)", WebToolPack2.pageChars) }],
|
|
1613
|
+
details: undefined
|
|
1614
|
+
};
|
|
1615
|
+
} catch (error) {
|
|
1616
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
1617
|
+
return { content: [{ type: "text", text: message }], details: undefined, isError: true };
|
|
1618
|
+
}
|
|
1500
1619
|
}
|
|
1501
1620
|
});
|
|
1502
1621
|
}
|
|
1503
|
-
|
|
1504
|
-
|
|
1622
|
+
#searcher() {
|
|
1623
|
+
const provider = WebToolPack2.providers.find((entry) => !!process.env[entry.envKey]);
|
|
1624
|
+
if (provider)
|
|
1625
|
+
return {
|
|
1626
|
+
name: provider.name,
|
|
1627
|
+
search: (query, count) => provider.search(process.env[provider.envKey] ?? "", query, count)
|
|
1628
|
+
};
|
|
1629
|
+
const deepseek = this.#options.deepseek;
|
|
1630
|
+
return deepseek ? { name: "deepseek", search: (query, count, signal) => deepseek.search(query, count, signal) } : undefined;
|
|
1631
|
+
}
|
|
1632
|
+
async#read(url, signal) {
|
|
1633
|
+
const deepseek = this.#options.deepseek;
|
|
1634
|
+
if (deepseek && !await this.#isLocal(new URL(url).hostname)) {
|
|
1635
|
+
try {
|
|
1636
|
+
const page = await deepseek.fetch(url, signal);
|
|
1637
|
+
return { status: 200, ok: true, title: page.title, text: page.content };
|
|
1638
|
+
} catch (error) {
|
|
1639
|
+
if (signal?.aborted)
|
|
1640
|
+
throw error;
|
|
1641
|
+
}
|
|
1642
|
+
}
|
|
1643
|
+
const response = await fetch(url, {
|
|
1644
|
+
signal: signal ? AbortSignal.any([signal, AbortSignal.timeout(20000)]) : AbortSignal.timeout(20000),
|
|
1645
|
+
redirect: "follow"
|
|
1646
|
+
});
|
|
1647
|
+
return { status: response.status, ok: response.ok, title: "", text: WebToolPack2.#readable(await response.text()) };
|
|
1648
|
+
}
|
|
1649
|
+
#remember(url, page) {
|
|
1650
|
+
this.#pages.delete(url);
|
|
1651
|
+
this.#pages.set(url, page);
|
|
1652
|
+
const oldest = this.#pages.keys().next().value;
|
|
1653
|
+
if (this.#pages.size > WebToolPack2.#rememberedPages && oldest)
|
|
1654
|
+
this.#pages.delete(oldest);
|
|
1655
|
+
}
|
|
1656
|
+
static #window(url, page, offset) {
|
|
1657
|
+
const head = [`${page.status} ${url}`, page.title].filter(Boolean).join(`
|
|
1658
|
+
`);
|
|
1659
|
+
const total = page.text.length;
|
|
1660
|
+
if (offset && offset >= total)
|
|
1661
|
+
return `${head}
|
|
1662
|
+
|
|
1663
|
+
Offset ${offset} is past the end; the page has ${total} characters.`;
|
|
1664
|
+
const end = Math.min(offset + WebToolPack2.pageChars, total);
|
|
1665
|
+
const rest = end < total ? `
|
|
1666
|
+
|
|
1667
|
+
[characters ${offset}\u2013${end} of ${total}; offset ${end} reads on]` : "";
|
|
1668
|
+
return `${head}
|
|
1669
|
+
|
|
1670
|
+
${page.text.slice(offset, end)}${rest}`;
|
|
1671
|
+
}
|
|
1672
|
+
async#isLocal(hostname) {
|
|
1673
|
+
const host = hostname.replace(/^\[|\]$|\.$/g, "").toLowerCase();
|
|
1674
|
+
if (isIP(host))
|
|
1675
|
+
return WebToolPack2.#isLocalAddress(host);
|
|
1676
|
+
if (!host.includes(".") || /\.(localhost|local|internal|lan|home\.arpa)$/.test(host))
|
|
1677
|
+
return true;
|
|
1678
|
+
try {
|
|
1679
|
+
const addresses = await (this.#options.lookup ?? WebToolPack2.#lookup)(host);
|
|
1680
|
+
return !addresses.length || addresses.some((address) => WebToolPack2.#isLocalAddress(address));
|
|
1681
|
+
} catch {
|
|
1682
|
+
return true;
|
|
1683
|
+
}
|
|
1684
|
+
}
|
|
1685
|
+
static async#lookup(host) {
|
|
1686
|
+
return (await lookup(host, { all: true })).map((entry) => entry.address);
|
|
1687
|
+
}
|
|
1688
|
+
static #isLocalAddress(literal) {
|
|
1689
|
+
const address = WebToolPack2.#unmapped(literal);
|
|
1690
|
+
if (isIP(address) === 6)
|
|
1691
|
+
return address === "::" || address === "::1" || /^(f[cd]|fe[89ab])/.test(address);
|
|
1692
|
+
const [a = 0, b = 0] = address.split(".").map(Number);
|
|
1693
|
+
return a === 0 || a === 10 || a === 127 || a === 100 && b >= 64 && b <= 127 || a === 169 && b === 254 || a === 172 && b >= 16 && b <= 31 || a === 192 && b === 168;
|
|
1694
|
+
}
|
|
1695
|
+
static #unmapped(address) {
|
|
1696
|
+
const mapped = /^::ffff:(?:(\d+\.\d+\.\d+\.\d+)|([0-9a-f]{1,4}):([0-9a-f]{1,4}))$/i.exec(address);
|
|
1697
|
+
if (!mapped)
|
|
1698
|
+
return address;
|
|
1699
|
+
if (mapped[1])
|
|
1700
|
+
return mapped[1];
|
|
1701
|
+
const high = Number.parseInt(mapped[2] ?? "0", 16);
|
|
1702
|
+
const low = Number.parseInt(mapped[3] ?? "0", 16);
|
|
1703
|
+
return [high >> 8, high & 255, low >> 8, low & 255].join(".");
|
|
1505
1704
|
}
|
|
1506
1705
|
static #refuseHost(url, allowHosts) {
|
|
1507
1706
|
let parsed;
|
|
@@ -1533,7 +1732,7 @@ class AkanCodePlugins2 {
|
|
|
1533
1732
|
});
|
|
1534
1733
|
const dispose = () => mcp?.close();
|
|
1535
1734
|
const mcpStatus = mcp?.status ?? [];
|
|
1536
|
-
const web = new WebToolPack2({ profile: options.profile });
|
|
1735
|
+
const web = new WebToolPack2({ profile: options.profile, deepseek: options.deepseek });
|
|
1537
1736
|
const sessions = new SessionToolPack2({
|
|
1538
1737
|
workspaceRoot: options.workspace.workspaceRoot,
|
|
1539
1738
|
cwd: options.cwd,
|
|
@@ -1668,9 +1867,9 @@ class CodeAgentAsks2 {
|
|
|
1668
1867
|
|
|
1669
1868
|
// pkgs/@akanjs/devkit/codeAgent/agent/CodeAgentEventMapper.ts
|
|
1670
1869
|
import {
|
|
1671
|
-
codeAgentClip as
|
|
1870
|
+
codeAgentClip as codeAgentClip5,
|
|
1672
1871
|
codeAgentLabelChars,
|
|
1673
|
-
codeAgentOutputChars as
|
|
1872
|
+
codeAgentOutputChars as codeAgentOutputChars3
|
|
1674
1873
|
} from "akanjs/common";
|
|
1675
1874
|
|
|
1676
1875
|
// pkgs/@akanjs/devkit/codeAgent/agent/stringArg.ts
|
|
@@ -1730,7 +1929,7 @@ class CodeAgentEventMapper2 {
|
|
|
1730
1929
|
type: "tool_progress",
|
|
1731
1930
|
turnId: this.#turnId,
|
|
1732
1931
|
toolCallId: event.toolCallId,
|
|
1733
|
-
text:
|
|
1932
|
+
text: codeAgentClip5(CodeAgentEventMapper2.#renderToolText(event.partialResult), codeAgentLabelChars)
|
|
1734
1933
|
}
|
|
1735
1934
|
];
|
|
1736
1935
|
case "tool_execution_end":
|
|
@@ -1801,8 +2000,8 @@ class CodeAgentEventMapper2 {
|
|
|
1801
2000
|
turnId: this.#turnId,
|
|
1802
2001
|
tool,
|
|
1803
2002
|
outcome: reason ? "blocked" : event.isError ? "error" : "ok",
|
|
1804
|
-
output:
|
|
1805
|
-
truncated: full.length >
|
|
2003
|
+
output: codeAgentClip5(full, codeAgentOutputChars3),
|
|
2004
|
+
truncated: full.length > codeAgentOutputChars3
|
|
1806
2005
|
};
|
|
1807
2006
|
}
|
|
1808
2007
|
noteOutcome(reason) {
|
|
@@ -1831,7 +2030,7 @@ class CodeAgentEventMapper2 {
|
|
|
1831
2030
|
name,
|
|
1832
2031
|
op: toolOps[name] ?? "other",
|
|
1833
2032
|
...path ? { path } : {},
|
|
1834
|
-
title:
|
|
2033
|
+
title: codeAgentClip5(`${name}${CodeAgentEventMapper2.#renderArgs(args)}`, codeAgentLabelChars)
|
|
1835
2034
|
};
|
|
1836
2035
|
}
|
|
1837
2036
|
#mapDelta(event) {
|
|
@@ -1858,7 +2057,7 @@ class CodeAgentEventMapper2 {
|
|
|
1858
2057
|
if (!entries.length)
|
|
1859
2058
|
return "";
|
|
1860
2059
|
const rendered = entries.map(([key, value]) => `${key}=${CodeAgentEventMapper2.#renderArgValue(value)}`).join(" ");
|
|
1861
|
-
return `(${
|
|
2060
|
+
return `(${codeAgentClip5(rendered, 120)})`;
|
|
1862
2061
|
}
|
|
1863
2062
|
static #renderArgValue(value) {
|
|
1864
2063
|
if (Array.isArray(value))
|
|
@@ -1867,7 +2066,7 @@ class CodeAgentEventMapper2 {
|
|
|
1867
2066
|
const keys = Object.keys(value).length;
|
|
1868
2067
|
return `{${keys} key${keys === 1 ? "" : "s"}}`;
|
|
1869
2068
|
}
|
|
1870
|
-
return
|
|
2069
|
+
return codeAgentClip5(String(value), 60);
|
|
1871
2070
|
}
|
|
1872
2071
|
static #renderContent(content) {
|
|
1873
2072
|
if (typeof content === "string")
|
|
@@ -2308,6 +2507,7 @@ class CodeAgent2 {
|
|
|
2308
2507
|
#replay = [];
|
|
2309
2508
|
#replayFrom = 0;
|
|
2310
2509
|
#lastContextTokens;
|
|
2510
|
+
#autoCompactAt;
|
|
2311
2511
|
constructor(profile) {
|
|
2312
2512
|
this.#profile = profile;
|
|
2313
2513
|
this.#gate = new CodeAgentGate2(profile);
|
|
@@ -2316,8 +2516,10 @@ class CodeAgent2 {
|
|
|
2316
2516
|
const workspaceRoot = options.workspace.workspaceRoot;
|
|
2317
2517
|
const cwd = options.cwd ?? workspaceRoot;
|
|
2318
2518
|
const agent = new CodeAgent2(options.profile);
|
|
2519
|
+
const autoCompactAt = AkanCodeCompaction2.normalize(options.autoCompactAt);
|
|
2319
2520
|
const settingsManager = AkanCodeServices2.settings();
|
|
2320
|
-
const
|
|
2521
|
+
const proxy = CodeAgentProxy.fromEnv(options.profile);
|
|
2522
|
+
const modelRuntime = await AkanCodeServices2.runtime(workspaceRoot, proxy);
|
|
2321
2523
|
const model = await akanCodeModel2(modelRuntime, options.model);
|
|
2322
2524
|
const compaction = settingsManager.getCompactionSettings(model);
|
|
2323
2525
|
const modelWarnings = akanCodeModelWarnings2(model, compaction.reserveTokens + compaction.keepRecentTokens);
|
|
@@ -2327,6 +2529,7 @@ class CodeAgent2 {
|
|
|
2327
2529
|
profile: options.profile,
|
|
2328
2530
|
apps: options.apps ?? [],
|
|
2329
2531
|
canSeeImages: akanCodeModelSupportsImages2(model),
|
|
2532
|
+
deepseek: await DeepSeekWeb.fromRuntime(modelRuntime, !!proxy),
|
|
2330
2533
|
depth: options.depth ?? 0,
|
|
2331
2534
|
...options.subagentSpend ? { subagentSpend: options.subagentSpend } : {},
|
|
2332
2535
|
currentSessionId: () => agent.sessionId,
|
|
@@ -2365,10 +2568,11 @@ class CodeAgent2 {
|
|
|
2365
2568
|
if (options.profile.session.store !== "memory")
|
|
2366
2569
|
agent.#sessionDir = akanCodePaths2.sessionsDir(workspaceRoot);
|
|
2367
2570
|
await agent.#attach(session, options.mode ?? "print");
|
|
2571
|
+
const autoCompactWarning = agent.#fitAutoCompact(autoCompactAt);
|
|
2368
2572
|
agent.#suspended = new CodeAgentSuspended(CodeAgentSuspended.fileOf(agent.#sessionDir, agent.sessionId));
|
|
2369
2573
|
if (agent.#sessionDir && options.profile.session.store === "file")
|
|
2370
2574
|
agent.#openMail(akanCodePaths2.mailDir(workspaceRoot), cwd);
|
|
2371
|
-
for (const message of modelWarnings)
|
|
2575
|
+
for (const message of [...modelWarnings, ...autoCompactWarning])
|
|
2372
2576
|
agent.#emit({ type: "notice", level: "warning", message });
|
|
2373
2577
|
return agent;
|
|
2374
2578
|
}
|
|
@@ -2433,6 +2637,7 @@ ${mail.text}`).catch((error) => this.#emit({ type: "notice", level: "error", mes
|
|
|
2433
2637
|
tools: session.getActiveToolNames(),
|
|
2434
2638
|
contextTokens: model?.contextWindow,
|
|
2435
2639
|
effort: session.supportsThinking() ? session.thinkingLevel : undefined,
|
|
2640
|
+
autoCompactAt: this.#autoCompactAt,
|
|
2436
2641
|
name: session.sessionName,
|
|
2437
2642
|
interaction: this.#profile.interaction
|
|
2438
2643
|
};
|
|
@@ -2581,8 +2786,38 @@ Continue the task.`);
|
|
|
2581
2786
|
if (!model)
|
|
2582
2787
|
throw new Error(`Unknown model: ${ref.provider}/${ref.id}`);
|
|
2583
2788
|
await session.setModel(model);
|
|
2789
|
+
for (const message of this.#fitAutoCompact(this.#autoCompactAt))
|
|
2790
|
+
this.#emit({ type: "notice", level: "warning", message });
|
|
2791
|
+
this.#emit({ type: "session", info: this.info });
|
|
2792
|
+
}
|
|
2793
|
+
setAutoCompactAt(percent) {
|
|
2794
|
+
const wanted = AkanCodeCompaction2.normalize(percent);
|
|
2795
|
+
const problem = this.#autoCompactProblem(wanted);
|
|
2796
|
+
if (problem)
|
|
2797
|
+
throw new Error(problem);
|
|
2798
|
+
this.#autoCompactAt = wanted;
|
|
2799
|
+
this.#applyAutoCompact();
|
|
2584
2800
|
this.#emit({ type: "session", info: this.info });
|
|
2585
2801
|
}
|
|
2802
|
+
#fitAutoCompact(percent) {
|
|
2803
|
+
const problem = this.#autoCompactProblem(percent);
|
|
2804
|
+
this.#autoCompactAt = problem ? undefined : percent;
|
|
2805
|
+
this.#applyAutoCompact();
|
|
2806
|
+
return problem ? [`${problem} Autocompact is back to the default.`] : [];
|
|
2807
|
+
}
|
|
2808
|
+
#autoCompactProblem(percent) {
|
|
2809
|
+
const session = this.#require();
|
|
2810
|
+
const model = session.model;
|
|
2811
|
+
if (!model || !percent)
|
|
2812
|
+
return;
|
|
2813
|
+
const { keepRecentTokens } = session.settingsManager.getCompactionSettings(model);
|
|
2814
|
+
return AkanCodeCompaction2.problemOf(model, percent, keepRecentTokens);
|
|
2815
|
+
}
|
|
2816
|
+
#applyAutoCompact() {
|
|
2817
|
+
const session = this.#require();
|
|
2818
|
+
if (session.model)
|
|
2819
|
+
AkanCodeCompaction2.apply(session.settingsManager, session.model, this.#autoCompactAt);
|
|
2820
|
+
}
|
|
2586
2821
|
async waitForIdle() {
|
|
2587
2822
|
await this.#require().waitForIdle();
|
|
2588
2823
|
}
|
|
@@ -2689,7 +2924,7 @@ Continue the task.`);
|
|
|
2689
2924
|
approvalId,
|
|
2690
2925
|
toolCallId,
|
|
2691
2926
|
name,
|
|
2692
|
-
summary:
|
|
2927
|
+
summary: codeAgentClip6(summary, codeAgentLabelChars2),
|
|
2693
2928
|
policy: this.#profile.approval
|
|
2694
2929
|
};
|
|
2695
2930
|
this.#emit({ type: "approval", request });
|