@hexdecimal16/nexo 0.0.0-stage → 0.2.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/LICENSE +75 -0
- package/README.md +75 -2
- package/cli/src/bin.js +12 -0
- package/cli/src/common.js +77 -0
- package/cli/src/doctor.js +27 -0
- package/cli/src/eval-cases.js +65 -0
- package/cli/src/eval.js +67 -0
- package/cli/src/init.js +186 -0
- package/cli/src/interactive.js +171 -0
- package/cli/src/learn.js +178 -0
- package/cli/src/main.js +261 -0
- package/cli/src/optimize.js +289 -0
- package/cli/src/prompter.js +47 -0
- package/cli/src/review.js +120 -0
- package/cli/src/runtime.js +2 -0
- package/cli/src/sessions.js +34 -0
- package/cli/src/settings.js +169 -0
- package/cli/src/ui.js +112 -0
- package/core/src/approval/classifier.js +152 -0
- package/core/src/config/load.js +283 -0
- package/core/src/config/schema.js +186 -0
- package/core/src/cost/admission.js +90 -0
- package/core/src/cost/budget.js +67 -0
- package/core/src/cost/pricing.js +53 -0
- package/core/src/engine/charged-completion.js +79 -0
- package/core/src/engine/errors.js +77 -0
- package/core/src/engine/mcp.js +11 -0
- package/core/src/engine/messages.js +86 -0
- package/core/src/engine/prompts.js +32 -0
- package/core/src/engine/provider-gate.js +33 -0
- package/core/src/engine/recorder.js +61 -0
- package/core/src/engine/run.js +1115 -0
- package/core/src/engine/semaphore.js +45 -0
- package/core/src/engine/spawn-tool.js +119 -0
- package/core/src/engine/task-graph.js +153 -0
- package/core/src/index.js +32 -0
- package/core/src/learn/caller.js +171 -0
- package/core/src/learn/context.js +112 -0
- package/core/src/learn/embedder.js +216 -0
- package/core/src/learn/job.js +196 -0
- package/core/src/learn/wiki.js +116 -0
- package/core/src/learn/worker.js +141 -0
- package/core/src/optimize/adapter.js +250 -0
- package/core/src/optimize/climb.js +338 -0
- package/core/src/optimize/mine.js +95 -0
- package/core/src/optimize/optimize.js +377 -0
- package/core/src/optimize/optimizer-run.js +67 -0
- package/core/src/optimize/reflect.js +100 -0
- package/core/src/optimize/scratchpad-wiki.js +69 -0
- package/core/src/providers/claude-p.js +363 -0
- package/core/src/providers/kiro-p.js +408 -0
- package/core/src/providers/models.js +10 -0
- package/core/src/scoring/calibration.js +31 -0
- package/core/src/scoring/continuation.js +24 -0
- package/core/src/scoring/runner.js +322 -0
- package/core/src/scoring/sources.js +88 -0
- package/core/src/session/lock.js +88 -0
- package/core/src/session/session.js +647 -0
- package/core/src/session/shell.js +26 -0
- package/core/src/session/transcript.js +86 -0
- package/core/src/settings/config-edit.js +472 -0
- package/core/src/settings/credentials.js +120 -0
- package/core/src/settings/doctor.js +103 -0
- package/core/src/settings/settings.js +265 -0
- package/mcp/src/hub.js +184 -0
- package/mcp/src/index.js +1 -0
- package/memory/src/curate.js +121 -0
- package/memory/src/index.js +4 -0
- package/memory/src/prompts.js +143 -0
- package/memory/src/retrieval.js +91 -0
- package/memory/src/similarity.js +47 -0
- package/optimize/src/engine.js +206 -0
- package/optimize/src/index.js +8 -0
- package/optimize/src/merge.js +73 -0
- package/optimize/src/novelty.js +37 -0
- package/optimize/src/pareto.js +83 -0
- package/optimize/src/proposer.js +148 -0
- package/optimize/src/report.js +107 -0
- package/optimize/src/rng.js +34 -0
- package/optimize/src/target.js +34 -0
- package/package.json +47 -4
- package/router/src/effort.js +5 -0
- package/router/src/escalation.js +171 -0
- package/router/src/index.js +4 -0
- package/router/src/registry.js +21 -0
- package/router/src/resolve.js +117 -0
- package/scorers/src/deterministic.js +194 -0
- package/scorers/src/family.js +48 -0
- package/scorers/src/index.js +6 -0
- package/scorers/src/judge.js +284 -0
- package/scorers/src/regex-worker.js +3 -0
- package/scorers/src/spec.js +147 -0
- package/scorers/src/trajectory.js +22 -0
- package/scorers/src/types.js +1 -0
- package/sdk/src/index.js +3 -0
- package/sdk/src/nexo.js +94 -0
- package/sdk/src/runtime.js +39 -0
- package/skills/bundled/browser/SKILL.md +57 -0
- package/skills/bundled/wiki/SKILL.md +73 -0
- package/skills/src/frontmatter.js +25 -0
- package/skills/src/index.js +3 -0
- package/skills/src/load-skill-tool.js +41 -0
- package/skills/src/loader.js +95 -0
- package/store/src/artifacts.js +124 -0
- package/store/src/budget-ledger.js +18 -0
- package/store/src/cost-report.js +46 -0
- package/store/src/cursor.js +35 -0
- package/store/src/db.js +83 -0
- package/store/src/errors.js +9 -0
- package/store/src/eval-cases.js +255 -0
- package/store/src/feedback.js +154 -0
- package/store/src/goldens.js +61 -0
- package/store/src/ids.js +6 -0
- package/store/src/index.js +25 -0
- package/store/src/judge-calibration.js +182 -0
- package/store/src/learn-jobs.js +145 -0
- package/store/src/memories.js +261 -0
- package/store/src/migrations/001_init.sql +81 -0
- package/store/src/migrations/002_feedback.sql +9 -0
- package/store/src/migrations/003_sessions.sql +19 -0
- package/store/src/migrations/004_scoring.sql +22 -0
- package/store/src/migrations/005_judge_calibration.sql +27 -0
- package/store/src/migrations/006_learning.sql +77 -0
- package/store/src/migrations/007_optimize.sql +55 -0
- package/store/src/migrations/008_mined_cases_and_climb.sql +46 -0
- package/store/src/mine.js +51 -0
- package/store/src/optim.js +291 -0
- package/store/src/paths.js +22 -0
- package/store/src/playbooks.js +199 -0
- package/store/src/reindex.js +143 -0
- package/store/src/run-dir.js +151 -0
- package/store/src/runs.js +310 -0
- package/store/src/scores.js +92 -0
- package/store/src/sessions.js +304 -0
- package/store/src/span-tree.js +98 -0
- package/store/src/spans.js +84 -0
- package/store/src/sql.js +13 -0
- package/store/src/workspace-copy.js +80 -0
- package/telemetry/src/errors.js +32 -0
- package/telemetry/src/index.js +3 -0
- package/telemetry/src/logger.js +39 -0
- package/telemetry/src/redact.js +106 -0
- package/tools/src/builtin.js +269 -0
- package/tools/src/change-tracker.js +57 -0
- package/tools/src/confine.js +101 -0
- package/tools/src/index.js +7 -0
- package/tools/src/leases.js +57 -0
- package/tools/src/policy.js +162 -0
- package/tools/src/read-only.js +338 -0
- package/tools/src/session-rules.js +140 -0
- package/tui/src/app.js +948 -0
- package/tui/src/approvals.js +96 -0
- package/tui/src/commands.js +38 -0
- package/tui/src/components.js +248 -0
- package/tui/src/index.js +5 -0
- package/tui/src/picker.js +78 -0
- package/tui/src/session-picker.js +100 -0
- package/tui/src/settings-screen.js +346 -0
- package/tui/src/text.js +70 -0
- package/tui/src/theme.js +44 -0
- package/web/public/cost.html +25 -0
- package/web/public/fonts/GeistMono-400.woff2 +0 -0
- package/web/public/fonts/GeistMono-600.woff2 +0 -0
- package/web/public/fonts/InstrumentSans-400.woff2 +0 -0
- package/web/public/fonts/InstrumentSans-600.woff2 +0 -0
- package/web/public/index.html +39 -0
- package/web/public/judge.html +21 -0
- package/web/public/learning.html +46 -0
- package/web/public/lib/api-types.ts +616 -0
- package/web/public/lib/common-view.ts +47 -0
- package/web/public/lib/cost-view.ts +35 -0
- package/web/public/lib/files-view.ts +90 -0
- package/web/public/lib/format.ts +35 -0
- package/web/public/lib/html.ts +51 -0
- package/web/public/lib/judge-view.ts +62 -0
- package/web/public/lib/learning-view.ts +102 -0
- package/web/public/lib/optim-view.ts +148 -0
- package/web/public/lib/pager.ts +56 -0
- package/web/public/lib/poller.ts +79 -0
- package/web/public/lib/run-view.ts +61 -0
- package/web/public/lib/runs-view.ts +87 -0
- package/web/public/lib/score-view.ts +94 -0
- package/web/public/lib/sessions-view.ts +28 -0
- package/web/public/lib/span-view.ts +90 -0
- package/web/public/lib/theme.ts +60 -0
- package/web/public/lib/timeline.ts +97 -0
- package/web/public/lib/wikis-view.ts +257 -0
- package/web/public/optim.html +30 -0
- package/web/public/pages/api.ts +60 -0
- package/web/public/pages/cost.ts +36 -0
- package/web/public/pages/judge.ts +15 -0
- package/web/public/pages/learning.ts +92 -0
- package/web/public/pages/optim.ts +68 -0
- package/web/public/pages/paging.ts +18 -0
- package/web/public/pages/run.ts +221 -0
- package/web/public/pages/runs.ts +91 -0
- package/web/public/pages/sessions.ts +25 -0
- package/web/public/pages/wikis.ts +103 -0
- package/web/public/run.html +36 -0
- package/web/public/sessions.html +28 -0
- package/web/public/style.css +288 -0
- package/web/public/wikis.html +25 -0
- package/web/src/api.js +682 -0
- package/web/src/http-errors.js +60 -0
- package/web/src/index.js +5 -0
- package/web/src/server.js +292 -0
- package/web/src/static.js +86 -0
- package/web/src/strip.js +22 -0
|
@@ -0,0 +1,304 @@
|
|
|
1
|
+
import { appendFileSync, closeSync, existsSync, mkdirSync, openSync, readFileSync, readSync, renameSync, rmSync, statSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { NexoError } from "../../telemetry/src/index.js";
|
|
4
|
+
import { checkLimit, checkOffset, decodeCursor, pageOf } from "./cursor.js";
|
|
5
|
+
import { insertRow } from "./sql.js";
|
|
6
|
+
const COLUMNS = {
|
|
7
|
+
id: "id",
|
|
8
|
+
title: "title",
|
|
9
|
+
cwd: "cwd",
|
|
10
|
+
status: "status",
|
|
11
|
+
budgetUsd: "budget_usd",
|
|
12
|
+
costUsd: "cost_usd",
|
|
13
|
+
turns: "turns",
|
|
14
|
+
createdAt: "created_at",
|
|
15
|
+
updatedAt: "updated_at",
|
|
16
|
+
dirPath: "dir_path",
|
|
17
|
+
};
|
|
18
|
+
function encode(_key, value) {
|
|
19
|
+
return (value ?? null);
|
|
20
|
+
}
|
|
21
|
+
function decode(row) {
|
|
22
|
+
return {
|
|
23
|
+
id: String(row.id),
|
|
24
|
+
title: String(row.title),
|
|
25
|
+
cwd: String(row.cwd),
|
|
26
|
+
status: row.status,
|
|
27
|
+
budgetUsd: Number(row.budget_usd),
|
|
28
|
+
costUsd: Number(row.cost_usd),
|
|
29
|
+
turns: Number(row.turns),
|
|
30
|
+
createdAt: String(row.created_at),
|
|
31
|
+
updatedAt: String(row.updated_at),
|
|
32
|
+
dirPath: String(row.dir_path),
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
export function sessionRowFromJson(json, dirPath) {
|
|
36
|
+
return {
|
|
37
|
+
id: json.id,
|
|
38
|
+
title: json.title,
|
|
39
|
+
cwd: json.cwd,
|
|
40
|
+
status: json.status,
|
|
41
|
+
budgetUsd: json.budgetUsd,
|
|
42
|
+
costUsd: json.costUsd,
|
|
43
|
+
turns: json.turns,
|
|
44
|
+
createdAt: json.createdAt,
|
|
45
|
+
updatedAt: json.updatedAt,
|
|
46
|
+
dirPath,
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
/** Inserts or replaces a `sessions` row. */
|
|
50
|
+
export function upsertSessionRow(db, row) {
|
|
51
|
+
insertRow(db, "sessions", COLUMNS, { ...row }, encode, true);
|
|
52
|
+
}
|
|
53
|
+
export function getSessionRow(db, id) {
|
|
54
|
+
const row = db.prepare("SELECT * FROM sessions WHERE id = ?").get(id);
|
|
55
|
+
return row ? decode(row) : undefined;
|
|
56
|
+
}
|
|
57
|
+
/** Sessions, most recently updated first; `withTurns` leaves out sessions that never ran a turn (no recorded turn and no linked run). */
|
|
58
|
+
export function listSessionRows(db, options = {}) {
|
|
59
|
+
const where = options.withTurns ? "WHERE turns > 0 OR EXISTS (SELECT 1 FROM runs WHERE runs.session_id = sessions.id) " : "";
|
|
60
|
+
return db
|
|
61
|
+
.prepare(`SELECT * FROM sessions ${where}ORDER BY updated_at DESC, id DESC LIMIT ?`)
|
|
62
|
+
.all(options.limit ?? 20)
|
|
63
|
+
.map(decode);
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Sessions that ran a turn (as `listSessionRows({ withTurns: true })`), most recently updated first, with each one's latest turn and its count of unreviewed turns. Only root runs
|
|
67
|
+
* count as turns, and optimization runs never do.
|
|
68
|
+
*/
|
|
69
|
+
export function listSessionSummaries(db, options = {}) {
|
|
70
|
+
return querySessionSummaries(db, options).sessions;
|
|
71
|
+
}
|
|
72
|
+
/** One page of `listSessionSummaries`, newest update first; `cursor` (from a previous page) continues after its last session. */
|
|
73
|
+
export function querySessionSummaries(db, options = {}) {
|
|
74
|
+
const limit = checkLimit(options.limit ?? 50, 200);
|
|
75
|
+
const offset = checkOffset(options.offset);
|
|
76
|
+
const after = options.cursor === undefined ? null : decodeCursor(options.cursor);
|
|
77
|
+
const total = Number(db.prepare("SELECT COUNT(*) AS n FROM sessions s WHERE s.turns > 0 OR EXISTS (SELECT 1 FROM runs WHERE runs.session_id = s.id)").get().n);
|
|
78
|
+
const rows = db
|
|
79
|
+
.prepare(`WITH turns AS (
|
|
80
|
+
SELECT t.session_id, t.id, t.status, t.started_at,
|
|
81
|
+
ROW_NUMBER() OVER (PARTITION BY t.session_id ORDER BY t.turn_index DESC, t.started_at DESC, t.id DESC) AS recency,
|
|
82
|
+
(t.status != 'running' AND NOT EXISTS (SELECT 1 FROM feedback f WHERE f.run_id = t.id)) AS is_unreviewed
|
|
83
|
+
FROM runs t WHERE t.session_id IS NOT NULL AND t.parent_run_id IS NULL AND t.optim_run_id IS NULL
|
|
84
|
+
)
|
|
85
|
+
SELECT s.*, last.id AS last_id, last.status AS last_status, last.started_at AS last_started_at,
|
|
86
|
+
(SELECT COUNT(*) FROM turns u WHERE u.session_id = s.id AND u.is_unreviewed) AS unreviewed
|
|
87
|
+
FROM sessions s LEFT JOIN turns last ON last.session_id = s.id AND last.recency = 1
|
|
88
|
+
WHERE (s.turns > 0 OR EXISTS (SELECT 1 FROM runs WHERE runs.session_id = s.id))${after ? " AND (s.updated_at < ? OR (s.updated_at = ? AND s.id < ?))" : ""}
|
|
89
|
+
ORDER BY s.updated_at DESC, s.id DESC LIMIT ? OFFSET ?`)
|
|
90
|
+
.all(...(after ? [after.key, after.key, after.id] : []), limit + 1, offset);
|
|
91
|
+
const summaries = rows.map((row) => {
|
|
92
|
+
const session = decode(row);
|
|
93
|
+
return {
|
|
94
|
+
id: session.id,
|
|
95
|
+
title: session.title,
|
|
96
|
+
status: session.status,
|
|
97
|
+
turns: session.turns,
|
|
98
|
+
costUsd: session.costUsd,
|
|
99
|
+
budgetUsd: session.budgetUsd,
|
|
100
|
+
createdAt: session.createdAt,
|
|
101
|
+
updatedAt: session.updatedAt,
|
|
102
|
+
lastTurn: row.last_id === null ? null : { runId: String(row.last_id), status: row.last_status, startedAt: String(row.last_started_at) },
|
|
103
|
+
unreviewedTurns: Number(row.unreviewed),
|
|
104
|
+
};
|
|
105
|
+
});
|
|
106
|
+
const { items, nextCursor } = pageOf(summaries, limit, (s) => ({ key: s.updatedAt, id: s.id }));
|
|
107
|
+
return { sessions: items, nextCursor, total };
|
|
108
|
+
}
|
|
109
|
+
export function deleteSessionRow(db, id) {
|
|
110
|
+
db.prepare("DELETE FROM sessions WHERE id = ?").run(id);
|
|
111
|
+
}
|
|
112
|
+
/** Highest `turn_index` among the session's indexed runs; 0 when it has none. */
|
|
113
|
+
export function maxSessionTurn(db, sessionId) {
|
|
114
|
+
const row = db.prepare("SELECT MAX(turn_index) AS t FROM runs WHERE session_id = ?").get(sessionId);
|
|
115
|
+
return row?.t === null || row?.t === undefined ? 0 : Number(row.t);
|
|
116
|
+
}
|
|
117
|
+
/** The latest indexed run of a session (highest turn index), or undefined. */
|
|
118
|
+
export function latestSessionRunId(db, sessionId) {
|
|
119
|
+
const row = db.prepare("SELECT id FROM runs WHERE session_id = ? ORDER BY turn_index DESC, id DESC LIMIT 1").get(sessionId);
|
|
120
|
+
return row ? String(row.id) : undefined;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* The newest indexed turn run of the session whose run folder still has its `workspace/` folder (the files a run-folder
|
|
124
|
+
* session carries into its next turn), or undefined.
|
|
125
|
+
*/
|
|
126
|
+
export function latestSessionRunWorkspace(db, sessionId) {
|
|
127
|
+
const rows = db.prepare("SELECT id, dir_path FROM runs WHERE session_id = ? ORDER BY turn_index DESC, id DESC").all(sessionId);
|
|
128
|
+
for (const row of rows) {
|
|
129
|
+
const dir = join(String(row.dir_path), "workspace");
|
|
130
|
+
if (existsSync(dir))
|
|
131
|
+
return { runId: String(row.id), dir };
|
|
132
|
+
}
|
|
133
|
+
return undefined;
|
|
134
|
+
}
|
|
135
|
+
/** Directories of the session's indexed turn runs, newest turn first. */
|
|
136
|
+
export function sessionRunDirs(db, sessionId) {
|
|
137
|
+
return db
|
|
138
|
+
.prepare("SELECT dir_path FROM runs WHERE session_id = ? ORDER BY turn_index DESC, id DESC")
|
|
139
|
+
.all(sessionId)
|
|
140
|
+
.map((row) => String(row.dir_path));
|
|
141
|
+
}
|
|
142
|
+
/** Keys whose values are opaque provider data (signatures, response handles) that must round-trip unchanged. */
|
|
143
|
+
const OPAQUE_KEYS = new Set(["thinkingSignature", "textSignature", "thoughtSignature", "responseId", "deferred"]);
|
|
144
|
+
const OPAQUE_MARK = "\u0000nexo-opaque:";
|
|
145
|
+
/**
|
|
146
|
+
* Redacts `value` like `redact`, except that opaque provider fields (signatures, response ids, deferred handles and
|
|
147
|
+
* image data) are kept byte for byte: altering them would make the provider reject the replayed message.
|
|
148
|
+
*/
|
|
149
|
+
export function redactPreservingOpaque(redact, value) {
|
|
150
|
+
const saved = [];
|
|
151
|
+
const strip = (v) => {
|
|
152
|
+
if (Array.isArray(v))
|
|
153
|
+
return v.map(strip);
|
|
154
|
+
if (v === null || typeof v !== "object")
|
|
155
|
+
return v;
|
|
156
|
+
const obj = v;
|
|
157
|
+
const out = {};
|
|
158
|
+
for (const [key, item] of Object.entries(obj)) {
|
|
159
|
+
const opaque = OPAQUE_KEYS.has(key) || (key === "data" && obj.type === "image");
|
|
160
|
+
if (opaque && item !== undefined) {
|
|
161
|
+
saved.push(item);
|
|
162
|
+
out[key] = `${OPAQUE_MARK}${saved.length - 1}`;
|
|
163
|
+
}
|
|
164
|
+
else {
|
|
165
|
+
out[key] = strip(item);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
return out;
|
|
169
|
+
};
|
|
170
|
+
const restore = (v) => {
|
|
171
|
+
if (typeof v === "string" && v.startsWith(OPAQUE_MARK))
|
|
172
|
+
return saved[Number(v.slice(OPAQUE_MARK.length))];
|
|
173
|
+
if (Array.isArray(v))
|
|
174
|
+
return v.map(restore);
|
|
175
|
+
if (v === null || typeof v !== "object")
|
|
176
|
+
return v;
|
|
177
|
+
const out = {};
|
|
178
|
+
for (const [key, item] of Object.entries(v))
|
|
179
|
+
out[key] = restore(item);
|
|
180
|
+
return out;
|
|
181
|
+
};
|
|
182
|
+
return restore(redact(strip(value)));
|
|
183
|
+
}
|
|
184
|
+
export function sessionNotFound(id) {
|
|
185
|
+
return new NexoError({
|
|
186
|
+
code: "NOT_FOUND",
|
|
187
|
+
message: `Session ${id} does not exist`,
|
|
188
|
+
hint: "List sessions with `nexo sessions`",
|
|
189
|
+
context: { sessionId: id },
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
/** One session's directory (`~/.nexo/sessions/{id}`). Every write is redacted. */
|
|
193
|
+
export class SessionDir {
|
|
194
|
+
id;
|
|
195
|
+
root;
|
|
196
|
+
redact;
|
|
197
|
+
constructor(root, id, redact) {
|
|
198
|
+
this.root = root;
|
|
199
|
+
this.id = id;
|
|
200
|
+
this.redact = redact;
|
|
201
|
+
}
|
|
202
|
+
static create(sessionsRoot, id, redact) {
|
|
203
|
+
const dir = new SessionDir(join(sessionsRoot, id), id, redact);
|
|
204
|
+
try {
|
|
205
|
+
mkdirSync(dir.root, { recursive: true });
|
|
206
|
+
}
|
|
207
|
+
catch (cause) {
|
|
208
|
+
throw new NexoError({ code: "STORE_IO", message: `Cannot create session directory ${dir.root}`, cause });
|
|
209
|
+
}
|
|
210
|
+
return dir;
|
|
211
|
+
}
|
|
212
|
+
/** Deletes the directory and everything in it. */
|
|
213
|
+
remove() {
|
|
214
|
+
try {
|
|
215
|
+
rmSync(this.root, { recursive: true, force: true });
|
|
216
|
+
}
|
|
217
|
+
catch (cause) {
|
|
218
|
+
throw new NexoError({ code: "STORE_IO", message: `Cannot remove session directory ${this.root}`, cause });
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
/** An existing session's directory; NOT_FOUND when it has no session.json. */
|
|
222
|
+
static open(sessionsRoot, id, redact) {
|
|
223
|
+
const dir = new SessionDir(join(sessionsRoot, id), id, redact);
|
|
224
|
+
if (!/^[A-Za-z0-9_-]+$/.test(id) || !existsSync(dir.sessionFile))
|
|
225
|
+
throw sessionNotFound(id);
|
|
226
|
+
return dir;
|
|
227
|
+
}
|
|
228
|
+
get sessionFile() {
|
|
229
|
+
return join(this.root, "session.json");
|
|
230
|
+
}
|
|
231
|
+
get transcriptFile() {
|
|
232
|
+
return join(this.root, "transcript.jsonl");
|
|
233
|
+
}
|
|
234
|
+
writeSessionJson(json) {
|
|
235
|
+
const tmp = `${this.sessionFile}.tmp`;
|
|
236
|
+
try {
|
|
237
|
+
writeFileSync(tmp, `${JSON.stringify(this.redact(json), null, 2)}\n`);
|
|
238
|
+
renameSync(tmp, this.sessionFile);
|
|
239
|
+
}
|
|
240
|
+
catch (cause) {
|
|
241
|
+
throw new NexoError({ code: "STORE_IO", message: `Cannot write ${this.sessionFile}`, retryable: true, cause });
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
readSessionJson() {
|
|
245
|
+
try {
|
|
246
|
+
return JSON.parse(readFileSync(this.sessionFile, "utf8"));
|
|
247
|
+
}
|
|
248
|
+
catch (cause) {
|
|
249
|
+
throw new NexoError({
|
|
250
|
+
code: "STORE_IO",
|
|
251
|
+
message: `Cannot read ${this.sessionFile}`,
|
|
252
|
+
hint: "The session file is missing or not valid JSON",
|
|
253
|
+
cause,
|
|
254
|
+
});
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
appendTranscript(lines) {
|
|
258
|
+
if (lines.length === 0)
|
|
259
|
+
return;
|
|
260
|
+
try {
|
|
261
|
+
const body = lines.map((line) => `${JSON.stringify(redactPreservingOpaque(this.redact, line))}\n`).join("");
|
|
262
|
+
appendFileSync(this.transcriptFile, this.endsMidLine() ? `\n${body}` : body);
|
|
263
|
+
}
|
|
264
|
+
catch (cause) {
|
|
265
|
+
throw new NexoError({ code: "STORE_IO", message: `Cannot append to ${this.transcriptFile}`, retryable: true, cause });
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
/** True when the transcript is non-empty and its last byte is not a newline (a crash cut the last line short). */
|
|
269
|
+
endsMidLine() {
|
|
270
|
+
if (!existsSync(this.transcriptFile))
|
|
271
|
+
return false;
|
|
272
|
+
const size = statSync(this.transcriptFile).size;
|
|
273
|
+
if (size === 0)
|
|
274
|
+
return false;
|
|
275
|
+
const fd = openSync(this.transcriptFile, "r");
|
|
276
|
+
try {
|
|
277
|
+
const last = Buffer.alloc(1);
|
|
278
|
+
readSync(fd, last, 0, 1, size - 1);
|
|
279
|
+
return last[0] !== 0x0a;
|
|
280
|
+
}
|
|
281
|
+
finally {
|
|
282
|
+
closeSync(fd);
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
/** Transcript lines in file order, skipping unparsable lines (such as a truncated last line). */
|
|
286
|
+
readTranscript() {
|
|
287
|
+
if (!existsSync(this.transcriptFile))
|
|
288
|
+
return [];
|
|
289
|
+
const lines = [];
|
|
290
|
+
for (const text of readFileSync(this.transcriptFile, "utf8").split("\n")) {
|
|
291
|
+
if (!text.trim())
|
|
292
|
+
continue;
|
|
293
|
+
try {
|
|
294
|
+
const line = JSON.parse(text);
|
|
295
|
+
if (line && (line.type === "message" || line.type === "compaction") && typeof line.turnIndex === "number")
|
|
296
|
+
lines.push(line);
|
|
297
|
+
}
|
|
298
|
+
catch {
|
|
299
|
+
continue;
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
return lines;
|
|
303
|
+
}
|
|
304
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { descendantRunIds } from "./runs.js";
|
|
2
|
+
import { listSpansForRuns } from "./spans.js";
|
|
3
|
+
/** Largest span tree returned in one response; deeper history is reported as `truncated`. */
|
|
4
|
+
export const MAX_TREE_SPANS = 5000;
|
|
5
|
+
/** Longest string kept in a tree node's attrs; the full span is available by id. */
|
|
6
|
+
export const ATTR_PREVIEW_CHARS = 4000;
|
|
7
|
+
/** Deep copy of `value` with every string longer than `max` cut to `max` characters plus a marker. */
|
|
8
|
+
export function trimAttrs(value, max) {
|
|
9
|
+
let truncated = false;
|
|
10
|
+
const walk = (v, depth) => {
|
|
11
|
+
if (typeof v === "string") {
|
|
12
|
+
if (v.length <= max)
|
|
13
|
+
return v;
|
|
14
|
+
truncated = true;
|
|
15
|
+
return `${v.slice(0, max)}… [${v.length - max} more characters]`;
|
|
16
|
+
}
|
|
17
|
+
if (v === null || typeof v !== "object")
|
|
18
|
+
return v;
|
|
19
|
+
if (depth > 32) {
|
|
20
|
+
truncated = true;
|
|
21
|
+
return "[nested too deeply]";
|
|
22
|
+
}
|
|
23
|
+
if (Array.isArray(v))
|
|
24
|
+
return v.map((item) => walk(item, depth + 1));
|
|
25
|
+
const out = {};
|
|
26
|
+
for (const [key, item] of Object.entries(v))
|
|
27
|
+
out[key] = walk(item, depth + 1);
|
|
28
|
+
return out;
|
|
29
|
+
};
|
|
30
|
+
return { value: walk(value, 0), truncated };
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Nests spans by `parentSpanId`. A child run's root `run` span has no parentSpanId; it hangs under the parent run's
|
|
34
|
+
* `subagent` span named in its `attrs.parentSpanId`, or under the subagent span whose `attrs.trajectoryId` is that
|
|
35
|
+
* child run. Spans whose parent is absent (outside the list or truncated away) become roots; a corrupt parent cycle
|
|
36
|
+
* is broken by making its first member a root.
|
|
37
|
+
*/
|
|
38
|
+
export function buildSpanTree(spans, previewChars = ATTR_PREVIEW_CHARS) {
|
|
39
|
+
const nodes = new Map();
|
|
40
|
+
const subagentByRun = new Map();
|
|
41
|
+
for (const span of spans) {
|
|
42
|
+
const trimmed = trimAttrs(span.attrs, previewChars);
|
|
43
|
+
nodes.set(span.id, { span: { ...span, attrs: trimmed.value }, attrsTruncated: trimmed.truncated, children: [] });
|
|
44
|
+
const child = span.attrs.trajectoryId;
|
|
45
|
+
if (span.kind === "subagent" && typeof child === "string")
|
|
46
|
+
subagentByRun.set(child, span.id);
|
|
47
|
+
}
|
|
48
|
+
const parentOf = (span) => {
|
|
49
|
+
if (span.parentSpanId && nodes.has(span.parentSpanId))
|
|
50
|
+
return span.parentSpanId;
|
|
51
|
+
if (span.kind !== "run")
|
|
52
|
+
return null;
|
|
53
|
+
const linked = span.attrs.parentSpanId;
|
|
54
|
+
if (typeof linked === "string" && nodes.has(linked))
|
|
55
|
+
return linked;
|
|
56
|
+
return subagentByRun.get(span.runId) ?? null;
|
|
57
|
+
};
|
|
58
|
+
const roots = [];
|
|
59
|
+
for (const span of spans) {
|
|
60
|
+
const node = nodes.get(span.id);
|
|
61
|
+
const parent = parentOf(span);
|
|
62
|
+
if (parent && parent !== span.id)
|
|
63
|
+
nodes.get(parent).children.push(node);
|
|
64
|
+
else
|
|
65
|
+
roots.push(node);
|
|
66
|
+
}
|
|
67
|
+
const reached = new Set();
|
|
68
|
+
const stack = [...roots];
|
|
69
|
+
while (stack.length) {
|
|
70
|
+
const node = stack.pop();
|
|
71
|
+
if (reached.has(node.span.id))
|
|
72
|
+
continue;
|
|
73
|
+
reached.add(node.span.id);
|
|
74
|
+
stack.push(...node.children);
|
|
75
|
+
}
|
|
76
|
+
for (const span of spans) {
|
|
77
|
+
if (reached.has(span.id))
|
|
78
|
+
continue;
|
|
79
|
+
const node = nodes.get(span.id);
|
|
80
|
+
for (const other of nodes.values())
|
|
81
|
+
other.children = other.children.filter((c) => c !== node);
|
|
82
|
+
roots.push(node);
|
|
83
|
+
const again = [node];
|
|
84
|
+
while (again.length) {
|
|
85
|
+
const next = again.pop();
|
|
86
|
+
if (reached.has(next.span.id))
|
|
87
|
+
continue;
|
|
88
|
+
reached.add(next.span.id);
|
|
89
|
+
again.push(...next.children);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
return roots;
|
|
93
|
+
}
|
|
94
|
+
/** The span tree of a run and all of its subagent runs. */
|
|
95
|
+
export function loadSpanTree(db, runId, options = {}) {
|
|
96
|
+
const { spans, total } = listSpansForRuns(db, descendantRunIds(db, runId), options.maxSpans ?? MAX_TREE_SPANS);
|
|
97
|
+
return { roots: buildSpanTree(spans, options.previewChars), total, truncated: total > spans.length };
|
|
98
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { insertRow, updateById } from "./sql.js";
|
|
2
|
+
const COLUMNS = {
|
|
3
|
+
id: "id",
|
|
4
|
+
runId: "run_id",
|
|
5
|
+
parentSpanId: "parent_span_id",
|
|
6
|
+
kind: "kind",
|
|
7
|
+
name: "name",
|
|
8
|
+
status: "status",
|
|
9
|
+
startedAt: "started_at",
|
|
10
|
+
endedAt: "ended_at",
|
|
11
|
+
queuedMs: "queued_ms",
|
|
12
|
+
model: "model",
|
|
13
|
+
provider: "provider",
|
|
14
|
+
tier: "tier",
|
|
15
|
+
effort: "effort",
|
|
16
|
+
modelSource: "model_source",
|
|
17
|
+
tokensIn: "tokens_in",
|
|
18
|
+
tokensOut: "tokens_out",
|
|
19
|
+
cacheRead: "cache_read",
|
|
20
|
+
cacheWrite: "cache_write",
|
|
21
|
+
costUsd: "cost_usd",
|
|
22
|
+
costUnknown: "cost_unknown",
|
|
23
|
+
payloadRef: "payload_ref",
|
|
24
|
+
attrs: "attrs_json",
|
|
25
|
+
};
|
|
26
|
+
function encode(key, value) {
|
|
27
|
+
if (key === "costUnknown")
|
|
28
|
+
return value ? 1 : 0;
|
|
29
|
+
if (key === "attrs")
|
|
30
|
+
return JSON.stringify(value ?? {});
|
|
31
|
+
return (value ?? null);
|
|
32
|
+
}
|
|
33
|
+
function decode(row) {
|
|
34
|
+
const nullable = (v) => (v === null || v === undefined ? null : String(v));
|
|
35
|
+
return {
|
|
36
|
+
id: String(row.id),
|
|
37
|
+
runId: String(row.run_id),
|
|
38
|
+
parentSpanId: nullable(row.parent_span_id),
|
|
39
|
+
kind: row.kind,
|
|
40
|
+
name: String(row.name),
|
|
41
|
+
status: row.status,
|
|
42
|
+
startedAt: String(row.started_at),
|
|
43
|
+
endedAt: nullable(row.ended_at),
|
|
44
|
+
queuedMs: row.queued_ms === null || row.queued_ms === undefined ? null : Number(row.queued_ms),
|
|
45
|
+
model: nullable(row.model),
|
|
46
|
+
provider: nullable(row.provider),
|
|
47
|
+
tier: nullable(row.tier),
|
|
48
|
+
effort: nullable(row.effort),
|
|
49
|
+
modelSource: nullable(row.model_source),
|
|
50
|
+
tokensIn: Number(row.tokens_in),
|
|
51
|
+
tokensOut: Number(row.tokens_out),
|
|
52
|
+
cacheRead: Number(row.cache_read),
|
|
53
|
+
cacheWrite: Number(row.cache_write),
|
|
54
|
+
costUsd: Number(row.cost_usd),
|
|
55
|
+
costUnknown: Number(row.cost_unknown) === 1,
|
|
56
|
+
payloadRef: nullable(row.payload_ref),
|
|
57
|
+
attrs: JSON.parse(String(row.attrs_json ?? "{}")),
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
export function insertSpan(db, row) {
|
|
61
|
+
insertRow(db, "spans", COLUMNS, { ...row }, encode, true);
|
|
62
|
+
}
|
|
63
|
+
export function updateSpan(db, id, patch) {
|
|
64
|
+
updateById(db, "spans", COLUMNS, id, patch, encode);
|
|
65
|
+
}
|
|
66
|
+
export function listSpans(db, runId) {
|
|
67
|
+
return db.prepare("SELECT * FROM spans WHERE run_id = ? ORDER BY started_at, rowid").all(runId).map(decode);
|
|
68
|
+
}
|
|
69
|
+
export function getSpan(db, id) {
|
|
70
|
+
const row = db.prepare("SELECT * FROM spans WHERE id = ?").get(id);
|
|
71
|
+
return row ? decode(row) : undefined;
|
|
72
|
+
}
|
|
73
|
+
/** Spans of the given runs in start order, at most `limit`, with the total count before the limit. */
|
|
74
|
+
export function listSpansForRuns(db, runIds, limit) {
|
|
75
|
+
if (runIds.length === 0)
|
|
76
|
+
return { spans: [], total: 0 };
|
|
77
|
+
const marks = runIds.map(() => "?").join(", ");
|
|
78
|
+
const total = Number(db.prepare(`SELECT COUNT(*) AS n FROM spans WHERE run_id IN (${marks})`).get(...runIds)?.n ?? 0);
|
|
79
|
+
const spans = db
|
|
80
|
+
.prepare(`SELECT * FROM spans WHERE run_id IN (${marks}) ORDER BY started_at, rowid LIMIT ?`)
|
|
81
|
+
.all(...runIds, limit)
|
|
82
|
+
.map(decode);
|
|
83
|
+
return { spans, total };
|
|
84
|
+
}
|
package/store/src/sql.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/** INSERT (or INSERT OR REPLACE) of a row whose keys map to columns through `columns`. */
|
|
2
|
+
export function insertRow(db, table, columns, row, encode, replace = false) {
|
|
3
|
+
const keys = Object.keys(columns);
|
|
4
|
+
const sql = `INSERT ${replace ? "OR REPLACE " : ""}INTO ${table} (${keys.map((k) => columns[k]).join(", ")}) VALUES (${keys.map(() => "?").join(", ")})`;
|
|
5
|
+
db.prepare(sql).run(...keys.map((k) => encode(k, row[k])));
|
|
6
|
+
}
|
|
7
|
+
export function updateById(db, table, columns, id, patch, encode) {
|
|
8
|
+
const keys = Object.keys(patch).filter((k) => k in columns && patch[k] !== undefined);
|
|
9
|
+
if (keys.length === 0)
|
|
10
|
+
return;
|
|
11
|
+
const sql = `UPDATE ${table} SET ${keys.map((k) => `${columns[k]} = ?`).join(", ")} WHERE id = ?`;
|
|
12
|
+
db.prepare(sql).run(...keys.map((k) => encode(k, patch[k])), id);
|
|
13
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { execFile } from "node:child_process";
|
|
2
|
+
import { constants } from "node:fs";
|
|
3
|
+
import { copyFile, lstat, mkdir, readdir, readlink, rm, symlink } from "node:fs/promises";
|
|
4
|
+
import { join } from "node:path";
|
|
5
|
+
function defaultRunCp(args, signal) {
|
|
6
|
+
return new Promise((resolve, reject) => {
|
|
7
|
+
execFile("/bin/cp", args, { signal }, (error, _stdout, stderr) => {
|
|
8
|
+
if (error)
|
|
9
|
+
reject(stderr ? new Error(`${error.message}: ${String(stderr).trim()}`, { cause: error }) : error);
|
|
10
|
+
else
|
|
11
|
+
resolve();
|
|
12
|
+
});
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
/** Removes everything inside `dir`, keeping `dir`. */
|
|
16
|
+
export async function emptyDir(dir) {
|
|
17
|
+
for (const name of await readdir(dir))
|
|
18
|
+
await rm(join(dir, name), { recursive: true, force: true });
|
|
19
|
+
}
|
|
20
|
+
/** Total size of the regular files under `dir`, not following symlinks. */
|
|
21
|
+
async function regularFileBytes(dir) {
|
|
22
|
+
let total = 0;
|
|
23
|
+
for (const entry of await readdir(dir, { withFileTypes: true })) {
|
|
24
|
+
const path = join(dir, entry.name);
|
|
25
|
+
if (entry.isDirectory())
|
|
26
|
+
total += await regularFileBytes(path);
|
|
27
|
+
else if (entry.isFile())
|
|
28
|
+
total += (await lstat(path)).size;
|
|
29
|
+
}
|
|
30
|
+
return total;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Copies the tree under `source` into the existing directory `dest` and returns the bytes of regular files. Each file
|
|
34
|
+
* is requested as a copy-on-write clone (`COPYFILE_FICLONE`, which libuv clones on Linux file systems with reflinks and
|
|
35
|
+
* otherwise copies); symlinks are recreated with their target text unchanged. Other file types (sockets, FIFOs) are skipped.
|
|
36
|
+
*/
|
|
37
|
+
async function jsCopy(source, dest, copy, signal) {
|
|
38
|
+
let total = 0;
|
|
39
|
+
for (const entry of await readdir(source, { withFileTypes: true })) {
|
|
40
|
+
signal?.throwIfAborted();
|
|
41
|
+
const from = join(source, entry.name);
|
|
42
|
+
const to = join(dest, entry.name);
|
|
43
|
+
if (entry.isSymbolicLink())
|
|
44
|
+
await symlink(await readlink(from), to);
|
|
45
|
+
else if (entry.isDirectory()) {
|
|
46
|
+
await mkdir(to);
|
|
47
|
+
total += await jsCopy(from, to, copy, signal);
|
|
48
|
+
}
|
|
49
|
+
else if (entry.isFile()) {
|
|
50
|
+
await copy(from, to, constants.COPYFILE_FICLONE);
|
|
51
|
+
total += (await lstat(from)).size;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
signal?.throwIfAborted();
|
|
55
|
+
return total;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Copies a workspace's contents into the empty directory `dest`, asynchronously, and returns the bytes of regular files
|
|
59
|
+
* copied. On macOS it runs `/bin/cp -cRP`, which clones files with clonefile(2) on APFS and never follows symlinks; when
|
|
60
|
+
* that fails (another file system), what it left is removed and the JS copy runs instead. Elsewhere the JS copy runs:
|
|
61
|
+
* a clone where the file system supports reflinks, a plain copy otherwise. Symlinks are copied as links, their targets
|
|
62
|
+
* unchanged. On failure or abort, `dest` may hold a partial copy.
|
|
63
|
+
*/
|
|
64
|
+
export async function copyWorkspaceTree(source, dest, options = {}) {
|
|
65
|
+
const { signal } = options;
|
|
66
|
+
const copy = options.copyFile ?? ((from, to, mode) => copyFile(from, to, mode));
|
|
67
|
+
signal?.throwIfAborted();
|
|
68
|
+
if ((options.platform ?? process.platform) === "darwin") {
|
|
69
|
+
try {
|
|
70
|
+
await (options.runCp ?? defaultRunCp)(["-cRP", `${source}/.`, dest], signal);
|
|
71
|
+
return await regularFileBytes(dest);
|
|
72
|
+
}
|
|
73
|
+
catch (error) {
|
|
74
|
+
if (signal?.aborted)
|
|
75
|
+
throw error;
|
|
76
|
+
await emptyDir(dest);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
return jsCopy(source, dest, copy, signal);
|
|
80
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/** Structured error carried across every nexo boundary (CLI, run.json, tool results). */
|
|
2
|
+
export class NexoError extends Error {
|
|
3
|
+
code;
|
|
4
|
+
retryable;
|
|
5
|
+
hint;
|
|
6
|
+
context;
|
|
7
|
+
constructor(options) {
|
|
8
|
+
super(options.message, options.cause === undefined ? undefined : { cause: options.cause });
|
|
9
|
+
this.name = "NexoError";
|
|
10
|
+
this.code = options.code;
|
|
11
|
+
this.retryable = options.retryable ?? false;
|
|
12
|
+
this.hint = options.hint;
|
|
13
|
+
this.context = options.context;
|
|
14
|
+
}
|
|
15
|
+
toPayload() {
|
|
16
|
+
const payload = { code: this.code, message: this.message, retryable: this.retryable };
|
|
17
|
+
if (this.hint !== undefined)
|
|
18
|
+
payload.hint = this.hint;
|
|
19
|
+
if (this.context !== undefined)
|
|
20
|
+
payload.context = this.context;
|
|
21
|
+
return payload;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
export function toErrorPayload(error) {
|
|
25
|
+
if (error instanceof NexoError)
|
|
26
|
+
return error.toPayload();
|
|
27
|
+
if (error instanceof Error)
|
|
28
|
+
return { code: "INTERNAL", message: error.message, retryable: false };
|
|
29
|
+
if (typeof error === "string")
|
|
30
|
+
return { code: "INTERNAL", message: error, retryable: false };
|
|
31
|
+
return { code: "INTERNAL", message: "Unknown error", retryable: false };
|
|
32
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { appendFileSync, mkdirSync } from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { toErrorPayload } from "./errors.js";
|
|
4
|
+
const ORDER = { debug: 10, info: 20, warn: 30, error: 40 };
|
|
5
|
+
function normalizeFields(fields) {
|
|
6
|
+
if (!fields)
|
|
7
|
+
return {};
|
|
8
|
+
const out = {};
|
|
9
|
+
for (const [key, value] of Object.entries(fields))
|
|
10
|
+
out[key] = value instanceof Error ? toErrorPayload(value) : value;
|
|
11
|
+
return out;
|
|
12
|
+
}
|
|
13
|
+
/** JSON-lines logger writing to `<dir>/nexo-YYYY-MM-DD.log` (UTC date). */
|
|
14
|
+
export function createLogger(options) {
|
|
15
|
+
mkdirSync(options.dir, { recursive: true });
|
|
16
|
+
const now = options.now ?? (() => new Date());
|
|
17
|
+
const minLevel = ORDER[options.level ?? "info"];
|
|
18
|
+
const write = (level, msg, fields) => {
|
|
19
|
+
if (ORDER[level] < minLevel)
|
|
20
|
+
return;
|
|
21
|
+
const ts = now().toISOString();
|
|
22
|
+
const record = options.redact({
|
|
23
|
+
ts,
|
|
24
|
+
level,
|
|
25
|
+
msg,
|
|
26
|
+
component: options.component,
|
|
27
|
+
...normalizeFields(options.fields),
|
|
28
|
+
...normalizeFields(fields),
|
|
29
|
+
});
|
|
30
|
+
appendFileSync(join(options.dir, `nexo-${ts.slice(0, 10)}.log`), `${JSON.stringify(record)}\n`);
|
|
31
|
+
};
|
|
32
|
+
return {
|
|
33
|
+
debug: (msg, fields) => write("debug", msg, fields),
|
|
34
|
+
info: (msg, fields) => write("info", msg, fields),
|
|
35
|
+
warn: (msg, fields) => write("warn", msg, fields),
|
|
36
|
+
error: (msg, fields) => write("error", msg, fields),
|
|
37
|
+
child: (fields) => createLogger({ ...options, fields: { ...options.fields, ...fields } }),
|
|
38
|
+
};
|
|
39
|
+
}
|