@hyperwindmill/caretaker-cli 0.33.0 → 0.34.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli/index.d.ts.map +1 -1
- package/dist/cli/index.js +9 -1
- package/dist/cli/web/api_access.d.ts +38 -0
- package/dist/cli/web/api_access.d.ts.map +1 -0
- package/dist/cli/web/api_access.js +125 -0
- package/dist/cli/web/openapi.d.ts +7 -0
- package/dist/cli/web/openapi.d.ts.map +1 -0
- package/dist/cli/web/openapi.js +489 -0
- package/dist/cli/web/scheduler/task_review.d.ts +8 -0
- package/dist/cli/web/scheduler/task_review.d.ts.map +1 -1
- package/dist/cli/web/scheduler/task_review.js +17 -1
- package/dist/cli/web/scheduler/task_strategy.js +41 -14
- package/dist/cli/web/server.d.ts +4 -1
- package/dist/cli/web/server.d.ts.map +1 -1
- package/dist/cli/web/server.js +33 -12
- package/dist/harness/tools/builtin/task_tools.d.ts.map +1 -1
- package/dist/harness/tools/builtin/task_tools.js +5 -17
- package/dist/store/db.d.ts +12 -0
- package/dist/store/db.d.ts.map +1 -1
- package/dist/store/db.js +37 -0
- package/dist/store/json.d.ts +29 -0
- package/dist/store/json.d.ts.map +1 -1
- package/dist/store/json.js +54 -0
- package/dist/webview/standalone.js +588 -430
- package/dist/webview/standalone.js.map +4 -4
- package/package.json +3 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../../src/cli/web/server.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../../src/cli/web/server.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,OAAO,MAAM,wBAAwB,CAAC;AA8ClD,OAAO,KAAK,EAAE,WAAW,EAAE,cAAc,EAAgC,MAAM,gBAAgB,CAAC;AAChG,OAAO,KAAK,EAAe,eAAe,EAA0B,MAAM,mBAAmB,CAAC;AAuC9F,MAAM,WAAW,aAA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AI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,CAAC,EACtE,iBAAiB,CAAC,EAAE,OAAO,GAC1B,OAAO,CAAC,IAAI,CAAC;IAsFhB,KAAK,IAAI,IAAI;CAGd;AAED,wBAAsB,WAAW,CAC/B,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,EACZ,GAAG,GAAE;IAAE,IAAI,CAAC,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAA;CAAO,GACzC,OAAO,CAAC,IAAI,CAAC,CAywCf"}
|
package/dist/cli/web/server.js
CHANGED
|
@@ -2,13 +2,14 @@ import { fileURLToPath } from 'node:url';
|
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
import fs from 'node:fs';
|
|
4
4
|
import { watch, existsSync, mkdirSync } from 'node:fs';
|
|
5
|
-
import { randomUUID } from 'node:crypto';
|
|
6
5
|
import { Hono } from 'hono';
|
|
6
|
+
import { applyApiListener, registerApiAccess } from './api_access.js';
|
|
7
|
+
import { registerOpenApi } from './openapi.js';
|
|
7
8
|
import { stream } from 'hono/streaming';
|
|
8
9
|
import { serve } from '@hono/node-server';
|
|
9
10
|
import { WebSocketServer, WebSocket } from 'ws';
|
|
10
11
|
import * as harness from '../../harness/index.js';
|
|
11
|
-
import { getDb, getTaskById, saveTask, createTask, addTaskMessage, deleteTask, deleteTaskSessions, runQuery, tryNormalizeChecklistStatus } from '../../store/db.js';
|
|
12
|
+
import { getDb, getTaskById, saveTask, createTask, addTaskMessage, deleteTask, deleteTaskSessions, runQuery, tryNormalizeChecklistStatus, buildChecklist } from '../../store/db.js';
|
|
12
13
|
import { discardWorktree, syncProjectRepo, projectRepoStatus, managedRepoDir } from '../../lib/task_git.js';
|
|
13
14
|
import { removeContainer } from '../../lib/docker.js';
|
|
14
15
|
import { validateRepositoryUrl } from '../../lib/repo_url.js';
|
|
@@ -154,8 +155,12 @@ export class WebSessionController {
|
|
|
154
155
|
this.inflight?.abort();
|
|
155
156
|
}
|
|
156
157
|
}
|
|
157
|
-
export async function startServer(port, host) {
|
|
158
|
+
export async function startServer(port, host, api = {}) {
|
|
158
159
|
const app = new Hono();
|
|
160
|
+
// Token-authenticated listener for clients outside the browser (api_access.ts).
|
|
161
|
+
const apiListener = { webPort: port, host: api.host ?? host, portOverride: api.port };
|
|
162
|
+
registerApiAccess(app, apiListener);
|
|
163
|
+
registerOpenApi(app);
|
|
159
164
|
app.route('/api/fs', fsRouter);
|
|
160
165
|
registerTaskBridge(app);
|
|
161
166
|
registerVoiceProxy(app);
|
|
@@ -424,23 +429,21 @@ export async function startServer(port, host) {
|
|
|
424
429
|
}
|
|
425
430
|
}
|
|
426
431
|
}
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
order: idx,
|
|
432
|
-
}));
|
|
432
|
+
// Items may arrive already ticked; one without a status starts pending.
|
|
433
|
+
const built = buildChecklist(checklist ?? [], 'pending');
|
|
434
|
+
if ('error' in built)
|
|
435
|
+
return c.json({ ok: false, error: built.error }, 400);
|
|
433
436
|
const config = await loadConfig();
|
|
434
437
|
const project = (config.projects || []).find((p) => p.id === projectId);
|
|
435
438
|
const taskPlanning = typeof planningEnabled === 'boolean' ? planningEnabled : null;
|
|
436
439
|
const startStatus = startActive
|
|
437
440
|
? (resolvePlanningEnabled({ planningEnabled: taskPlanning }, project) ? 'planning' : 'active')
|
|
438
441
|
: 'draft';
|
|
439
|
-
await createTask({
|
|
442
|
+
const task = await createTask({
|
|
440
443
|
projectId,
|
|
441
444
|
title,
|
|
442
445
|
objective,
|
|
443
|
-
checklist:
|
|
446
|
+
checklist: built.checklist,
|
|
444
447
|
status: startStatus,
|
|
445
448
|
blockedReason: null,
|
|
446
449
|
noProgressCount: 0,
|
|
@@ -454,7 +457,7 @@ export async function startServer(port, host) {
|
|
|
454
457
|
sddEnabled: typeof sddEnabled === 'boolean' ? sddEnabled : null,
|
|
455
458
|
maxRunSeconds: typeof maxRunSeconds === 'number' && maxRunSeconds > 0 ? maxRunSeconds : null,
|
|
456
459
|
});
|
|
457
|
-
return c.json({ ok: true });
|
|
460
|
+
return c.json({ ok: true, task });
|
|
458
461
|
});
|
|
459
462
|
app.get('/api/tasks/:id/messages', async (c) => {
|
|
460
463
|
const taskId = c.req.param('id');
|
|
@@ -649,6 +652,22 @@ export async function startServer(port, host) {
|
|
|
649
652
|
}
|
|
650
653
|
return c.json({ ok: true });
|
|
651
654
|
});
|
|
655
|
+
// Replace the whole checklist — same semantics as mcp__task__task_update_checklist:
|
|
656
|
+
// items with an id keep it, the others get a new one, order follows the array.
|
|
657
|
+
app.put('/api/tasks/:id/checklist', async (c) => {
|
|
658
|
+
const taskId = c.req.param('id');
|
|
659
|
+
const body = await c.req.json().catch(() => null);
|
|
660
|
+
const built = buildChecklist(body?.checklist);
|
|
661
|
+
if ('error' in built)
|
|
662
|
+
return c.json({ ok: false, error: built.error }, 400);
|
|
663
|
+
const task = await getTaskById(taskId);
|
|
664
|
+
if (!task)
|
|
665
|
+
return c.json({ ok: false, error: `Task ${taskId} not found` }, 404);
|
|
666
|
+
task.checklist = built.checklist;
|
|
667
|
+
task.updatedAt = new Date().toISOString();
|
|
668
|
+
await saveTask(task);
|
|
669
|
+
return c.json({ ok: true, checklist: task.checklist });
|
|
670
|
+
});
|
|
652
671
|
app.patch('/api/tasks/:id/agent', async (c) => {
|
|
653
672
|
const taskId = c.req.param('id');
|
|
654
673
|
const body = await c.req.json();
|
|
@@ -766,6 +785,8 @@ export async function startServer(port, host) {
|
|
|
766
785
|
port,
|
|
767
786
|
hostname: host,
|
|
768
787
|
});
|
|
788
|
+
// Fire-and-forget: a busy API port is reported in the settings, never fatal.
|
|
789
|
+
void applyApiListener(app, apiListener);
|
|
769
790
|
const bridgeHost = host === '0.0.0.0' || host === '::' ? '127.0.0.1' : host;
|
|
770
791
|
setTaskBridgeUrl(`http://${bridgeHost}:${port}/api/mcp/task`);
|
|
771
792
|
const wss = new WebSocketServer({ noServer: true });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"task_tools.d.ts","sourceRoot":"","sources":["../../../../src/harness/tools/builtin/task_tools.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,IAAI,EAAc,MAAM,aAAa,CAAC;AAepD,eAAO,MAAM,gBAAgB,EAAE,IAmD9B,CAAC;AAEF,eAAO,MAAM,uBAAuB,EAAE,IAqCrC,CAAC;AAEF,eAAO,MAAM,mBAAmB,EAAE,
|
|
1
|
+
{"version":3,"file":"task_tools.d.ts","sourceRoot":"","sources":["../../../../src/harness/tools/builtin/task_tools.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,IAAI,EAAc,MAAM,aAAa,CAAC;AAepD,eAAO,MAAM,gBAAgB,EAAE,IAmD9B,CAAC;AAEF,eAAO,MAAM,uBAAuB,EAAE,IAqCrC,CAAC;AAEF,eAAO,MAAM,mBAAmB,EAAE,IAuCjC,CAAC;AAEF,eAAO,MAAM,qBAAqB,EAAE,IAmEnC,CAAC;AAEF,eAAO,MAAM,cAAc,EAAE,IAiC5B,CAAC;AAEF,eAAO,MAAM,gBAAgB,EAAE,IAgD9B,CAAC;AAEF,eAAO,MAAM,aAAa,EAAE,IAoC3B,CAAC;AAEF,eAAO,MAAM,aAAa,EAAE,IA2C3B,CAAC;AAEF,eAAO,MAAM,eAAe,EAAE,IA4B7B,CAAC;AAEF,eAAO,MAAM,cAAc,EAAE,IAgG5B,CAAC;AAEF,eAAO,MAAM,cAAc,EAAE,IA+B5B,CAAC;AAEF,eAAO,MAAM,eAAe,EAAE,IAwC7B,CAAC;AAEF,eAAO,MAAM,gBAAgB,EAAE,IAoC9B,CAAC;AAEF,eAAO,MAAM,eAAe,EAAE,IAwC7B,CAAC;AAEF,eAAO,MAAM,uBAAuB,EAAE,IA+CrC,CAAC;AAEF,eAAO,MAAM,eAAe,EAAE,IAkC7B,CAAC;AAEF,eAAO,MAAM,iBAAiB,EAAE,IA8B/B,CAAC;AAEF,eAAO,MAAM,cAAc,EAAE,IA0D5B,CAAC;AAEF,eAAO,MAAM,gBAAgB,EAAE,IAgD9B,CAAC;AAEF,eAAO,MAAM,cAAc,EAAE,IAuC5B,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { randomUUID } from 'node:crypto';
|
|
2
|
-
import { getDb, getTaskById, saveTask, createTask, addTaskMessage, deleteTask, tryNormalizeChecklistStatus } from '../../../store/db.js';
|
|
2
|
+
import { getDb, getTaskById, saveTask, createTask, addTaskMessage, deleteTask, tryNormalizeChecklistStatus, buildChecklist } from '../../../store/db.js';
|
|
3
3
|
import { loadConfig, loadAgents } from '../../../store/json.js';
|
|
4
4
|
import { discardWorktree, projectWorkingDir } from '../../../lib/task_git.js';
|
|
5
5
|
import { removeContainer } from '../../../lib/docker.js';
|
|
@@ -117,25 +117,13 @@ export const updateChecklistTool = {
|
|
|
117
117
|
execute: async (args) => {
|
|
118
118
|
const db = getDb();
|
|
119
119
|
const taskId = String(args.task_id);
|
|
120
|
-
const checklistInput = args.checklist;
|
|
121
120
|
const task = await getTaskById(taskId);
|
|
122
121
|
if (!task)
|
|
123
122
|
return err(`Task ${taskId} not found`);
|
|
124
|
-
const
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
if (!status) {
|
|
129
|
-
return err(`Invalid checklist item status "${item.status}" for item "${item.text}". Allowed values are: pending, in_progress, done, skipped.`);
|
|
130
|
-
}
|
|
131
|
-
checklist.push({
|
|
132
|
-
id: item.id || randomUUID(),
|
|
133
|
-
text: item.text,
|
|
134
|
-
status,
|
|
135
|
-
order: idx,
|
|
136
|
-
});
|
|
137
|
-
}
|
|
138
|
-
task.checklist = checklist;
|
|
123
|
+
const built = buildChecklist(args.checklist);
|
|
124
|
+
if ('error' in built)
|
|
125
|
+
return err(built.error);
|
|
126
|
+
task.checklist = built.checklist;
|
|
139
127
|
task.updatedAt = new Date().toISOString();
|
|
140
128
|
await saveTask(task);
|
|
141
129
|
return ok();
|
package/dist/store/db.d.ts
CHANGED
|
@@ -75,6 +75,18 @@ export declare function dataDir(): string;
|
|
|
75
75
|
export declare function dbStoreDir(): string;
|
|
76
76
|
export declare function getDb(): Store;
|
|
77
77
|
export declare function tryNormalizeChecklistStatus(status: any): 'pending' | 'in_progress' | 'done' | 'skipped' | null;
|
|
78
|
+
/**
|
|
79
|
+
* Build a task checklist from untrusted input (a tool call or a REST body).
|
|
80
|
+
* Items that carry an `id` keep it, the others get a new one; order follows the
|
|
81
|
+
* array. `defaultStatus` is what an item without a `status` gets — leave it
|
|
82
|
+
* unset to require one on every item (a replace must not silently reset a
|
|
83
|
+
* finished item to pending).
|
|
84
|
+
*/
|
|
85
|
+
export declare function buildChecklist(input: unknown, defaultStatus?: ChecklistItem['status']): {
|
|
86
|
+
checklist: ChecklistItem[];
|
|
87
|
+
} | {
|
|
88
|
+
error: string;
|
|
89
|
+
};
|
|
78
90
|
export declare function runQuery(sql: string): Promise<any>;
|
|
79
91
|
export declare function getTaskById(id: string): Promise<Task | null>;
|
|
80
92
|
export declare function saveTask(task: Task): Promise<void>;
|
package/dist/store/db.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"db.d.ts","sourceRoot":"","sources":["../../src/store/db.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"db.d.ts","sourceRoot":"","sources":["../../src/store/db.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAKvC,MAAM,WAAW,aAAa;IAC5B,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,SAAS,GAAG,aAAa,GAAG,MAAM,GAAG,SAAS,CAAC;IACvD,KAAK,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,OAAO;IACtB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,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C;IACrB,sDAAsD;IACtD,cAAc,CAAC,EAAE,MAAM,CAAC;IAExB,eAAe,EAAE,MAAM,CAAC;IACxB;4BACwB;IACxB,aAAa,EAAE,MAAM,CAAC;IACtB,wBAAwB;IACxB,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,wBAAsB,UAAU,CAAC,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAIzD;AAED,wBAAsB,YAAY,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC,CAMtD;AAED,wBAAsB,YAAY,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAG5D;AAED;;kEAEkE;AAClE,wBAAsB,gBAAgB,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAahE"}
|
package/dist/store/db.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { join } from 'node:path';
|
|
2
|
+
import { randomUUID } from 'node:crypto';
|
|
2
3
|
import { homedir } from 'node:os';
|
|
3
4
|
import { existsSync, mkdirSync } from 'node:fs';
|
|
4
5
|
import { Store } from '@morphql/store';
|
|
@@ -58,6 +59,42 @@ export function tryNormalizeChecklistStatus(status) {
|
|
|
58
59
|
}
|
|
59
60
|
return null;
|
|
60
61
|
}
|
|
62
|
+
/**
|
|
63
|
+
* Build a task checklist from untrusted input (a tool call or a REST body).
|
|
64
|
+
* Items that carry an `id` keep it, the others get a new one; order follows the
|
|
65
|
+
* array. `defaultStatus` is what an item without a `status` gets — leave it
|
|
66
|
+
* unset to require one on every item (a replace must not silently reset a
|
|
67
|
+
* finished item to pending).
|
|
68
|
+
*/
|
|
69
|
+
export function buildChecklist(input, defaultStatus) {
|
|
70
|
+
if (!Array.isArray(input))
|
|
71
|
+
return { error: 'checklist must be an array.' };
|
|
72
|
+
const checklist = [];
|
|
73
|
+
const seen = new Set();
|
|
74
|
+
for (let idx = 0; idx < input.length; idx++) {
|
|
75
|
+
const item = input[idx];
|
|
76
|
+
const text = typeof item?.text === 'string' ? item.text.trim() : '';
|
|
77
|
+
if (!text)
|
|
78
|
+
return { error: `Checklist item ${idx + 1} has no text.` };
|
|
79
|
+
const status = item.status === undefined || item.status === null
|
|
80
|
+
? (defaultStatus ?? null)
|
|
81
|
+
: tryNormalizeChecklistStatus(item.status);
|
|
82
|
+
if (!status && (item.status === undefined || item.status === null)) {
|
|
83
|
+
return { error: `Checklist item "${text}" has no status. Allowed values are: pending, in_progress, done, skipped.` };
|
|
84
|
+
}
|
|
85
|
+
if (!status) {
|
|
86
|
+
return {
|
|
87
|
+
error: `Invalid checklist item status "${item.status}" for item "${text}". Allowed values are: pending, in_progress, done, skipped.`,
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
const id = typeof item.id === 'string' && item.id ? item.id : randomUUID();
|
|
91
|
+
if (seen.has(id))
|
|
92
|
+
return { error: `Duplicate checklist item id "${id}".` };
|
|
93
|
+
seen.add(id);
|
|
94
|
+
checklist.push({ id, text, status, order: idx });
|
|
95
|
+
}
|
|
96
|
+
return { checklist };
|
|
97
|
+
}
|
|
61
98
|
/** Ids are validated slugs/composites; anything else never matches a record.
|
|
62
99
|
* Also keeps quotes/backslashes out of interpolated queries. */
|
|
63
100
|
function safeId(id) {
|
package/dist/store/json.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ export declare function agentsPath(): string;
|
|
|
7
7
|
export declare function pluginsPath(): string;
|
|
8
8
|
export declare function mcpServersPath(): string;
|
|
9
9
|
export declare function uiStatePath(): string;
|
|
10
|
+
export declare function apiAccessPath(): string;
|
|
10
11
|
export declare const defaultConfig: CaretakerConfig;
|
|
11
12
|
export declare function loadConfig(): Promise<CaretakerConfig>;
|
|
12
13
|
export declare function saveConfig(c: CaretakerConfig): Promise<void>;
|
|
@@ -19,6 +20,34 @@ export interface UiState {
|
|
|
19
20
|
}
|
|
20
21
|
export declare function loadUiState(): Promise<UiState>;
|
|
21
22
|
export declare function saveUiState(s: UiState): Promise<void>;
|
|
23
|
+
/** One API token as stored: the token itself is shown once at creation and
|
|
24
|
+
* only its SHA-256 is kept. A plain hash is enough because the token is 32
|
|
25
|
+
* random bytes, not a password. */
|
|
26
|
+
export interface ApiTokenRecord {
|
|
27
|
+
id: string;
|
|
28
|
+
name: string;
|
|
29
|
+
hash: string;
|
|
30
|
+
createdAt: string;
|
|
31
|
+
}
|
|
32
|
+
/** `api.json`: the authenticated API listener's port and its tokens. Kept out
|
|
33
|
+
* of caretaker.json for the same reason as the UI state — the settings form
|
|
34
|
+
* saves that file whole from a stale copy — and so the hashes never travel
|
|
35
|
+
* to the view inside the config. */
|
|
36
|
+
export interface ApiAccess {
|
|
37
|
+
/** Unset = the listener is off. */
|
|
38
|
+
port?: number;
|
|
39
|
+
tokens: ApiTokenRecord[];
|
|
40
|
+
}
|
|
41
|
+
export declare function loadApiAccess(): Promise<ApiAccess>;
|
|
42
|
+
export declare function setApiPort(port: number | null): Promise<void>;
|
|
43
|
+
/** Creates a token and returns it in clear — the only time it exists outside
|
|
44
|
+
* the caller's hands. */
|
|
45
|
+
export declare function createApiToken(name: string): Promise<{
|
|
46
|
+
token: string;
|
|
47
|
+
record: ApiTokenRecord;
|
|
48
|
+
}>;
|
|
49
|
+
export declare function revokeApiToken(id: string): Promise<boolean>;
|
|
50
|
+
export declare function verifyApiToken(token: string): Promise<boolean>;
|
|
22
51
|
export declare function loadAgents(): Promise<AgentConfig[]>;
|
|
23
52
|
export declare function saveAgents(a: AgentConfig[]): Promise<void>;
|
|
24
53
|
export declare function loadPlugins(): Promise<PluginsFile>;
|
package/dist/store/json.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"json.d.ts","sourceRoot":"","sources":["../../src/store/json.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"json.d.ts","sourceRoot":"","sources":["../../src/store/json.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,WAAW,EAA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AAU,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAGnE;AAED;0BAC0B;AAC1B,wBAAsB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,cAAc,CAAA;CAAE,CAAC,CAYrG;AAED,wBAAsB,cAAc,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAMjE;AAED,wBAAsB,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAWpE;AAED,wBAAsB,UAAU,IAAI,OAAO,CAAC,WAAW,EAAE,CAAC,CAEzD;AAED,wBAAsB,UAAU,CAAC,CAAC,EAAE,WAAW,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAEhE;AAED,wBAAsB,WAAW,IAAI,OAAO,CAAC,WAAW,CAAC,CASxD;AAED,wBAAsB,WAAW,CAAC,IAAI,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,CAElE;AAMD,wBAAsB,cAAc,IAAI,OAAO,CAAC,cAAc,CAAC,CAO9D;AAED,wBAAsB,cAAc,CAAC,IAAI,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC,CAExE;AAID;;;GAGG;AACH,wBAAsB,kBAAkB,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAO5E"}
|
package/dist/store/json.js
CHANGED
|
@@ -2,6 +2,7 @@ import { homedir } from 'node:os';
|
|
|
2
2
|
import { join } from 'node:path';
|
|
3
3
|
import { mkdir, readFile, writeFile, chmod, rename } from 'node:fs/promises';
|
|
4
4
|
import { existsSync } from 'node:fs';
|
|
5
|
+
import { createHash, randomBytes, randomUUID, timingSafeEqual } from 'node:crypto';
|
|
5
6
|
import { encrypt, isEncrypted } from '../lib/encryption.js';
|
|
6
7
|
// Re-exported through the package's `./store` entry point so every surface that
|
|
7
8
|
// persists config (web server, VSCode extension) enforces the same rule on
|
|
@@ -28,6 +29,9 @@ export function mcpServersPath() {
|
|
|
28
29
|
export function uiStatePath() {
|
|
29
30
|
return join(dataDir(), 'ui-state.json');
|
|
30
31
|
}
|
|
32
|
+
export function apiAccessPath() {
|
|
33
|
+
return join(dataDir(), 'api.json');
|
|
34
|
+
}
|
|
31
35
|
export const defaultConfig = {
|
|
32
36
|
port: 17777,
|
|
33
37
|
providers: [],
|
|
@@ -125,6 +129,56 @@ export async function loadUiState() {
|
|
|
125
129
|
export async function saveUiState(s) {
|
|
126
130
|
await writeJson(uiStatePath(), s);
|
|
127
131
|
}
|
|
132
|
+
const hashApiToken = (token) => createHash('sha256').update(token).digest('hex');
|
|
133
|
+
export async function loadApiAccess() {
|
|
134
|
+
const raw = await readJsonOrDefault(apiAccessPath(), {});
|
|
135
|
+
const port = Number.isInteger(raw.port) && raw.port >= 1 && raw.port <= 65535 ? raw.port : undefined;
|
|
136
|
+
const tokens = Array.isArray(raw.tokens)
|
|
137
|
+
? raw.tokens.filter((t) => t && typeof t.id === 'string' && typeof t.hash === 'string')
|
|
138
|
+
: [];
|
|
139
|
+
return port === undefined ? { tokens } : { port, tokens };
|
|
140
|
+
}
|
|
141
|
+
export async function setApiPort(port) {
|
|
142
|
+
const { tokens } = await loadApiAccess();
|
|
143
|
+
await writeJson(apiAccessPath(), port === null ? { tokens } : { port, tokens });
|
|
144
|
+
}
|
|
145
|
+
/** Creates a token and returns it in clear — the only time it exists outside
|
|
146
|
+
* the caller's hands. */
|
|
147
|
+
export async function createApiToken(name) {
|
|
148
|
+
const access = await loadApiAccess();
|
|
149
|
+
const token = `ctk_${randomBytes(32).toString('base64url')}`;
|
|
150
|
+
const record = {
|
|
151
|
+
id: randomUUID(),
|
|
152
|
+
name: name.trim() || 'token',
|
|
153
|
+
hash: hashApiToken(token),
|
|
154
|
+
createdAt: new Date().toISOString(),
|
|
155
|
+
};
|
|
156
|
+
access.tokens.push(record);
|
|
157
|
+
await writeJson(apiAccessPath(), access);
|
|
158
|
+
return { token, record };
|
|
159
|
+
}
|
|
160
|
+
export async function revokeApiToken(id) {
|
|
161
|
+
const access = await loadApiAccess();
|
|
162
|
+
const tokens = access.tokens.filter((t) => t.id !== id);
|
|
163
|
+
if (tokens.length === access.tokens.length)
|
|
164
|
+
return false;
|
|
165
|
+
await writeJson(apiAccessPath(), { ...access, tokens });
|
|
166
|
+
return true;
|
|
167
|
+
}
|
|
168
|
+
export async function verifyApiToken(token) {
|
|
169
|
+
if (!token)
|
|
170
|
+
return false;
|
|
171
|
+
const presented = Buffer.from(hashApiToken(token), 'hex');
|
|
172
|
+
const { tokens } = await loadApiAccess();
|
|
173
|
+
let ok = false;
|
|
174
|
+
for (const t of tokens) {
|
|
175
|
+
const stored = Buffer.from(t.hash, 'hex');
|
|
176
|
+
// No early exit: every stored hash is compared, in constant time each.
|
|
177
|
+
if (stored.length === presented.length && timingSafeEqual(stored, presented))
|
|
178
|
+
ok = true;
|
|
179
|
+
}
|
|
180
|
+
return ok;
|
|
181
|
+
}
|
|
128
182
|
export async function loadAgents() {
|
|
129
183
|
return readJsonOrDefault(agentsPath(), []);
|
|
130
184
|
}
|