@zaly/agent 0.0.12 → 0.1.1
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/{agent-Dp4LZDSo.mjs → agent-BRENvuvx.mjs} +8 -11
- package/dist/{agent-Dp4LZDSo.mjs.map → agent-BRENvuvx.mjs.map} +1 -1
- package/dist/{agent-B7cQOuMZ.mjs → agent-sHtwQDAk.mjs} +2 -3
- package/dist/{agent-B7cQOuMZ.mjs.map → agent-sHtwQDAk.mjs.map} +1 -1
- package/dist/{bash-COgq4W7U.mjs → bash-DSy03sAj.mjs} +8 -9
- package/dist/bash-DSy03sAj.mjs.map +1 -0
- package/dist/compactions-HFjEgrv3.mjs +150 -0
- package/dist/compactions-HFjEgrv3.mjs.map +1 -0
- package/dist/{edit-D4yaBK1K.mjs → edit-DT672zIy.mjs} +2 -3
- package/dist/edit-DT672zIy.mjs.map +1 -0
- package/dist/{env-UUFv5Mye.mjs → env-C8p8i1E0.mjs} +2 -3
- package/dist/{env-UUFv5Mye.mjs.map → env-C8p8i1E0.mjs.map} +1 -1
- package/dist/fetch-BrtIqrid.mjs +158 -0
- package/dist/fetch-BrtIqrid.mjs.map +1 -0
- package/dist/{find-CimUGn-L.mjs → find-B-vvdlHu.mjs} +30 -13
- package/dist/find-B-vvdlHu.mjs.map +1 -0
- package/dist/{grep-6O3mjSvV.mjs → grep-rvZ5S319.mjs} +19 -10
- package/dist/grep-rvZ5S319.mjs.map +1 -0
- package/dist/html-VrAsoGBK.mjs +32950 -0
- package/dist/html-VrAsoGBK.mjs.map +1 -0
- package/dist/{index-node-esm-CJsN8G51.mjs → index-node-esm-BwaOzhXB.mjs} +2 -3
- package/dist/{index-node-esm-CJsN8G51.mjs.map → index-node-esm-BwaOzhXB.mjs.map} +1 -1
- package/dist/index.d.mts +72 -100
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +3 -3
- package/dist/{jsonl-CvgEOakL.mjs → jsonl-BGt7eqPK.mjs} +2 -3
- package/dist/{jsonl-CvgEOakL.mjs.map → jsonl-BGt7eqPK.mjs.map} +1 -1
- package/dist/{manager-BqlbCGYV.mjs → manager-1zEE5WiA.mjs} +4 -6
- package/dist/{manager-BqlbCGYV.mjs.map → manager-1zEE5WiA.mjs.map} +1 -1
- package/dist/{markdown-Bv4J8cg3.mjs → markdown-8ICz5aFw.mjs} +2 -3
- package/dist/{markdown-Bv4J8cg3.mjs.map → markdown-8ICz5aFw.mjs.map} +1 -1
- package/dist/{masker-ZoP381jN.mjs → masker-DEgR_ntk.mjs} +4 -6
- package/dist/{masker-ZoP381jN.mjs.map → masker-DEgR_ntk.mjs.map} +1 -1
- package/dist/{model-_3ZA2xqm.mjs → model-DqGqxfAc.mjs} +2 -3
- package/dist/{model-_3ZA2xqm.mjs.map → model-DqGqxfAc.mjs.map} +1 -1
- package/dist/{notify-DpG_m9iP.mjs → notify-Ds0-4BeI.mjs} +2 -3
- package/dist/{notify-DpG_m9iP.mjs.map → notify-Ds0-4BeI.mjs.map} +1 -1
- package/dist/{read-B-hwcc2Q.mjs → read-C5keKntU.mjs} +4 -44
- package/dist/read-C5keKntU.mjs.map +1 -0
- package/dist/{registry-L9GDccS0.mjs → registry-CntkeXlo.mjs} +45 -45
- package/dist/registry-CntkeXlo.mjs.map +1 -0
- package/dist/rolldown-runtime-DYf_mQCB.mjs +34 -0
- package/dist/{search-CRw247ES.mjs → search-B-89W3SM.mjs} +20 -17
- package/dist/search-B-89W3SM.mjs.map +1 -0
- package/dist/session/claude.d.mts +0 -2
- package/dist/session/claude.d.mts.map +1 -1
- package/dist/session/claude.mjs +4 -6
- package/dist/session/claude.mjs.map +1 -1
- package/dist/{session-BSvUrr12.mjs → session-C8zqqbPE.mjs} +6 -8
- package/dist/{session-BSvUrr12.mjs.map → session-C8zqqbPE.mjs.map} +1 -1
- package/dist/{session-Ds5nJz5A.d.mts → session-Cq52cam5.d.mts} +1 -11
- package/dist/session-Cq52cam5.d.mts.map +1 -0
- package/dist/session.d.mts +1 -3
- package/dist/session.d.mts.map +1 -1
- package/dist/session.mjs +4 -5
- package/dist/{src-C852Q6gy.mjs → src-C04Qk9KE.mjs} +35 -39
- package/dist/{src-C852Q6gy.mjs.map → src-C04Qk9KE.mjs.map} +1 -1
- package/dist/{subagent-C8XCEecM.mjs → subagent-BbcxLzgC.mjs} +4 -5
- package/dist/{subagent-C8XCEecM.mjs.map → subagent-BbcxLzgC.mjs.map} +1 -1
- package/dist/{swarm-BJ3gQA1Z.mjs → swarm-B_s9Qpbt.mjs} +2 -3
- package/dist/{swarm-BJ3gQA1Z.mjs.map → swarm-B_s9Qpbt.mjs.map} +1 -1
- package/dist/{swarm-BuFx_xeY.mjs → swarm-D823Yumk.mjs} +2 -3
- package/dist/{swarm-BuFx_xeY.mjs.map → swarm-D823Yumk.mjs.map} +1 -1
- package/dist/{tasks-WdRAHsOL.mjs → tasks-D76WXWr2.mjs} +3 -4
- package/dist/{tasks-WdRAHsOL.mjs.map → tasks-D76WXWr2.mjs.map} +1 -1
- package/dist/{tasks-BA-PCeGa.mjs → tasks-Dgsiuh0Q.mjs} +3 -4
- package/dist/{tasks-BA-PCeGa.mjs.map → tasks-Dgsiuh0Q.mjs.map} +1 -1
- package/dist/{tools-wvkkuXWH.mjs → tools-DmoUYORG.mjs} +7 -42
- package/dist/{tools-wvkkuXWH.mjs.map → tools-DmoUYORG.mjs.map} +1 -1
- package/dist/{truncate-BSMXgiXj.mjs → truncate-CChlZ113.mjs} +2 -3
- package/dist/{truncate-BSMXgiXj.mjs.map → truncate-CChlZ113.mjs.map} +1 -1
- package/dist/{uuid-CAdJg4l8.mjs → uuid-rfbQ9ad2.mjs} +2 -3
- package/dist/{uuid-CAdJg4l8.mjs.map → uuid-rfbQ9ad2.mjs.map} +1 -1
- package/dist/{wakeup-BYqTnfSp.mjs → wakeup-CFr1nu_L.mjs} +2 -3
- package/dist/{wakeup-BYqTnfSp.mjs.map → wakeup-CFr1nu_L.mjs.map} +1 -1
- package/dist/{write-DwGiDNeG.mjs → write-BRQFfWAn.mjs} +2 -3
- package/dist/write-BRQFfWAn.mjs.map +1 -0
- package/package.json +46 -8
- package/dist/bash-COgq4W7U.mjs.map +0 -1
- package/dist/compactions-CvQs64fS.mjs +0 -191
- package/dist/compactions-CvQs64fS.mjs.map +0 -1
- package/dist/edit-D4yaBK1K.mjs.map +0 -1
- package/dist/fetch-VKhSWdEh.mjs +0 -111
- package/dist/fetch-VKhSWdEh.mjs.map +0 -1
- package/dist/find-CimUGn-L.mjs.map +0 -1
- package/dist/grep-6O3mjSvV.mjs.map +0 -1
- package/dist/read-B-hwcc2Q.mjs.map +0 -1
- package/dist/registry-L9GDccS0.mjs.map +0 -1
- package/dist/search-CRw247ES.mjs.map +0 -1
- package/dist/session-Ds5nJz5A.d.mts.map +0 -1
- package/dist/write-DwGiDNeG.mjs.map +0 -1
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { r as uuidv7 } from "./uuid-
|
|
3
|
-
import { n as JsonlStore } from "./jsonl-
|
|
1
|
+
import { n as __exportAll } from "./rolldown-runtime-DYf_mQCB.mjs";
|
|
2
|
+
import { r as uuidv7 } from "./uuid-rfbQ9ad2.mjs";
|
|
3
|
+
import { n as JsonlStore } from "./jsonl-BGt7eqPK.mjs";
|
|
4
4
|
import { Emitter, normPath } from "@zaly/shared";
|
|
5
5
|
import { join } from "pathe";
|
|
6
6
|
import { isDeepStrictEqual } from "node:util";
|
|
7
7
|
import { zalyPaths } from "@zaly/shared/paths";
|
|
8
|
-
|
|
8
|
+
// src/session/memory.ts
|
|
9
9
|
/**
|
|
10
10
|
* In-memory `SessionStore` — a `Map<uuid, SessionNode>` plus a `root`
|
|
11
11
|
* pointer. No persistence. Construction takes optional initial nodes
|
|
@@ -35,8 +35,7 @@ var MemoryStore = class {
|
|
|
35
35
|
yield* this.#nodes.values();
|
|
36
36
|
}
|
|
37
37
|
};
|
|
38
|
-
|
|
39
|
-
//#region src/session/session.ts
|
|
38
|
+
// src/session/session.ts
|
|
40
39
|
var session_exports = /* @__PURE__ */ __exportAll({ Session: () => Session });
|
|
41
40
|
const VERSION = 2;
|
|
42
41
|
/**
|
|
@@ -444,7 +443,6 @@ var Session = class Session extends Emitter {
|
|
|
444
443
|
}
|
|
445
444
|
}
|
|
446
445
|
};
|
|
447
|
-
//#endregion
|
|
448
446
|
export { session_exports as n, MemoryStore as r, Session as t };
|
|
449
447
|
|
|
450
|
-
//# sourceMappingURL=session-
|
|
448
|
+
//# sourceMappingURL=session-C8zqqbPE.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"session-BSvUrr12.mjs","names":[],"sources":["../src/session/memory.ts","../src/session/session.ts"],"sourcesContent":["import type { SessionStore } from \"./store.ts\"\nimport type { SessionNode } from \"./types.ts\"\n\n/**\n * In-memory `SessionStore` — a `Map<uuid, SessionNode>` plus a `root`\n * pointer. No persistence. Construction takes optional initial nodes\n * for tests, replay tools, and the Claude session importer.\n */\nexport class MemoryStore implements SessionStore {\n readonly #nodes: Map<string, SessionNode>\n #root?: SessionNode\n\n constructor(nodes?: Iterable<SessionNode>) {\n this.#nodes = new Map()\n if (nodes) {\n for (const node of nodes) {\n this.#nodes.set(node.uuid, node)\n this.#root = node\n }\n }\n }\n\n get root(): SessionNode | undefined {\n return this.#root\n }\n\n async get(id: string): Promise<SessionNode | undefined> {\n return this.#nodes.get(id)\n }\n\n async write(node: SessionNode): Promise<void> {\n this.#nodes.set(node.uuid, node)\n this.#root = node\n }\n\n *all(): Iterable<SessionNode> {\n yield* this.#nodes.values()\n }\n}\n","import type { Message } from \"@zaly/ai\"\nimport type { SessionStore } from \"./store.ts\"\nimport type {\n MaskCheckpoint,\n PartialNode,\n SessionEvents,\n SessionInit,\n SessionMessage,\n SessionNode,\n SessionNodeView,\n SessionOptions,\n SessionSettings,\n SessionUpdate,\n SessionView,\n} from \"./types.ts\"\n\nimport { Emitter, normPath } from \"@zaly/shared\"\nimport { zalyPaths } from \"@zaly/shared/paths\"\nimport { isDeepStrictEqual } from \"node:util\"\nimport { join } from \"pathe\"\nimport { uuidv7 } from \"../utils/uuid.ts\"\nimport { JsonlStore } from \"./jsonl.ts\"\nimport { MemoryStore } from \"./memory.ts\"\n\nconst VERSION = 2\n\n/**\n * Conversation primitive. Owns a DAG of message + compaction + meta\n * nodes via a `SessionStore` backend; the *active* message list is\n * whatever you get by walking `parentUuid` backwards from the store's\n * root until you hit a `compact` node (or the start).\n *\n * **Meta is snapshot-based.** `session-meta` nodes carry the full\n * cumulative meta as of their commit time. Other node types (start,\n * resume, message, compact) don't carry meta — `Session` reconstructs\n * the cumulative meta at any point by finding the most recent\n * `session-meta` ancestor in a forward pass over the chain. Public\n * APIs return `SessionNodeView` (raw node + decorated `meta`).\n *\n * Designed so the loop, the persistor, the TUI, and any replay tool\n * all read from one source of truth and never mutate the DAG behind\n * each other's backs:\n *\n * - **Run loop** (`Agent`) calls `add()` on each new message and\n * `compact()` on overflow.\n * - **TUI** subscribes to the `node` event for streaming render.\n * - **Persistor** is the `SessionStore` — `MemoryStore` for ephemeral\n * sessions, `JsonlStore` for file-backed.\n *\n * Construction:\n * - Use `await Session.load(opts)` for the recommended path — picks\n * the right store (Memory if no path, JSONL if path).\n * - For tests / direct embedding, `new Session({ store })` works with\n * any pre-built store.\n */\nexport class Session<T extends SessionStore = SessionStore> extends Emitter<SessionEvents> {\n readonly #store: T\n #opts: SessionInit<T>\n #id: string\n #dir: string\n #settings: SessionSettings = {}\n #view: SessionView = { messages: [], nodes: new Map() }\n #closed = false\n #started = false\n #path?: string\n #head?: string\n\n protected constructor(opts: SessionInit<T>) {\n super()\n this.#opts = opts\n this.#path = opts.path\n this.#store = opts.store\n this.#id = opts.defaults?.sessionId ?? uuidv7()\n this.#dir = normPath(opts.dir ?? join(zalyPaths.env.tmp, \"sessions\", this.#id))\n }\n\n /** Recommended one-step path: pick the right store backend, hydrate\n * if applicable, return a ready-to-use session.\n *\n * - `path` provided → `JsonlStore` (file-backed, hydrates from disk\n * if the file exists, opens for append either way).\n * - No `path` → `MemoryStore` (ephemeral, no persistence). */\n static async load<T extends SessionStore = SessionStore>(\n opts: SessionOptions<T> & { store: T }\n ): Promise<Session<T>>\n static async load(opts: SessionOptions & { path: string }): Promise<Session<JsonlStore>>\n static async load(opts?: SessionOptions & {}): Promise<Session<MemoryStore>>\n static async load(opts: SessionOptions = {}): Promise<Session> {\n const session = await Session.create(opts)\n await session.#rebuild()\n return session\n }\n\n private static async create(opts: SessionOptions = {}): Promise<Session> {\n const path = opts.path ? normPath(opts.path) : undefined\n const store: SessionStore =\n opts.store ?? (path ? await JsonlStore.load(path) : new MemoryStore())\n const init: SessionInit = { ...opts, path, store }\n return new Session(init)\n }\n\n /** Efficiently fetch the most recent user message by walking backward until we hit\n * a user message, without reconstructing the full chain. Useful for a session picker. */\n static async lastMessage(opts: SessionOptions = {}): Promise<Message<\"user\"> | undefined> {\n const session = await Session.create(opts)\n let ret: Message<\"user\"> | undefined\n await session.#chain({\n stop: (node) => {\n if (node.type === \"message\" && node.message.role === \"user\") {\n ret = node.message\n return true\n }\n return false\n },\n })\n void session.close()\n return ret\n }\n\n async #rebuild(): Promise<void> {\n const chain = await this.#chain()\n this.#view = chain\n this.#settings = chain.settings\n this.#id = chain.settings.sessionId ?? this.#id\n }\n\n // ── Read ──────────────────────────────────────────────────────────────\n\n /** Active conversation — chain from current head back to the most\n * recent compact (exclusive), in chronological order. This is what\n * the agent sees on the next request. */\n get messages(): readonly Message[] {\n return this.#view.messages\n }\n\n get maskCheckpoint(): MaskCheckpoint | undefined {\n return this.#view.maskCheckpoint\n }\n\n get id(): string {\n return this.#id\n }\n\n get dir(): string {\n return this.#dir\n }\n\n get path(): string | undefined {\n return this.#path\n }\n\n get started(): boolean {\n return this.#started\n }\n\n /** Current session settings, merged with defaults. */\n get settings(): SessionSettings {\n return { ...this.#opts.defaults, ...this.#settings }\n }\n\n async update(settings: SessionUpdate, opts?: { force?: boolean }): Promise<string> {\n return this.#commit({ settings, type: \"session-settings\" }, opts)\n }\n\n /** Lazily emits `session-start` on a fresh session or `session-resume`\n * on a hydrated one. Called from `#commit` before the first non-marker\n * node lands so the start/resume marker always heads the chain. */\n async #autostart(): Promise<void> {\n if (!this.#started) await this.start()\n }\n\n /** Explicitly mark the session as started — writes a `session-start`\n * marker on a fresh session, `session-resume` on a hydrated one.\n * Idempotent; subsequent calls are no-ops. Optional `meta` is\n * applied via `update()` after the marker lands. */\n async start(settings?: SessionUpdate): Promise<string | undefined> {\n if (this.#started) return settings ? this.update(settings) : this.#store.root?.uuid\n this.#started = true\n const type = this.messages.length > 0 ? (\"session-resume\" as const) : (\"session-start\" as const)\n await this.#commit({ type })\n void this.emit(type)\n await this.update(settings ?? {})\n return this.#store.root?.uuid\n }\n\n /** Look up the decorated view for a node id — raw node plus the\n * cumulative meta as of that node's position. Returns the\n * message-typed view, or `undefined` if the id doesn't refer to a\n * message in this session. */\n async node(id?: string | Message): Promise<(SessionNodeView & { type: \"message\" }) | undefined> {\n const m = typeof id === \"string\" ? { id } : id\n if (!m?.id) return undefined\n const ret = this.#view.nodes.get(m.id)\n return ret?.type === \"message\" ? ret : undefined\n }\n\n /** Current head uuid — the root of the store, which is the most\n * recently appended node. */\n get head(): string | undefined {\n return this.#head ?? this.#store.root?.uuid\n }\n\n /** Full DAG iterator — backed by `store.all()`. Yields raw nodes\n * (no meta decoration). */\n nodes(): Iterable<SessionNode> | AsyncIterable<SessionNode> {\n return this.#store.all?.() ?? []\n }\n\n get root(): SessionNode | undefined {\n return this.#store.root\n }\n\n // ── Mutate ────────────────────────────────────────────────────────────\n\n /** Append a message. The new node is parented to the current head,\n * head advances, and a `node` event fires. Optional `meta` carries\n * usage / model / finish info — populate it for assistant turns\n * the agent commits after a step. Returns the assigned uuid.\n *\n * If `message.id` / `message.ts` are set (e.g. round-tripped from a\n * prior load), they're used as the node's uuid / timestamp; otherwise\n * fresh values are generated. The committed message always carries\n * both — `m.id === node.uuid` and `m.ts === node.ts`. */\n async add(message: Message): Promise<string> {\n const uuid = message.id ?? uuidv7()\n const ts = message.ts ?? Date.now()\n const m = { ...message, id: uuid, ts }\n return this.#commit({ message: m, type: \"message\" })\n }\n\n /** Mark a compaction boundary. Subsequent `add()` calls land after\n * this node; their messages form the new active conversation. The\n * pre-compact chain stays in the store but is no longer part of\n * `messages`. Also commits a fresh `session-meta` snapshot right\n * after the compact so post-compact lazy walks always have a nearby\n * meta anchor. */\n async compact(opts: {\n trigger?: \"manual\" | \"auto\"\n preTokens?: number\n durationMs?: number\n tail: number\n summary: Message<\"system\">\n }): Promise<string> {\n const node: SessionNode = {\n durationMs: opts.durationMs,\n parentUuid: this.#store.root?.uuid,\n preTokens: opts.preTokens,\n summary: opts.summary,\n tail: opts.tail,\n trigger: opts.trigger ?? \"manual\",\n ts: Date.now(),\n type: \"compact\",\n uuid: uuidv7(),\n }\n const compactUuid = await this.#commit(node)\n await this.update({}, { force: true })\n await this.#rebuild()\n void this.emit(\"compact\", { node })\n return compactUuid\n }\n\n async addMaskCheckpoint(opts: MaskCheckpoint): Promise<string> {\n this.#view.maskCheckpoint = opts\n return this.#commit({ ...opts, type: \"mask-checkpoint\" })\n }\n\n async checkout(uuid: string): Promise<void> {\n if (this.#closed) throw new Error(\"Session is closed\")\n this.#head = uuid\n await this.#rebuild()\n }\n\n /** Pre-active history of the current chain — messages from before\n * the most recent compact (and earlier compacts), in chronological\n * order. Useful for TUI scrollback that wants to render context the\n * agent itself no longer sees.\n *\n * `limit` truncates from the front (oldest), so the most recent\n * history messages always make it through. */\n async history(limit?: number): Promise<readonly Message[]> {\n const chain = await this.#chain({ active: false, limit })\n return chain.messages\n }\n\n /** Flush + close the underlying store. Subsequent writes throw. */\n async close(): Promise<void> {\n if (this.#closed) return\n this.#closed = true\n await this.#store.close?.()\n }\n\n // ── Internals ────────────────────────────────────────────────────────\n\n /** Atomically commit a node: register it in the store, update active\n * messages, persist, and emit. Single chokepoint for all mutations. */\n async #commit(n: PartialNode, opts: { force?: boolean } = {}): Promise<string> {\n let node: SessionNode = {\n ...n,\n parentUuid: this.head,\n ts: Date.now(),\n uuid: uuidv7(),\n }\n\n if (!this.#started && node.type !== \"session-start\" && node.type !== \"session-resume\") {\n await this.#autostart()\n }\n if (this.#closed) throw new Error(\"Session is closed\")\n\n const next: SessionSettings = {\n ...this.#opts.defaults,\n ...this.#settings,\n ...(node.type === \"session-settings\" ? node.settings : {}),\n sessionId: this.#id,\n version: VERSION,\n }\n if (next.cwd) next.cwd = normPath(next.cwd)\n if (next.workspace) next.workspace = normPath(next.workspace)\n\n if (node.type === \"session-settings\") {\n if (!opts.force && isDeepStrictEqual(this.#settings, next)) return this.#store.root!.uuid\n node = { ...node, settings: next }\n }\n\n node = { ...node, parentUuid: this.head }\n await this.#store.write(node)\n this.#head = undefined // invalidate head cache so it reflects the store's root on next read\n\n // Decorate the new node with cumulative meta and append to the\n // active chain view\n this.#view.nodes.set(node.uuid, { ...node, settings: next })\n if (node.type === \"message\") this.#view.messages.push(node.message)\n\n // cwd / meta event signaling\n if (node.type === \"session-settings\") {\n const prev = this.#settings\n this.#settings = next\n this.#emitChanges(prev)\n }\n\n void this.emit(\"node\", { node })\n return node.uuid\n }\n\n #emitChanges(prev: SessionSettings): void {\n const next = this.#settings\n if (next.cwd && next.cwd !== prev.cwd) void this.emit(\"cwd\", { cwd: next.cwd, prev: prev.cwd })\n if (next.modelId && next.modelId !== prev.modelId)\n void this.emit(\"model\", { model: next.modelId, prev: prev.modelId })\n if (next.reasoning && next.reasoning !== prev.reasoning)\n void this.emit(\"reasoning\", { effort: next.reasoning, prev: prev.reasoning })\n }\n\n /** Walk `parentUuid` from the given node back toward the root,\n * returning the chain as decorated views (each with cumulative meta).\n * The `active` flag controls what counts:\n * - `true` — only the active chain (stops at first compact /\n * session-start, with the kept tail spliced in via\n * the compact's `tail` field, summary substituted\n * in place of the compact node).\n * - `false` — includes everything back to the root\n * Returns chronological order. */\n async #chain(\n opts: {\n active?: boolean\n limit?: number\n uuid?: string\n stop?: (node: SessionNode) => boolean\n } = {}\n ): Promise<SessionView & { settings: SessionSettings }> {\n // Backward pass: collect raw nodes (new to old)\n const reverse: SessionNode[] = []\n let cursor = opts.uuid ?? this.head\n let limit = opts.limit ?? Infinity\n let compact: SessionNode<\"compact\"> | undefined\n const messageNodes: SessionNode<\"message\">[] = []\n let maskCheckpoint: SessionNode<\"mask-checkpoint\"> | undefined\n\n // Walk backward from the head until we hit a compact or the start, collecting nodes.\n while (cursor) {\n // eslint-disable-next-line no-await-in-loop\n const node = await this.#store.get(cursor)\n if (!node || (node.type === \"message\" && messageNodes.length + 1 > limit)) break\n cursor = node.parentUuid\n reverse.push(node)\n // Keep track if the last mask-checkpoint, until we hit a compaction.\n if (node.type === \"mask-checkpoint\" && !compact && !maskCheckpoint) maskCheckpoint = node\n if (node.type === \"message\") messageNodes.push(node)\n if (node.type === \"compact\" && (opts.active ?? true)) {\n if (compact) break // stop at the first compact\n compact = node\n // update limit to the compact's tail\n limit = Math.min(limit, messageNodes.length + node.tail)\n }\n if (opts.stop?.(node)) break\n }\n\n // Forward pass: decorate with cumulative meta. session-meta nodes\n // redefine the meta; everything else inherits the running snapshot.\n const nodes = new Map<string, SessionNodeView>()\n let settings: SessionSettings = {}\n for (const n of reverse.toReversed()) {\n if (n.type === \"session-settings\") settings = n.settings\n nodes.set(n.uuid, { ...n, settings })\n }\n\n this.#migrate(nodes)\n\n const messages: SessionMessage[] = []\n for (const n of messageNodes) {\n // add `id`, `ts` and `modelId` (if assistant turn) to the message\n const m = { ...n.message, id: n.uuid, ts: n.ts }\n if (m.role === \"assistant\") {\n // Add missing modelId to assistant messages if not present\n const s = nodes.get(n.uuid)?.settings ?? {}\n m.meta = { ...m.meta, modelId: m.meta?.modelId ?? s.modelId }\n }\n n.message = m\n messages.push(m)\n }\n\n // Add compaction summary as the first message\n if (compact) {\n messages.push({ ...compact.summary, id: compact.uuid, ts: compact.ts })\n nodes.set(compact.uuid, {\n message: compact.summary,\n parentUuid: compact.parentUuid,\n settings: nodes.get(compact.uuid)?.settings ?? {},\n ts: compact.ts,\n type: \"message\",\n uuid: compact.uuid,\n })\n }\n\n return {\n compact,\n maskCheckpoint,\n messages: messages.toReversed(),\n nodes,\n settings,\n }\n }\n\n #migrate(nodes: Map<string, SessionNodeView>) {\n for (const n of nodes.values()) {\n const version = n.settings.version ?? 0\n if (version === VERSION) continue\n n.settings = { ...n.settings, version: VERSION }\n\n if (n.type === \"compact\") {\n n.summary.meta = { kind: \"compaction-summary\", ...n.summary.meta }\n continue\n }\n\n if (n.type !== \"message\") continue\n const m = n.message\n\n if (\n m.role === \"system\" &&\n Array.isArray(m.content) &&\n m.content[0].type === \"meta\" &&\n m.content[0].tag === \"task\"\n ) {\n // Missing task meta data kind\n m.meta = { kind: \"task\", ...m.meta }\n }\n\n n.message = m\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;AAQA,IAAa,cAAb,MAAiD;CAC/C;CACA;CAEA,YAAY,OAA+B;EACzC,KAAK,yBAAS,IAAI,IAAI;EACtB,IAAI,OACF,KAAK,MAAM,QAAQ,OAAO;GACxB,KAAK,OAAO,IAAI,KAAK,MAAM,IAAI;GAC/B,KAAK,QAAQ;EACf;CAEJ;CAEA,IAAI,OAAgC;EAClC,OAAO,KAAK;CACd;CAEA,MAAM,IAAI,IAA8C;EACtD,OAAO,KAAK,OAAO,IAAI,EAAE;CAC3B;CAEA,MAAM,MAAM,MAAkC;EAC5C,KAAK,OAAO,IAAI,KAAK,MAAM,IAAI;EAC/B,KAAK,QAAQ;CACf;CAEA,CAAC,MAA6B;EAC5B,OAAO,KAAK,OAAO,OAAO;CAC5B;AACF;;;;ACdA,MAAM,UAAU;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+BhB,IAAa,UAAb,MAAa,gBAAuD,QAAuB;CACzF;CACA;CACA;CACA;CACA,YAA6B,CAAC;CAC9B,QAAqB;EAAE,UAAU,CAAC;EAAG,uBAAO,IAAI,IAAI;CAAE;C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E,YAAY,CAAC;IAC1C,EAAE,OAAO;KAAE,GAAG,EAAE;KAAM,SAAS,EAAE,MAAM,WAAW,EAAE;IAAQ;GAC9D;GACA,EAAE,UAAU;GACZ,SAAS,KAAK,CAAC;EACjB;EAGA,IAAI,SAAS;GACX,SAAS,KAAK;IAAE,GAAG,QAAQ;IAAS,IAAI,QAAQ;IAAM,IAAI,QAAQ;GAAG,CAAC;GACtE,MAAM,IAAI,QAAQ,MAAM;IACtB,SAAS,QAAQ;IACjB,YAAY,QAAQ;IACpB,UAAU,MAAM,IAAI,QAAQ,IAAI,CAAC,EAAE,YAAY,CAAC;IAChD,IAAI,QAAQ;IACZ,MAAM;IACN,MAAM,QAAQ;GAChB,CAAC;EACH;EAEA,OAAO;GACL;GACA;GACA,UAAU,SAAS,WAAW;GAC9B;GACA;EACF;CACF;CAEA,SAAS,OAAqC;EAC5C,KAAK,MAAM,KAAK,MAAM,OAAO,GAAG;GAE9B,KADgB,EAAE,SAAS,WAAW,OACtB,SAAS;GACzB,EAAE,WAAW;IAAE,GAAG,EAAE;IAAU,SAAS;GAAQ;GAE/C,IAAI,EAAE,SAAS,WAAW;IACxB,EAAE,QAAQ,OAAO;KAAE,MAAM;KAAsB,GAAG,EAAE,QAAQ;IAAK;IACjE;GACF;GAEA,IAAI,EAAE,SAAS,WAAW;GAC1B,MAAM,IAAI,EAAE;GAEZ,IACE,EAAE,SAAS,YACX,MAAM,QAAQ,EAAE,OAAO,KACvB,EAAE,QAAQ,EAAE,CAAC,SAAS,UACtB,EAAE,QAAQ,EAAE,CAAC,QAAQ,QAGrB,EAAE,OAAO;IAAE,MAAM;IAAQ,GAAG,EAAE;GAAK;GAGrC,EAAE,UAAU;EACd;CACF;AACF"}
|
|
1
|
+
{"version":3,"file":"session-C8zqqbPE.mjs","names":[],"sources":["../src/session/memory.ts","../src/session/session.ts"],"sourcesContent":["import type { SessionStore } from \"./store.ts\"\nimport type { SessionNode } from \"./types.ts\"\n\n/**\n * In-memory `SessionStore` — a `Map<uuid, SessionNode>` plus a `root`\n * pointer. No persistence. Construction takes optional initial nodes\n * for tests, replay tools, and the Claude session importer.\n */\nexport class MemoryStore implements SessionStore {\n readonly #nodes: Map<string, SessionNode>\n #root?: SessionNode\n\n constructor(nodes?: Iterable<SessionNode>) {\n this.#nodes = new Map()\n if (nodes) {\n for (const node of nodes) {\n this.#nodes.set(node.uuid, node)\n this.#root = node\n }\n }\n }\n\n get root(): SessionNode | undefined {\n return this.#root\n }\n\n async get(id: string): Promise<SessionNode | undefined> {\n return this.#nodes.get(id)\n }\n\n async write(node: SessionNode): Promise<void> {\n this.#nodes.set(node.uuid, node)\n this.#root = node\n }\n\n *all(): Iterable<SessionNode> {\n yield* this.#nodes.values()\n }\n}\n","import type { Message } from \"@zaly/ai\"\nimport type { SessionStore } from \"./store.ts\"\nimport type {\n MaskCheckpoint,\n PartialNode,\n SessionEvents,\n SessionInit,\n SessionMessage,\n SessionNode,\n SessionNodeView,\n SessionOptions,\n SessionSettings,\n SessionUpdate,\n SessionView,\n} from \"./types.ts\"\n\nimport { Emitter, normPath } from \"@zaly/shared\"\nimport { zalyPaths } from \"@zaly/shared/paths\"\nimport { isDeepStrictEqual } from \"node:util\"\nimport { join } from \"pathe\"\nimport { uuidv7 } from \"../utils/uuid.ts\"\nimport { JsonlStore } from \"./jsonl.ts\"\nimport { MemoryStore } from \"./memory.ts\"\n\nconst VERSION = 2\n\n/**\n * Conversation primitive. Owns a DAG of message + compaction + meta\n * nodes via a `SessionStore` backend; the *active* message list is\n * whatever you get by walking `parentUuid` backwards from the store's\n * root until you hit a `compact` node (or the start).\n *\n * **Meta is snapshot-based.** `session-meta` nodes carry the full\n * cumulative meta as of their commit time. Other node types (start,\n * resume, message, compact) don't carry meta — `Session` reconstructs\n * the cumulative meta at any point by finding the most recent\n * `session-meta` ancestor in a forward pass over the chain. Public\n * APIs return `SessionNodeView` (raw node + decorated `meta`).\n *\n * Designed so the loop, the persistor, the TUI, and any replay tool\n * all read from one source of truth and never mutate the DAG behind\n * each other's backs:\n *\n * - **Run loop** (`Agent`) calls `add()` on each new message and\n * `compact()` on overflow.\n * - **TUI** subscribes to the `node` event for streaming render.\n * - **Persistor** is the `SessionStore` — `MemoryStore` for ephemeral\n * sessions, `JsonlStore` for file-backed.\n *\n * Construction:\n * - Use `await Session.load(opts)` for the recommended path — picks\n * the right store (Memory if no path, JSONL if path).\n * - For tests / direct embedding, `new Session({ store })` works with\n * any pre-built store.\n */\nexport class Session<T extends SessionStore = SessionStore> extends Emitter<SessionEvents> {\n readonly #store: T\n #opts: SessionInit<T>\n #id: string\n #dir: string\n #settings: SessionSettings = {}\n #view: SessionView = { messages: [], nodes: new Map() }\n #closed = false\n #started = false\n #path?: string\n #head?: string\n\n protected constructor(opts: SessionInit<T>) {\n super()\n this.#opts = opts\n this.#path = opts.path\n this.#store = opts.store\n this.#id = opts.defaults?.sessionId ?? uuidv7()\n this.#dir = normPath(opts.dir ?? join(zalyPaths.env.tmp, \"sessions\", this.#id))\n }\n\n /** Recommended one-step path: pick the right store backend, hydrate\n * if applicable, return a ready-to-use session.\n *\n * - `path` provided → `JsonlStore` (file-backed, hydrates from disk\n * if the file exists, opens for append either way).\n * - No `path` → `MemoryStore` (ephemeral, no persistence). */\n static async load<T extends SessionStore = SessionStore>(\n opts: SessionOptions<T> & { store: T }\n ): Promise<Session<T>>\n static async load(opts: SessionOptions & { path: string }): Promise<Session<JsonlStore>>\n static async load(opts?: SessionOptions & {}): Promise<Session<MemoryStore>>\n static async load(opts: SessionOptions = {}): Promise<Session> {\n const session = await Session.create(opts)\n await session.#rebuild()\n return session\n }\n\n private static async create(opts: SessionOptions = {}): Promise<Session> {\n const path = opts.path ? normPath(opts.path) : undefined\n const store: SessionStore =\n opts.store ?? (path ? await JsonlStore.load(path) : new MemoryStore())\n const init: SessionInit = { ...opts, path, store }\n return new Session(init)\n }\n\n /** Efficiently fetch the most recent user message by walking backward until we hit\n * a user message, without reconstructing the full chain. Useful for a session picker. */\n static async lastMessage(opts: SessionOptions = {}): Promise<Message<\"user\"> | undefined> {\n const session = await Session.create(opts)\n let ret: Message<\"user\"> | undefined\n await session.#chain({\n stop: (node) => {\n if (node.type === \"message\" && node.message.role === \"user\") {\n ret = node.message\n return true\n }\n return false\n },\n })\n void session.close()\n return ret\n }\n\n async #rebuild(): Promise<void> {\n const chain = await this.#chain()\n this.#view = chain\n this.#settings = chain.settings\n this.#id = chain.settings.sessionId ?? this.#id\n }\n\n // ── Read ──────────────────────────────────────────────────────────────\n\n /** Active conversation — chain from current head back to the most\n * recent compact (exclusive), in chronological order. This is what\n * the agent sees on the next request. */\n get messages(): readonly Message[] {\n return this.#view.messages\n }\n\n get maskCheckpoint(): MaskCheckpoint | undefined {\n return this.#view.maskCheckpoint\n }\n\n get id(): string {\n return this.#id\n }\n\n get dir(): string {\n return this.#dir\n }\n\n get path(): string | undefined {\n return this.#path\n }\n\n get started(): boolean {\n return this.#started\n }\n\n /** Current session settings, merged with defaults. */\n get settings(): SessionSettings {\n return { ...this.#opts.defaults, ...this.#settings }\n }\n\n async update(settings: SessionUpdate, opts?: { force?: boolean }): Promise<string> {\n return this.#commit({ settings, type: \"session-settings\" }, opts)\n }\n\n /** Lazily emits `session-start` on a fresh session or `session-resume`\n * on a hydrated one. Called from `#commit` before the first non-marker\n * node lands so the start/resume marker always heads the chain. */\n async #autostart(): Promise<void> {\n if (!this.#started) await this.start()\n }\n\n /** Explicitly mark the session as started — writes a `session-start`\n * marker on a fresh session, `session-resume` on a hydrated one.\n * Idempotent; subsequent calls are no-ops. Optional `meta` is\n * applied via `update()` after the marker lands. */\n async start(settings?: SessionUpdate): Promise<string | undefined> {\n if (this.#started) return settings ? this.update(settings) : this.#store.root?.uuid\n this.#started = true\n const type = this.messages.length > 0 ? (\"session-resume\" as const) : (\"session-start\" as const)\n await this.#commit({ type })\n void this.emit(type)\n await this.update(settings ?? {})\n return this.#store.root?.uuid\n }\n\n /** Look up the decorated view for a node id — raw node plus the\n * cumulative meta as of that node's position. Returns the\n * message-typed view, or `undefined` if the id doesn't refer to a\n * message in this session. */\n async node(id?: string | Message): Promise<(SessionNodeView & { type: \"message\" }) | undefined> {\n const m = typeof id === \"string\" ? { id } : id\n if (!m?.id) return undefined\n const ret = this.#view.nodes.get(m.id)\n return ret?.type === \"message\" ? ret : undefined\n }\n\n /** Current head uuid — the root of the store, which is the most\n * recently appended node. */\n get head(): string | undefined {\n return this.#head ?? this.#store.root?.uuid\n }\n\n /** Full DAG iterator — backed by `store.all()`. Yields raw nodes\n * (no meta decoration). */\n nodes(): Iterable<SessionNode> | AsyncIterable<SessionNode> {\n return this.#store.all?.() ?? []\n }\n\n get root(): SessionNode | undefined {\n return this.#store.root\n }\n\n // ── Mutate ────────────────────────────────────────────────────────────\n\n /** Append a message. The new node is parented to the current head,\n * head advances, and a `node` event fires. Optional `meta` carries\n * usage / model / finish info — populate it for assistant turns\n * the agent commits after a step. Returns the assigned uuid.\n *\n * If `message.id` / `message.ts` are set (e.g. round-tripped from a\n * prior load), they're used as the node's uuid / timestamp; otherwise\n * fresh values are generated. The committed message always carries\n * both — `m.id === node.uuid` and `m.ts === node.ts`. */\n async add(message: Message): Promise<string> {\n const uuid = message.id ?? uuidv7()\n const ts = message.ts ?? Date.now()\n const m = { ...message, id: uuid, ts }\n return this.#commit({ message: m, type: \"message\" })\n }\n\n /** Mark a compaction boundary. Subsequent `add()` calls land after\n * this node; their messages form the new active conversation. The\n * pre-compact chain stays in the store but is no longer part of\n * `messages`. Also commits a fresh `session-meta` snapshot right\n * after the compact so post-compact lazy walks always have a nearby\n * meta anchor. */\n async compact(opts: {\n trigger?: \"manual\" | \"auto\"\n preTokens?: number\n durationMs?: number\n tail: number\n summary: Message<\"system\">\n }): Promise<string> {\n const node: SessionNode = {\n durationMs: opts.durationMs,\n parentUuid: this.#store.root?.uuid,\n preTokens: opts.preTokens,\n summary: opts.summary,\n tail: opts.tail,\n trigger: opts.trigger ?? \"manual\",\n ts: Date.now(),\n type: \"compact\",\n uuid: uuidv7(),\n }\n const compactUuid = await this.#commit(node)\n await this.update({}, { force: true })\n await this.#rebuild()\n void this.emit(\"compact\", { node })\n return compactUuid\n }\n\n async addMaskCheckpoint(opts: MaskCheckpoint): Promise<string> {\n this.#view.maskCheckpoint = opts\n return this.#commit({ ...opts, type: \"mask-checkpoint\" })\n }\n\n async checkout(uuid: string): Promise<void> {\n if (this.#closed) throw new Error(\"Session is closed\")\n this.#head = uuid\n await this.#rebuild()\n }\n\n /** Pre-active history of the current chain — messages from before\n * the most recent compact (and earlier compacts), in chronological\n * order. Useful for TUI scrollback that wants to render context the\n * agent itself no longer sees.\n *\n * `limit` truncates from the front (oldest), so the most recent\n * history messages always make it through. */\n async history(limit?: number): Promise<readonly Message[]> {\n const chain = await this.#chain({ active: false, limit })\n return chain.messages\n }\n\n /** Flush + close the underlying store. Subsequent writes throw. */\n async close(): Promise<void> {\n if (this.#closed) return\n this.#closed = true\n await this.#store.close?.()\n }\n\n // ── Internals ────────────────────────────────────────────────────────\n\n /** Atomically commit a node: register it in the store, update active\n * messages, persist, and emit. Single chokepoint for all mutations. */\n async #commit(n: PartialNode, opts: { force?: boolean } = {}): Promise<string> {\n let node: SessionNode = {\n ...n,\n parentUuid: this.head,\n ts: Date.now(),\n uuid: uuidv7(),\n }\n\n if (!this.#started && node.type !== \"session-start\" && node.type !== \"session-resume\") {\n await this.#autostart()\n }\n if (this.#closed) throw new Error(\"Session is closed\")\n\n const next: SessionSettings = {\n ...this.#opts.defaults,\n ...this.#settings,\n ...(node.type === \"session-settings\" ? node.settings : {}),\n sessionId: this.#id,\n version: VERSION,\n }\n if (next.cwd) next.cwd = normPath(next.cwd)\n if (next.workspace) next.workspace = normPath(next.workspace)\n\n if (node.type === \"session-settings\") {\n if (!opts.force && isDeepStrictEqual(this.#settings, next)) return this.#store.root!.uuid\n node = { ...node, settings: next }\n }\n\n node = { ...node, parentUuid: this.head }\n await this.#store.write(node)\n this.#head = undefined // invalidate head cache so it reflects the store's root on next read\n\n // Decorate the new node with cumulative meta and append to the\n // active chain view\n this.#view.nodes.set(node.uuid, { ...node, settings: next })\n if (node.type === \"message\") this.#view.messages.push(node.message)\n\n // cwd / meta event signaling\n if (node.type === \"session-settings\") {\n const prev = this.#settings\n this.#settings = next\n this.#emitChanges(prev)\n }\n\n void this.emit(\"node\", { node })\n return node.uuid\n }\n\n #emitChanges(prev: SessionSettings): void {\n const next = this.#settings\n if (next.cwd && next.cwd !== prev.cwd) void this.emit(\"cwd\", { cwd: next.cwd, prev: prev.cwd })\n if (next.modelId && next.modelId !== prev.modelId)\n void this.emit(\"model\", { model: next.modelId, prev: prev.modelId })\n if (next.reasoning && next.reasoning !== prev.reasoning)\n void this.emit(\"reasoning\", { effort: next.reasoning, prev: prev.reasoning })\n }\n\n /** Walk `parentUuid` from the given node back toward the root,\n * returning the chain as decorated views (each with cumulative meta).\n * The `active` flag controls what counts:\n * - `true` — only the active chain (stops at first compact /\n * session-start, with the kept tail spliced in via\n * the compact's `tail` field, summary substituted\n * in place of the compact node).\n * - `false` — includes everything back to the root\n * Returns chronological order. */\n async #chain(\n opts: {\n active?: boolean\n limit?: number\n uuid?: string\n stop?: (node: SessionNode) => boolean\n } = {}\n ): Promise<SessionView & { settings: SessionSettings }> {\n // Backward pass: collect raw nodes (new to old)\n const reverse: SessionNode[] = []\n let cursor = opts.uuid ?? this.head\n let limit = opts.limit ?? Infinity\n let compact: SessionNode<\"compact\"> | undefined\n const messageNodes: SessionNode<\"message\">[] = []\n let maskCheckpoint: SessionNode<\"mask-checkpoint\"> | undefined\n\n // Walk backward from the head until we hit a compact or the start, collecting nodes.\n while (cursor) {\n // eslint-disable-next-line no-await-in-loop\n const node = await this.#store.get(cursor)\n if (!node || (node.type === \"message\" && messageNodes.length + 1 > limit)) break\n cursor = node.parentUuid\n reverse.push(node)\n // Keep track if the last mask-checkpoint, until we hit a compaction.\n if (node.type === \"mask-checkpoint\" && !compact && !maskCheckpoint) maskCheckpoint = node\n if (node.type === \"message\") messageNodes.push(node)\n if (node.type === \"compact\" && (opts.active ?? true)) {\n if (compact) break // stop at the first compact\n compact = node\n // update limit to the compact's tail\n limit = Math.min(limit, messageNodes.length + node.tail)\n }\n if (opts.stop?.(node)) break\n }\n\n // Forward pass: decorate with cumulative meta. session-meta nodes\n // redefine the meta; everything else inherits the running snapshot.\n const nodes = new Map<string, SessionNodeView>()\n let settings: SessionSettings = {}\n for (const n of reverse.toReversed()) {\n if (n.type === \"session-settings\") settings = n.settings\n nodes.set(n.uuid, { ...n, settings })\n }\n\n this.#migrate(nodes)\n\n const messages: SessionMessage[] = []\n for (const n of messageNodes) {\n // add `id`, `ts` and `modelId` (if assistant turn) to the message\n const m = { ...n.message, id: n.uuid, ts: n.ts }\n if (m.role === \"assistant\") {\n // Add missing modelId to assistant messages if not present\n const s = nodes.get(n.uuid)?.settings ?? {}\n m.meta = { ...m.meta, modelId: m.meta?.modelId ?? s.modelId }\n }\n n.message = m\n messages.push(m)\n }\n\n // Add compaction summary as the first message\n if (compact) {\n messages.push({ ...compact.summary, id: compact.uuid, ts: compact.ts })\n nodes.set(compact.uuid, {\n message: compact.summary,\n parentUuid: compact.parentUuid,\n settings: nodes.get(compact.uuid)?.settings ?? {},\n ts: compact.ts,\n type: \"message\",\n uuid: compact.uuid,\n })\n }\n\n return {\n compact,\n maskCheckpoint,\n messages: messages.toReversed(),\n nodes,\n settings,\n }\n }\n\n #migrate(nodes: Map<string, SessionNodeView>) {\n for (const n of nodes.values()) {\n const version = n.settings.version ?? 0\n if (version === VERSION) continue\n n.settings = { ...n.settings, version: VERSION }\n\n if (n.type === \"compact\") {\n n.summary.meta = { kind: \"compaction-summary\", ...n.summary.meta }\n continue\n }\n\n if (n.type !== \"message\") continue\n const m = n.message\n\n if (\n m.role === \"system\" &&\n Array.isArray(m.content) &&\n m.content[0].type === \"meta\" &&\n m.content[0].tag === \"task\"\n ) {\n // Missing task meta data kind\n m.meta = { kind: \"task\", ...m.meta }\n }\n\n n.message = m\n }\n }\n}\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C;EAC5C,KAAK,MAAM,KAAK,MAAM,OAAO,GAAG;GAE9B,KADgB,EAAE,SAAS,WAAW,OACtB,SAAS;GACzB,EAAE,WAAW;IAAE,GAAG,EAAE;IAAU,SAAS;GAAQ;GAE/C,IAAI,EAAE,SAAS,WAAW;IACxB,EAAE,QAAQ,OAAO;KAAE,MAAM;KAAsB,GAAG,EAAE,QAAQ;IAAK;IACjE;GACF;GAEA,IAAI,EAAE,SAAS,WAAW;GAC1B,MAAM,IAAI,EAAE;GAEZ,IACE,EAAE,SAAS,YACX,MAAM,QAAQ,EAAE,OAAO,KACvB,EAAE,QAAQ,EAAE,CAAC,SAAS,UACtB,EAAE,QAAQ,EAAE,CAAC,QAAQ,QAGrB,EAAE,OAAO;IAAE,MAAM;IAAQ,GAAG,EAAE;GAAK;GAGrC,EAAE,UAAU;EACd;CACF;AACF"}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { Emitter } from "@zaly/shared";
|
|
2
2
|
import { Message, ReasoningEffort } from "@zaly/ai";
|
|
3
|
-
//#region src/session/types.d.ts
|
|
4
3
|
/** A single node in the session DAG. Same shape on disk (JSONL) as in
|
|
5
4
|
* memory — what we persist *is* what we navigate. Session settings live ONLY on
|
|
6
5
|
* `session-settings` nodes as a full snapshot of the cumulative session
|
|
@@ -128,8 +127,6 @@ type SessionInit<T extends SessionStore = SessionStore> = SessionOptions & {
|
|
|
128
127
|
* store based on options; direct construction passes one explicitly. */
|
|
129
128
|
store: T;
|
|
130
129
|
};
|
|
131
|
-
//#endregion
|
|
132
|
-
//#region src/session/store.d.ts
|
|
133
130
|
/**
|
|
134
131
|
* Storage backend for a `Session`'s DAG.
|
|
135
132
|
*
|
|
@@ -170,8 +167,6 @@ interface SessionStore {
|
|
|
170
167
|
* override with a more efficient bulk-scan implementation. */
|
|
171
168
|
all?: () => Iterable<SessionNode> | AsyncIterable<SessionNode>;
|
|
172
169
|
}
|
|
173
|
-
//#endregion
|
|
174
|
-
//#region src/session/jsonl.d.ts
|
|
175
170
|
/**
|
|
176
171
|
* JSONL-backed `SessionStore` — append-only file, one record per line.
|
|
177
172
|
*
|
|
@@ -206,8 +201,6 @@ declare class JsonlReader<T> {
|
|
|
206
201
|
next(): Promise<T | undefined>;
|
|
207
202
|
close(): Promise<void>;
|
|
208
203
|
}
|
|
209
|
-
//#endregion
|
|
210
|
-
//#region src/session/memory.d.ts
|
|
211
204
|
/**
|
|
212
205
|
* In-memory `SessionStore` — a `Map<uuid, SessionNode>` plus a `root`
|
|
213
206
|
* pointer. No persistence. Construction takes optional initial nodes
|
|
@@ -221,8 +214,6 @@ declare class MemoryStore implements SessionStore {
|
|
|
221
214
|
write(node: SessionNode): Promise<void>;
|
|
222
215
|
all(): Iterable<SessionNode>;
|
|
223
216
|
}
|
|
224
|
-
//#endregion
|
|
225
|
-
//#region src/session/session.d.ts
|
|
226
217
|
/**
|
|
227
218
|
* Conversation primitive. Owns a DAG of message + compaction + meta
|
|
228
219
|
* nodes via a `SessionStore` backend; the *active* message list is
|
|
@@ -341,6 +332,5 @@ declare class Session<T extends SessionStore = SessionStore> extends Emitter<Ses
|
|
|
341
332
|
/** Flush + close the underlying store. Subsequent writes throw. */
|
|
342
333
|
close(): Promise<void>;
|
|
343
334
|
}
|
|
344
|
-
//#endregion
|
|
345
335
|
export { SessionStore as a, SessionEvents as c, SessionNode as d, SessionNodeView as f, SessionView as g, SessionUpdate as h, JsonlStore as i, SessionInit as l, SessionSettings as m, MemoryStore as n, MaskCheckpoint as o, SessionOptions as p, JsonlReader as r, PartialNode as s, Session as t, SessionMessage as u };
|
|
346
|
-
//# sourceMappingURL=session-
|
|
336
|
+
//# sourceMappingURL=session-Cq52cam5.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session-Cq52cam5.d.mts","names":[],"sources":["../src/session/types.ts","../src/session/store.ts","../src/session/jsonl.ts","../src/session/memory.ts","../src/session/session.ts"],"mappings":";;;;;;;;;KAYK;EACH;;EAEA;;E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,SAAS;MAUzB,QAAQ;EAIN,IAAI,aAAa,QAAQ;EAIzB,MAAM,MAAM,cAAc;EAK/B,OAAO,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cCoBN,QAAQ,UAAU,eAAe,sBAAsB,QAAQ;;YAYjE,YAAa,MAAM,YAAY;;;;;;;SAe3B,KAAK,UAAU,eAAe,cACzC,MAAM,eAAe;IAAO,OAAO;MAClC,QAAQ,QAAQ;SACN,KAAK,MAAM;IAAmB;MAAiB,QAAQ,QAAQ;SAC/D,KAAK,OAAO,sBAAsB,QAAQ,QAAQ;iBAO1C;;;SAUR,YAAY,OAAM,iBAAsB,QAAQ;;;;MA4BzD,qBAAqB;MAIrB,kBAAkB;MAIlB;MAIA;MAIA;MAIA;;MAKA,YAAY;EAIV,OAAO,UAAU,eAAe;IAAS;MAAoB;;;;;EAe7D,MAAM,WAAW,gBAAgB;;;;;EAcjC,KAAK,cAAc,UAAU,SAAS;IAAoB;;;;MAS5D;;;EAMJ,SAAS,SAAS,eAAe,cAAc;MAI3C,QAAQ;;;;;;;;;;EAeN,IAAI,SAAS,UAAU;;;;;;;EAavB,QAAQ;IACZ;IACA;IACA;IACA;IACA,SAAS;MACP;EAmBE,kBAAkB,MAAM,iBAAiB;EAKzC,SAAS,eAAe;;;;;;;;EAaxB,QAAQ,iBAAiB,iBAAiB;;EAM1C,SAAS"}
|
package/dist/session.d.mts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { a as SessionStore, c as SessionEvents, d as SessionNode, f as SessionNodeView, g as SessionView, h as SessionUpdate, i as JsonlStore, l as SessionInit, m as SessionSettings, n as MemoryStore, o as MaskCheckpoint, p as SessionOptions, r as JsonlReader, s as PartialNode, t as Session, u as SessionMessage } from "./session-
|
|
1
|
+
import { a as SessionStore, c as SessionEvents, d as SessionNode, f as SessionNodeView, g as SessionView, h as SessionUpdate, i as JsonlStore, l as SessionInit, m as SessionSettings, n as MemoryStore, o as MaskCheckpoint, p as SessionOptions, r as JsonlReader, s as PartialNode, t as Session, u as SessionMessage } from "./session-Cq52cam5.mjs";
|
|
2
2
|
import { Stats } from "node:fs";
|
|
3
|
-
//#region src/session/manager.d.ts
|
|
4
3
|
export type SessionInfo = {
|
|
5
4
|
/** uuidv7 session id. Absent for non-managed external paths until the
|
|
6
5
|
* session is loaded — the file's session-start node carries the
|
|
@@ -32,6 +31,5 @@ export declare function listSessions(opts?: SessionListOpts): Promise<SessionInf
|
|
|
32
31
|
export declare function resumeSession(filter: string | SessionFilter): Promise<Session | undefined>;
|
|
33
32
|
export declare function loadSession(opts?: Partial<SessionInfo>): Promise<Session>;
|
|
34
33
|
export declare function sessionInfo(opts?: Partial<SessionInfo>): SessionInfo;
|
|
35
|
-
//#endregion
|
|
36
34
|
export { JsonlReader, JsonlStore, type MaskCheckpoint, MemoryStore, type PartialNode, Session, type SessionEvents, type SessionInit, type SessionMessage, type SessionNode, type SessionNodeView, type SessionOptions, type SessionSettings, type SessionStore, type SessionUpdate, type SessionView };
|
|
37
35
|
//# sourceMappingURL=session.d.mts.map
|
package/dist/session.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"session.d.mts","names":[],"sources":["../src/session/manager.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"session.d.mts","names":[],"sources":["../src/session/manager.ts"],"mappings":";;YAUY;;;;EAIV;;EAEA;;EAEA;;EAEA;;EAEA;EACA,OAAO;;YAGG;;EAEV;;EAEA;;EAEA;;YAGU;EACV,kBAAkB;EAClB;;wBAcoB,aAAa,OAAM,kBAAoB,QAAA;wBAyCvC,cAAc,iBAAiB,gBAAgB,QAAQ;wBAKvD,YAAY,OAAM,QAAQ,eAAoB,QAAQ;wBAc5D,YAAY,OAAM,QAAQ,eAAoB"}
|
package/dist/session.mjs
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { n as isUuidv7Like, r as uuidv7 } from "./uuid-
|
|
2
|
-
import { n as JsonlStore, t as JsonlReader } from "./jsonl-
|
|
3
|
-
import { r as MemoryStore, t as Session } from "./session-
|
|
1
|
+
import { n as isUuidv7Like, r as uuidv7 } from "./uuid-rfbQ9ad2.mjs";
|
|
2
|
+
import { n as JsonlStore, t as JsonlReader } from "./jsonl-BGt7eqPK.mjs";
|
|
3
|
+
import { r as MemoryStore, t as Session } from "./session-C8zqqbPE.mjs";
|
|
4
4
|
import { decodePath, encodePath, normPath, safeStatAsync } from "@zaly/shared";
|
|
5
5
|
import { basename, dirname, join, relative } from "pathe";
|
|
6
6
|
import { glob } from "@zaly/shared/glob";
|
|
7
7
|
import { mkdir, stat } from "node:fs/promises";
|
|
8
8
|
import { zalyPaths } from "@zaly/shared/paths";
|
|
9
|
-
|
|
9
|
+
// src/session/manager.ts
|
|
10
10
|
async function toFilter(filter) {
|
|
11
11
|
if (isUuidv7Like(filter)) return { id: filter };
|
|
12
12
|
if ((await safeStatAsync(filter))?.isDirectory()) return { workspace: filter };
|
|
@@ -100,7 +100,6 @@ function sessionInfo(opts = {}) {
|
|
|
100
100
|
workspace
|
|
101
101
|
};
|
|
102
102
|
}
|
|
103
|
-
//#endregion
|
|
104
103
|
export { JsonlReader, JsonlStore, MemoryStore, Session, listSessions, loadSession, resumeSession, sessionInfo };
|
|
105
104
|
|
|
106
105
|
//# sourceMappingURL=session.mjs.map
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import "./
|
|
1
|
+
import { n as __exportAll } from "./rolldown-runtime-DYf_mQCB.mjs";
|
|
2
|
+
import { n as parseBash, t as TOOLS } from "./tools-DmoUYORG.mjs";
|
|
3
|
+
import "./registry-CntkeXlo.mjs";
|
|
3
4
|
import { Emitter, formatDuration, isInstance, normPath, prettyPath, safeReadFile, safeStatAsync, safeStringify, toError } from "@zaly/shared";
|
|
4
5
|
import { LazyCache } from "@zaly/shared/cache";
|
|
5
6
|
import { BaseCollection } from "@zaly/shared/collection";
|
|
@@ -10,7 +11,7 @@ import { glob } from "@zaly/shared/glob";
|
|
|
10
11
|
import { readFile } from "node:fs/promises";
|
|
11
12
|
import { isDeepStrictEqual } from "node:util";
|
|
12
13
|
import { Type } from "typebox";
|
|
13
|
-
|
|
14
|
+
// src/ctx.ts
|
|
14
15
|
var ctx_exports = /* @__PURE__ */ __exportAll({
|
|
15
16
|
AgentContext: () => AgentContext,
|
|
16
17
|
createAgent: () => createAgent,
|
|
@@ -160,7 +161,7 @@ var AgentContext = class extends Emitter {
|
|
|
160
161
|
}
|
|
161
162
|
async swarm() {
|
|
162
163
|
return this.#cache.need("swarm", async () => {
|
|
163
|
-
const { Swarm } = await import("./swarm-
|
|
164
|
+
const { Swarm } = await import("./swarm-B_s9Qpbt.mjs");
|
|
164
165
|
return new Swarm();
|
|
165
166
|
}, this.#opts.swarm);
|
|
166
167
|
}
|
|
@@ -174,19 +175,19 @@ var AgentContext = class extends Emitter {
|
|
|
174
175
|
}
|
|
175
176
|
async notifier() {
|
|
176
177
|
return this.#cache.want("notifier", async (opts) => {
|
|
177
|
-
const { Notifier } = await import("./notify-
|
|
178
|
+
const { Notifier } = await import("./notify-Ds0-4BeI.mjs");
|
|
178
179
|
return new Notifier(opts);
|
|
179
180
|
}, this.#opts.notify);
|
|
180
181
|
}
|
|
181
182
|
async masker() {
|
|
182
183
|
return this.#cache.want("masker", async (opts) => {
|
|
183
|
-
const { Masker } = await import("./masker-
|
|
184
|
+
const { Masker } = await import("./masker-DEgR_ntk.mjs");
|
|
184
185
|
return new Masker(this.agent, opts);
|
|
185
186
|
}, this.#opts.mask);
|
|
186
187
|
}
|
|
187
188
|
async permissions() {
|
|
188
189
|
return this.#cache.need("permissions", async (opts) => {
|
|
189
|
-
const { PermissionManager } = await import("./manager-
|
|
190
|
+
const { PermissionManager } = await import("./manager-1zEE5WiA.mjs");
|
|
190
191
|
return new PermissionManager({
|
|
191
192
|
...opts,
|
|
192
193
|
cwd: this.cwd
|
|
@@ -197,7 +198,7 @@ var AgentContext = class extends Emitter {
|
|
|
197
198
|
async function loadSession(spec) {
|
|
198
199
|
if (isInstance(spec)) return spec;
|
|
199
200
|
else {
|
|
200
|
-
const { Session } = await import("./session-
|
|
201
|
+
const { Session } = await import("./session-C8zqqbPE.mjs").then((n) => n.n);
|
|
201
202
|
return await Session.load({ ...spec });
|
|
202
203
|
}
|
|
203
204
|
}
|
|
@@ -209,15 +210,15 @@ async function createAgentContext(opts) {
|
|
|
209
210
|
});
|
|
210
211
|
}
|
|
211
212
|
async function createAgent(opts) {
|
|
212
|
-
const [{ Agent }, ctx] = await Promise.all([import("./agent-
|
|
213
|
+
const [{ Agent }, ctx] = await Promise.all([import("./agent-BRENvuvx.mjs"), createAgentContext(opts)]);
|
|
213
214
|
return new Agent(ctx);
|
|
214
215
|
}
|
|
215
216
|
const promptRegistry = createRegistry("prompt").from({
|
|
216
|
-
"AGENTS.md": (ctx) => import("./markdown-
|
|
217
|
-
"MEMORY.md": (ctx) => import("./markdown-
|
|
218
|
-
agent: () => import("./agent-
|
|
219
|
-
env: (ctx) => import("./env-
|
|
220
|
-
model: (ctx) => import("./model-
|
|
217
|
+
"AGENTS.md": (ctx) => import("./markdown-8ICz5aFw.mjs").then((m) => m.agentsMdPrompt(ctx)),
|
|
218
|
+
"MEMORY.md": (ctx) => import("./markdown-8ICz5aFw.mjs").then((m) => m.memoryMdPrompt(ctx)),
|
|
219
|
+
agent: () => import("./agent-sHtwQDAk.mjs").then((m) => m.agentPrompt),
|
|
220
|
+
env: (ctx) => import("./env-C8p8i1E0.mjs").then((m) => m.prompt(ctx)),
|
|
221
|
+
model: (ctx) => import("./model-DqGqxfAc.mjs").then((m) => m.prompt(ctx))
|
|
221
222
|
});
|
|
222
223
|
var PromptCollection = class extends BaseCollection {
|
|
223
224
|
list() {
|
|
@@ -254,21 +255,21 @@ async function promptCollection() {
|
|
|
254
255
|
]);
|
|
255
256
|
}
|
|
256
257
|
const toolRegistry = createRegistry("tool").from({
|
|
257
|
-
agent_send: () => import("./swarm-
|
|
258
|
-
agent_spawn: () => import("./swarm-
|
|
259
|
-
bash: () => import("./bash-
|
|
260
|
-
edit: () => import("./edit-
|
|
261
|
-
fetch: () => import("./fetch-
|
|
262
|
-
find: () => import("./find-
|
|
263
|
-
grep: () => import("./grep-
|
|
264
|
-
read: () => import("./read-
|
|
265
|
-
search: () => import("./search-
|
|
266
|
-
subagent: () => import("./subagent-
|
|
267
|
-
task_list: () => import("./tasks-
|
|
268
|
-
task_poll: () => import("./tasks-
|
|
269
|
-
task_stop: () => import("./tasks-
|
|
270
|
-
wakeup: () => import("./wakeup-
|
|
271
|
-
write: () => import("./write-
|
|
258
|
+
agent_send: () => import("./swarm-D823Yumk.mjs").then((m) => m.agentSendTool),
|
|
259
|
+
agent_spawn: () => import("./swarm-D823Yumk.mjs").then((m) => m.agentSpawnTool),
|
|
260
|
+
bash: () => import("./bash-DSy03sAj.mjs").then((m) => m.bashTool),
|
|
261
|
+
edit: () => import("./edit-DT672zIy.mjs").then((m) => m.editTool),
|
|
262
|
+
fetch: () => import("./fetch-BrtIqrid.mjs").then((m) => m.fetchTool),
|
|
263
|
+
find: () => import("./find-B-vvdlHu.mjs").then((m) => m.findTool),
|
|
264
|
+
grep: () => import("./grep-rvZ5S319.mjs").then((m) => m.grepTool),
|
|
265
|
+
read: () => import("./read-C5keKntU.mjs").then((m) => m.readTool),
|
|
266
|
+
search: () => import("./search-B-89W3SM.mjs").then((m) => m.searchTool),
|
|
267
|
+
subagent: () => import("./subagent-BbcxLzgC.mjs").then((m) => m.subagentTool),
|
|
268
|
+
task_list: () => import("./tasks-Dgsiuh0Q.mjs").then((m) => m.taskListTool),
|
|
269
|
+
task_poll: () => import("./tasks-Dgsiuh0Q.mjs").then((m) => m.taskPollTool),
|
|
270
|
+
task_stop: () => import("./tasks-Dgsiuh0Q.mjs").then((m) => m.taskStopTool),
|
|
271
|
+
wakeup: () => import("./wakeup-CFr1nu_L.mjs").then((m) => m.wakeupTool),
|
|
272
|
+
write: () => import("./write-BRQFfWAn.mjs").then((m) => m.writeTool)
|
|
272
273
|
});
|
|
273
274
|
var ToolCollection = class extends BaseCollection {
|
|
274
275
|
list() {
|
|
@@ -284,8 +285,7 @@ var ToolCollection = class extends BaseCollection {
|
|
|
284
285
|
async function toolCollection() {
|
|
285
286
|
return new ToolCollection([]);
|
|
286
287
|
}
|
|
287
|
-
|
|
288
|
-
//#region src/commands.ts
|
|
288
|
+
// src/commands.ts
|
|
289
289
|
const BASH_RE = /^!`(.*)`$/;
|
|
290
290
|
var Commands = class {
|
|
291
291
|
#opts;
|
|
@@ -428,8 +428,7 @@ async function exec(script, opts = {}) {
|
|
|
428
428
|
md.push("");
|
|
429
429
|
return md.join("\n");
|
|
430
430
|
}
|
|
431
|
-
|
|
432
|
-
//#region src/skills.ts
|
|
431
|
+
// src/skills.ts
|
|
433
432
|
var Skills = class Skills {
|
|
434
433
|
catalog = /* @__PURE__ */ new Map();
|
|
435
434
|
#tool;
|
|
@@ -585,8 +584,7 @@ async function listReferences(dir) {
|
|
|
585
584
|
}
|
|
586
585
|
return out.toSorted();
|
|
587
586
|
}
|
|
588
|
-
|
|
589
|
-
//#region src/compaction/utils.ts
|
|
587
|
+
// src/compaction/utils.ts
|
|
590
588
|
const LAMBDA = Math.LN2 / 60;
|
|
591
589
|
const KIND_WEIGHTS = {
|
|
592
590
|
edit: 2,
|
|
@@ -791,8 +789,7 @@ function formatFileUsage(files) {
|
|
|
791
789
|
const text = lines.join("\n");
|
|
792
790
|
return toXml(text, "files", { indent: false });
|
|
793
791
|
}
|
|
794
|
-
|
|
795
|
-
//#region src/context/tokens.ts
|
|
792
|
+
// src/context/tokens.ts
|
|
796
793
|
const CHARS_PER_TOKEN = 4;
|
|
797
794
|
const ATTACHMENT_TOKENS = {
|
|
798
795
|
audio: 3e3,
|
|
@@ -947,7 +944,6 @@ function formatTokenStats(s, indent = 0) {
|
|
|
947
944
|
function fmt(n) {
|
|
948
945
|
return n.toLocaleString("en-US").replace(/,/g, "_");
|
|
949
946
|
}
|
|
950
|
-
//#endregion
|
|
951
947
|
export { ctx_exports as _, extractConversation as a, formatFileUsage as c, Commands as d, toolCollection as f, createAgent as g, promptRegistry as h, extractBashUsage as i, messageTail as l, promptCollection as m, formatTokenStats as n, extractFileUsage as o, toolRegistry as p, tokenStats as r, formatBashUsage as s, estimatePart as t, Skills as u };
|
|
952
948
|
|
|
953
|
-
//# sourceMappingURL=src-
|
|
949
|
+
//# sourceMappingURL=src-C04Qk9KE.mjs.map
|