@dinoxx/dinox-cli 2.16.1 → 2.18.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.js +2 -0
- package/dist/commands/editor/index.d.ts +4 -0
- package/dist/commands/editor/index.js +155 -0
- package/dist/commands/notes/contentPatch.d.ts +23 -0
- package/dist/commands/notes/contentPatch.js +37 -0
- package/dist/commands/schema/renderSkills.js +1 -0
- package/dist/commands/schema/spec.js +2 -0
- package/dist/daemon/server.d.ts +2 -1
- package/dist/daemon/server.js +22 -2
- package/dist/dsh-plugin/cordis.patch.yml +3 -0
- package/dist/dsh-plugin/lib/client.js +2145 -0
- package/dist/dsh-plugin/lib/index.js +369 -0
- package/dist/dsh-plugin/package.json +32 -0
- package/dist/dsh-plugin/runtime.json +5 -0
- package/dist/editor/anchor.d.ts +46 -0
- package/dist/editor/anchor.js +129 -0
- package/dist/editor/blockIds.d.ts +21 -0
- package/dist/editor/blockIds.js +51 -0
- package/dist/editor/blocks.d.ts +47 -0
- package/dist/editor/blocks.js +236 -0
- package/dist/editor/compat.d.ts +32 -0
- package/dist/editor/compat.js +392 -0
- package/dist/editor/daemon.d.ts +10 -0
- package/dist/editor/daemon.js +56 -0
- package/dist/editor/document.d.ts +74 -0
- package/dist/editor/document.js +88 -0
- package/dist/editor/i18n.d.ts +23 -0
- package/dist/editor/i18n.js +61 -0
- package/dist/editor/install.d.ts +72 -0
- package/dist/editor/install.js +239 -0
- package/dist/editor/mcp.d.ts +22 -0
- package/dist/editor/mcp.js +222 -0
- package/dist/editor/meta.d.ts +70 -0
- package/dist/editor/meta.js +163 -0
- package/dist/editor/paths.d.ts +2 -0
- package/dist/editor/paths.js +13 -0
- package/dist/editor/persistence.d.ts +4 -0
- package/dist/editor/persistence.js +35 -0
- package/dist/editor/saveGuard.d.ts +9 -0
- package/dist/editor/saveGuard.js +38 -0
- package/dist/editor/schema.d.ts +14 -0
- package/dist/editor/schema.js +38 -0
- package/dist/editor/service.d.ts +326 -0
- package/dist/editor/service.js +1007 -0
- package/dist/editor-ui/mcp-app.html +765 -0
- package/dist/gateway/adapters/acp.d.ts +8 -0
- package/dist/gateway/adapters/acp.js +38 -2
- package/dist/gateway/agentTaskHost.d.ts +135 -0
- package/dist/gateway/agentTaskHost.js +410 -0
- package/dist/gateway/config.js +2 -2
- package/dist/gateway/deviceHost.d.ts +6 -1
- package/dist/gateway/deviceHost.js +22 -4
- package/dist/gateway/mcpCommandTools.d.ts +1 -1
- package/dist/gateway/mcpCommandTools.js +2 -2
- package/dist/gateway/processTree.d.ts +15 -0
- package/dist/gateway/processTree.js +60 -0
- package/dist/gateway/protocol.js +2 -1
- package/dist/gateway/service.d.ts +1 -1
- package/dist/gateway/service.js +3 -1
- package/dist/gateway/taskJournal.d.ts +14 -0
- package/dist/gateway/taskJournal.js +47 -0
- package/dist/gateway/threadStore.d.ts +7 -1
- package/dist/gateway/threadStore.js +14 -3
- package/dist/gateway/types.d.ts +7 -3
- package/dist/gateway/types.js +3 -1
- package/dist/integrations/dsh/host.d.ts +53 -0
- package/dist/integrations/dsh/host.js +237 -0
- package/dist/integrations/dsh/mcpClient.d.ts +66 -0
- package/dist/integrations/dsh/mcpClient.js +192 -0
- package/dist/utils/errorCodes.d.ts +28 -0
- package/dist/utils/errorCodes.js +7 -0
- package/dist/vendor/electron/shared/remote-device-agent.d.ts +2 -0
- package/package.json +9 -2
|
@@ -4,12 +4,14 @@ import { credsAuthenticator, wsconnect, } from '@nats-io/nats-core';
|
|
|
4
4
|
import { AI_SERVICE_URL } from '../config/serviceEndpoints.js';
|
|
5
5
|
import { toAuthorizationHeaderValue } from '../utils/authToken.js';
|
|
6
6
|
import { REMOTE_DEVICE_PRESENCE_INTERVAL_MS, REMOTE_DEVICE_PROTOCOL_NAME, REMOTE_DEVICE_PROTOCOL_VERSION, remoteDeviceSubject, remoteDiscoverSubject, remotePresenceSubject, remoteRunStreamSubject, } from '../vendor/electron/shared/remote-device-agent.js';
|
|
7
|
+
import { GatewayAgentTaskHost } from './agentTaskHost.js';
|
|
7
8
|
import { projectPendingApprovals } from './assistantProjection.js';
|
|
8
9
|
import { isAgentConfigQuery, isAgentFolderPrepareQuery, isAgentFoldersQuery, isAgentSettingsQuery, isCancelRequest, isRunStatusRequest, readAgentSettingsUpdate, reconnectDelayMs, validateApprovalRequest, validateRunRequest, } from './protocol.js';
|
|
9
10
|
import { GatewayRunExecutor, MAX_QUEUED_TURNS, QueueFullError } from './runExecutor.js';
|
|
10
11
|
import { RunStreamPublisher } from './streamPublisher.js';
|
|
11
|
-
import { findRun, readRecentSessionFolders, readSessionBinding, resolveTrustedResource, TERMINAL_RUN_STATUSES, threadExists, } from './threadStore.js';
|
|
12
|
+
import { findActiveThreadRun, findRun, readRecentSessionFolders, readSessionBinding, resolveTrustedResource, TERMINAL_RUN_STATUSES, threadExists, } from './threadStore.js';
|
|
12
13
|
import { uploadToOfficialStorage } from './fileUpload.js';
|
|
14
|
+
import { gatewayApproval, } from './types.js';
|
|
13
15
|
import { agentHomeFolder, ensureAgentHomeFolder, existingWorkspaceFolders, listWorkspaceFolders, resolveWorkspaceFolder, WorkspaceFolderError, } from './workspaceFolders.js';
|
|
14
16
|
export const DEFAULT_NATS_CREDENTIALS_URL = `${AI_SERVICE_URL}/api/nats/credentials`;
|
|
15
17
|
const CREDENTIALS_TIMEOUT_MS = 10_000;
|
|
@@ -45,6 +47,7 @@ function decode(msg) {
|
|
|
45
47
|
export class GatewayDeviceHost {
|
|
46
48
|
deps;
|
|
47
49
|
executor;
|
|
50
|
+
agentTasks;
|
|
48
51
|
connection = null;
|
|
49
52
|
subscriptions = [];
|
|
50
53
|
userNo = null;
|
|
@@ -73,6 +76,16 @@ export class GatewayDeviceHost {
|
|
|
73
76
|
keepAwake: deps.keepAwake,
|
|
74
77
|
uploadFile: (file) => uploadToOfficialStorage({ db: deps.db, userId: deps.userId, authorization: deps.authorization, fetchImpl: deps.fetchImpl }, file),
|
|
75
78
|
});
|
|
79
|
+
this.agentTasks = new GatewayAgentTaskHost({
|
|
80
|
+
gateway: deps.gateway,
|
|
81
|
+
userId: deps.userId,
|
|
82
|
+
authorization: deps.authorization,
|
|
83
|
+
machineId: deps.machineId,
|
|
84
|
+
executor: this.executor,
|
|
85
|
+
log: deps.log,
|
|
86
|
+
fetchImpl: deps.fetchImpl,
|
|
87
|
+
baseUrl: deps.agentTaskBaseUrl,
|
|
88
|
+
});
|
|
76
89
|
}
|
|
77
90
|
/** A `send_file` from the Dinox tools of one of this gateway's sessions; `null` when the token is another's. */
|
|
78
91
|
sendFile(token, file) {
|
|
@@ -133,6 +146,7 @@ export class GatewayDeviceHost {
|
|
|
133
146
|
this.connectedAt = new Date().toISOString();
|
|
134
147
|
this.lastError = null;
|
|
135
148
|
this.subscribe(connection, credentials.userNo);
|
|
149
|
+
void this.agentTasks.attach(connection, credentials.userNo);
|
|
136
150
|
this.publishPresence('online');
|
|
137
151
|
this.flushPendingEvents();
|
|
138
152
|
this.presenceTimer = setInterval(() => this.publishPresence('online'), REMOTE_DEVICE_PRESENCE_INTERVAL_MS);
|
|
@@ -188,6 +202,7 @@ export class GatewayDeviceHost {
|
|
|
188
202
|
clearTimeout(timer);
|
|
189
203
|
}
|
|
190
204
|
this.presenceTimer = this.refreshTimer = this.reconnectTimer = null;
|
|
205
|
+
this.agentTasks.detach();
|
|
191
206
|
const connection = this.connection;
|
|
192
207
|
this.connection = null;
|
|
193
208
|
for (const subscription of this.subscriptions)
|
|
@@ -437,7 +452,7 @@ export class GatewayDeviceHost {
|
|
|
437
452
|
threadCwd: null,
|
|
438
453
|
settings: {
|
|
439
454
|
cwd: gateway.cwd ?? null,
|
|
440
|
-
approval: gateway
|
|
455
|
+
approval: gatewayApproval(gateway),
|
|
441
456
|
paused: gateway.paused === true,
|
|
442
457
|
dinoxTools: gateway.dinoxTools !== false,
|
|
443
458
|
},
|
|
@@ -536,13 +551,16 @@ export class GatewayDeviceHost {
|
|
|
536
551
|
if (!msg.reply)
|
|
537
552
|
return;
|
|
538
553
|
if (isRunStatusRequest(value)) {
|
|
539
|
-
|
|
554
|
+
// `active`: a client following a run it did not start (a delegated task's turn) asks
|
|
555
|
+
// for whatever the thread is running and learns its run id from the answer.
|
|
556
|
+
const run = (await findRun(this.deps.db, { runId: value.runId, userId: this.deps.userId })) ??
|
|
557
|
+
(value.active ? await findActiveThreadRun(this.deps.db, { threadId: value.threadId, userId: this.deps.userId }) : null);
|
|
540
558
|
const found = Boolean(run && run.threadId === value.threadId);
|
|
541
559
|
msg.respond(encode({
|
|
542
560
|
protocolVersion: REMOTE_DEVICE_PROTOCOL_VERSION,
|
|
543
561
|
type: 'run.status.result',
|
|
544
562
|
requestId: value.requestId,
|
|
545
|
-
runId: value.runId,
|
|
563
|
+
runId: found && run ? run.id : value.runId,
|
|
546
564
|
threadId: value.threadId,
|
|
547
565
|
found,
|
|
548
566
|
...(found && run
|
|
@@ -12,7 +12,7 @@ import { MCP_COMMAND_GROUPS, type McpCommandGroup } from './mcpGroups.js';
|
|
|
12
12
|
*/
|
|
13
13
|
export { MCP_COMMAND_GROUPS, type McpCommandGroup };
|
|
14
14
|
/** Commands deliberately excluded from the MCP surface. */
|
|
15
|
-
export declare const MCP_COMMAND_EXCLUSIONS: readonly ["auth.*", "config.*", "daemon.*", "gateway.*", "doctor", "skills.*", "update", "sync", "info", "schema", "meta.schema", "batch", "mcp"];
|
|
15
|
+
export declare const MCP_COMMAND_EXCLUSIONS: readonly ["auth.*", "config.*", "daemon.*", "gateway.*", "doctor", "skills.*", "update", "sync", "info", "schema", "meta.schema", "batch", "mcp", "editor.*"];
|
|
16
16
|
export type CommandToolOptions = {
|
|
17
17
|
/** Only commands whose risk is `read`; groups left without any are dropped. */
|
|
18
18
|
readOnly?: boolean;
|
|
@@ -17,8 +17,8 @@ export const MCP_COMMAND_EXCLUSIONS = [
|
|
|
17
17
|
'auth.*', 'config.*', 'daemon.*', 'gateway.*', 'doctor', 'skills.*', 'update', 'sync', 'info', 'schema', 'meta.schema',
|
|
18
18
|
// MCP clients issue several tool calls themselves; batch is the shell's equivalent.
|
|
19
19
|
'batch',
|
|
20
|
-
// The MCP
|
|
21
|
-
'mcp',
|
|
20
|
+
// The MCP servers themselves.
|
|
21
|
+
'mcp', 'editor.*',
|
|
22
22
|
];
|
|
23
23
|
/** The tool name a command group is published under. */
|
|
24
24
|
export function commandToolName(group) {
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/** `ps` elapsed time, `[[dd-]hh:]mm:ss`, in seconds. */
|
|
2
|
+
export declare function parseElapsed(value: string): number | null;
|
|
3
|
+
/**
|
|
4
|
+
* Descendants of `rootPid` that started within the last `withinSeconds`, from
|
|
5
|
+
* `ps -A -o pid=,ppid=,etime=` output. Older descendants (long-lived helpers the agent
|
|
6
|
+
* keeps, such as the `codex` process under codex-acp) are left running, but the search
|
|
7
|
+
* goes on below them: that is where the commands of a turn usually are.
|
|
8
|
+
*/
|
|
9
|
+
export declare function recentDescendants(psOutput: string, rootPid: number, withinSeconds: number): number[];
|
|
10
|
+
/**
|
|
11
|
+
* Stops what an agent started during a turn. ACP's `session/cancel` ends the turn, but
|
|
12
|
+
* agents such as codex-acp leave the shell commands it launched running (they even
|
|
13
|
+
* outlive the agent process), so a cancelled task would keep writing.
|
|
14
|
+
*/
|
|
15
|
+
export declare function killRecentDescendants(rootPid: number, sinceMs: number): Promise<number[]>;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { execFile } from 'node:child_process';
|
|
2
|
+
/** `ps` elapsed time, `[[dd-]hh:]mm:ss`, in seconds. */
|
|
3
|
+
export function parseElapsed(value) {
|
|
4
|
+
const match = /^(?:(\d+)-)?(?:(\d+):)?(\d+):(\d+)$/.exec(value.trim());
|
|
5
|
+
if (!match)
|
|
6
|
+
return null;
|
|
7
|
+
const [, days = '0', hours = '0', minutes, seconds] = match;
|
|
8
|
+
return ((Number(days) * 24 + Number(hours)) * 60 + Number(minutes)) * 60 + Number(seconds);
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Descendants of `rootPid` that started within the last `withinSeconds`, from
|
|
12
|
+
* `ps -A -o pid=,ppid=,etime=` output. Older descendants (long-lived helpers the agent
|
|
13
|
+
* keeps, such as the `codex` process under codex-acp) are left running, but the search
|
|
14
|
+
* goes on below them: that is where the commands of a turn usually are.
|
|
15
|
+
*/
|
|
16
|
+
export function recentDescendants(psOutput, rootPid, withinSeconds) {
|
|
17
|
+
const children = new Map();
|
|
18
|
+
for (const line of psOutput.split('\n')) {
|
|
19
|
+
const [pid, ppid, etime] = line.trim().split(/\s+/);
|
|
20
|
+
const elapsed = etime ? parseElapsed(etime) : null;
|
|
21
|
+
if (!pid || !ppid || elapsed === null)
|
|
22
|
+
continue;
|
|
23
|
+
const list = children.get(Number(ppid)) ?? [];
|
|
24
|
+
list.push({ pid: Number(pid), elapsed });
|
|
25
|
+
children.set(Number(ppid), list);
|
|
26
|
+
}
|
|
27
|
+
const found = [];
|
|
28
|
+
const visit = (parent) => {
|
|
29
|
+
for (const child of children.get(parent) ?? []) {
|
|
30
|
+
if (child.elapsed <= withinSeconds)
|
|
31
|
+
found.push(child.pid);
|
|
32
|
+
visit(child.pid);
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
visit(rootPid);
|
|
36
|
+
return found;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Stops what an agent started during a turn. ACP's `session/cancel` ends the turn, but
|
|
40
|
+
* agents such as codex-acp leave the shell commands it launched running (they even
|
|
41
|
+
* outlive the agent process), so a cancelled task would keep writing.
|
|
42
|
+
*/
|
|
43
|
+
export async function killRecentDescendants(rootPid, sinceMs) {
|
|
44
|
+
if (process.platform === 'win32')
|
|
45
|
+
return [];
|
|
46
|
+
const output = await new Promise((resolve) => {
|
|
47
|
+
execFile('ps', ['-A', '-o', 'pid=,ppid=,etime='], (error, stdout) => resolve(error ? '' : stdout));
|
|
48
|
+
});
|
|
49
|
+
// One extra second: `etime` is whole seconds.
|
|
50
|
+
const pids = recentDescendants(output, rootPid, Math.ceil((Date.now() - sinceMs) / 1000) + 1);
|
|
51
|
+
for (const pid of pids) {
|
|
52
|
+
try {
|
|
53
|
+
process.kill(pid, 'SIGTERM');
|
|
54
|
+
}
|
|
55
|
+
catch {
|
|
56
|
+
// Already gone.
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return pids;
|
|
60
|
+
}
|
package/dist/gateway/protocol.js
CHANGED
|
@@ -122,8 +122,9 @@ export function readAgentSettingsUpdate(value, byteLength) {
|
|
|
122
122
|
change.useAgentFolder = true;
|
|
123
123
|
}
|
|
124
124
|
if (input.approval !== undefined) {
|
|
125
|
-
if (input.approval !== 'ask' && input.approval !== 'auto_read')
|
|
125
|
+
if (input.approval !== 'ask' && input.approval !== 'auto_read' && input.approval !== 'yolo') {
|
|
126
126
|
return { error: 'invalid approval' };
|
|
127
|
+
}
|
|
127
128
|
change.approval = input.approval;
|
|
128
129
|
}
|
|
129
130
|
for (const key of ['paused', 'dinoxTools']) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { AbstractPowerSyncDatabase } from '@powersync/common';
|
|
2
2
|
import { type DeviceHostStatus } from './deviceHost.js';
|
|
3
|
-
import type
|
|
3
|
+
import { type GatewayFileSource, type GatewaySentFile } from './types.js';
|
|
4
4
|
type Logger = (message: string, details?: Record<string, unknown>) => void;
|
|
5
5
|
export type GatewayServiceDeps = {
|
|
6
6
|
db: AbstractPowerSyncDatabase;
|
package/dist/gateway/service.js
CHANGED
|
@@ -6,6 +6,7 @@ import { getMachineId, loadGateways, updateGatewaySettings } from './config.js';
|
|
|
6
6
|
import { GatewayDeviceHost } from './deviceHost.js';
|
|
7
7
|
import { KeepAwake } from './keepAwake.js';
|
|
8
8
|
import { interruptOrphanedRuns, retireRemovedRobots, upsertRobot } from './threadStore.js';
|
|
9
|
+
import { gatewayApproval } from './types.js';
|
|
9
10
|
/** Settings the owner changes from the app; the running gateway picks them up without a restart. */
|
|
10
11
|
const LIVE_SETTINGS = ['cwd', 'previousCwd', 'approval', 'paused', 'dinoxTools'];
|
|
11
12
|
function applyLiveSettings(target, source) {
|
|
@@ -72,6 +73,7 @@ export class GatewayService {
|
|
|
72
73
|
appVersion: getPackageVersion(),
|
|
73
74
|
log: (message, details) => this.log(message, { gateway: gateway.name, ...details }),
|
|
74
75
|
credentialsUrl: this.deps.credentialsUrl,
|
|
76
|
+
machineId,
|
|
75
77
|
updateSettings: (change) => this.updateSettings(gateway, machineId, change),
|
|
76
78
|
keepAwake: () => this.keepAwake.acquire(),
|
|
77
79
|
});
|
|
@@ -124,7 +126,7 @@ export class GatewayService {
|
|
|
124
126
|
machineId,
|
|
125
127
|
...(gateway.agentId ? { agentId: gateway.agentId } : {}),
|
|
126
128
|
settings: {
|
|
127
|
-
approval: gateway
|
|
129
|
+
approval: gatewayApproval(gateway),
|
|
128
130
|
paused: gateway.paused === true,
|
|
129
131
|
dinoxTools: gateway.dinoxTools !== false,
|
|
130
132
|
},
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Dispatches whose agent turn has started and not yet settled, kept on disk so a restarted
|
|
3
|
+
* daemon answers a reconcile honestly: the work may have run (`executor_restarted`, spends an
|
|
4
|
+
* attempt) rather than never arrived (`dispatch_lost`, retried for free and run again).
|
|
5
|
+
*/
|
|
6
|
+
export declare class TaskJournal {
|
|
7
|
+
private readonly file;
|
|
8
|
+
constructor(file?: string);
|
|
9
|
+
has(dispatchId: string): boolean;
|
|
10
|
+
markStarted(dispatchId: string): void;
|
|
11
|
+
clear(dispatchId: string): void;
|
|
12
|
+
private read;
|
|
13
|
+
private write;
|
|
14
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { getDataDir } from '../config/paths.js';
|
|
4
|
+
const KEEP_MS = 7 * 24 * 60 * 60 * 1000;
|
|
5
|
+
/**
|
|
6
|
+
* Dispatches whose agent turn has started and not yet settled, kept on disk so a restarted
|
|
7
|
+
* daemon answers a reconcile honestly: the work may have run (`executor_restarted`, spends an
|
|
8
|
+
* attempt) rather than never arrived (`dispatch_lost`, retried for free and run again).
|
|
9
|
+
*/
|
|
10
|
+
export class TaskJournal {
|
|
11
|
+
file;
|
|
12
|
+
constructor(file = path.join(getDataDir(), 'agent-task-started.json')) {
|
|
13
|
+
this.file = file;
|
|
14
|
+
}
|
|
15
|
+
has(dispatchId) {
|
|
16
|
+
return dispatchId in this.read();
|
|
17
|
+
}
|
|
18
|
+
markStarted(dispatchId) {
|
|
19
|
+
const now = Date.now();
|
|
20
|
+
const entries = Object.fromEntries(Object.entries(this.read()).filter(([, at]) => now - at < KEEP_MS));
|
|
21
|
+
this.write({ ...entries, [dispatchId]: now });
|
|
22
|
+
}
|
|
23
|
+
clear(dispatchId) {
|
|
24
|
+
const entries = this.read();
|
|
25
|
+
if (!(dispatchId in entries))
|
|
26
|
+
return;
|
|
27
|
+
delete entries[dispatchId];
|
|
28
|
+
this.write(entries);
|
|
29
|
+
}
|
|
30
|
+
read() {
|
|
31
|
+
try {
|
|
32
|
+
return JSON.parse(fs.readFileSync(this.file, 'utf8'));
|
|
33
|
+
}
|
|
34
|
+
catch {
|
|
35
|
+
return {};
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
write(entries) {
|
|
39
|
+
try {
|
|
40
|
+
fs.mkdirSync(path.dirname(this.file), { recursive: true });
|
|
41
|
+
fs.writeFileSync(this.file, JSON.stringify(entries));
|
|
42
|
+
}
|
|
43
|
+
catch {
|
|
44
|
+
// Best effort: without it a restart reports dispatch_lost, as before.
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { AbstractPowerSyncDatabase } from '@powersync/common';
|
|
2
2
|
import type { ChatUIMessage, ThreadRunCreateThreadRequest, ThreadRunEventStatus } from '../vendor/electron/shared/external-types.js';
|
|
3
|
+
import type { GatewayApprovalMode } from './types.js';
|
|
3
4
|
/**
|
|
4
5
|
* Persistence for gateway runs, written exactly like Dinox desktop's remote host
|
|
5
6
|
* (dinox-electron ThreadRunQueueService / ThreadRunCoordinatorHelpers) so every
|
|
@@ -85,6 +86,11 @@ export declare function findRun(db: Tx, input: {
|
|
|
85
86
|
runId: string;
|
|
86
87
|
userId: string;
|
|
87
88
|
}): Promise<StoredRun | null>;
|
|
89
|
+
/** The thread's turn that is running now (queued turns wait behind it). */
|
|
90
|
+
export declare function findActiveThreadRun(db: Tx, input: {
|
|
91
|
+
threadId: string;
|
|
92
|
+
userId: string;
|
|
93
|
+
}): Promise<StoredRun | null>;
|
|
88
94
|
/** The queued turns start now: their messages stop showing as queued. */
|
|
89
95
|
export declare function startQueuedRuns(db: AbstractPowerSyncDatabase, userMessageIds: string[]): Promise<void>;
|
|
90
96
|
/** Ends a queued turn that was merged into a later one: no reply of its own is written. */
|
|
@@ -203,7 +209,7 @@ export type RobotRegistration = {
|
|
|
203
209
|
settings?: RobotSettings;
|
|
204
210
|
};
|
|
205
211
|
export type RobotSettings = {
|
|
206
|
-
approval:
|
|
212
|
+
approval: GatewayApprovalMode;
|
|
207
213
|
paused: boolean;
|
|
208
214
|
dinoxTools: boolean;
|
|
209
215
|
};
|
|
@@ -244,9 +244,8 @@ export async function commitRunTerminal(db, input) {
|
|
|
244
244
|
]);
|
|
245
245
|
});
|
|
246
246
|
}
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
FROM local_thread_run WHERE id = ? AND user_id = ? LIMIT 1`, [input.runId, input.userId]);
|
|
247
|
+
const RUN_COLUMNS = 'id, thread_id, status, request_payload_json, assistant_snapshot_json, updated_at';
|
|
248
|
+
function toStoredRun(row) {
|
|
250
249
|
if (!row)
|
|
251
250
|
return null;
|
|
252
251
|
const payload = parseJson(row.request_payload_json);
|
|
@@ -260,6 +259,18 @@ export async function findRun(db, input) {
|
|
|
260
259
|
updatedAt: row.updated_at,
|
|
261
260
|
};
|
|
262
261
|
}
|
|
262
|
+
export async function findRun(db, input) {
|
|
263
|
+
return toStoredRun(await db.getOptional(`SELECT ${RUN_COLUMNS} FROM local_thread_run WHERE id = ? AND user_id = ? LIMIT 1`, [
|
|
264
|
+
input.runId,
|
|
265
|
+
input.userId,
|
|
266
|
+
]));
|
|
267
|
+
}
|
|
268
|
+
/** The thread's turn that is running now (queued turns wait behind it). */
|
|
269
|
+
export async function findActiveThreadRun(db, input) {
|
|
270
|
+
return toStoredRun(await db.getOptional(`SELECT ${RUN_COLUMNS} FROM local_thread_run
|
|
271
|
+
WHERE thread_id = ? AND user_id = ? AND status IN ('running', 'waiting_approval')
|
|
272
|
+
ORDER BY created_at DESC LIMIT 1`, [input.threadId, input.userId]));
|
|
273
|
+
}
|
|
263
274
|
/** Rewrites a user message's queue marker in place; a missing message is ignored. */
|
|
264
275
|
async function writeQueueMarker(tx, messageId, marker, extra = {}) {
|
|
265
276
|
const row = await tx.getOptional('SELECT content FROM c_chat_message WHERE id = ? LIMIT 1', [messageId]);
|
package/dist/gateway/types.d.ts
CHANGED
|
@@ -9,10 +9,14 @@
|
|
|
9
9
|
*/
|
|
10
10
|
export type GatewayKind = 'acp' | 'echo';
|
|
11
11
|
/**
|
|
12
|
-
* When the agent must ask before acting: `
|
|
13
|
-
*
|
|
12
|
+
* When the agent must ask before acting: `yolo` never (the default: the agent runs in its
|
|
13
|
+
* most permissive mode and every request is granted), `auto_read` only for edits and
|
|
14
|
+
* commands, `ask` every time.
|
|
14
15
|
*/
|
|
15
|
-
export type GatewayApprovalMode = 'ask' | 'auto_read';
|
|
16
|
+
export type GatewayApprovalMode = 'ask' | 'auto_read' | 'yolo';
|
|
17
|
+
export declare function gatewayApproval(gateway: {
|
|
18
|
+
approval?: GatewayApprovalMode;
|
|
19
|
+
}): GatewayApprovalMode;
|
|
16
20
|
/** Local-only gateway definition (never synced: it may carry commands and env). */
|
|
17
21
|
export type GatewayDefinition = {
|
|
18
22
|
/** Stable id; also the `c_robot.id` the app binds agents to. */
|
package/dist/gateway/types.js
CHANGED
|
@@ -7,4 +7,6 @@
|
|
|
7
7
|
* user message plus any transcript messages its session has not seen (another
|
|
8
8
|
* agent answered meanwhile), while Dinox keeps the synced copy of the transcript.
|
|
9
9
|
*/
|
|
10
|
-
export {
|
|
10
|
+
export function gatewayApproval(gateway) {
|
|
11
|
+
return gateway.approval ?? 'yolo';
|
|
12
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type { IncomingMessage, ServerResponse } from 'node:http';
|
|
2
|
+
import { McpStdioClient } from './mcpClient.js';
|
|
3
|
+
/**
|
|
4
|
+
* Host half of the Dinox editor plugin for DeepSeek Harness (dsh) Desktop.
|
|
5
|
+
*
|
|
6
|
+
* It is only an adapter: a long-lived `dino editor mcp` child owns nothing but
|
|
7
|
+
* the connection to the daemon, which owns every editor session. This plugin
|
|
8
|
+
* - registers the editor's model tools as dsh tools, keyed by the calling
|
|
9
|
+
* agent's session (`dsh:<sessionId>`);
|
|
10
|
+
* - serves `/dinox-editor/*` for the sidebar tab (same-origin JSON only);
|
|
11
|
+
* - queues the user's selection as context for the agent's next step.
|
|
12
|
+
*
|
|
13
|
+
* It imports Node built-ins only: the profile cannot resolve our dependencies.
|
|
14
|
+
*/
|
|
15
|
+
export declare const name = "dinox-editor";
|
|
16
|
+
export declare const inject: string[];
|
|
17
|
+
export declare const ROUTE = "/dinox-editor";
|
|
18
|
+
type Disposer = () => void;
|
|
19
|
+
/** The slice of the Cordis context this plugin uses (verified against dsh 0.2.1-rc.5). */
|
|
20
|
+
export type DshContext = {
|
|
21
|
+
effect(callback: () => Disposer | void): unknown;
|
|
22
|
+
tools: {
|
|
23
|
+
register(definition: Record<string, unknown>): Disposer;
|
|
24
|
+
};
|
|
25
|
+
webServer: {
|
|
26
|
+
register(route: {
|
|
27
|
+
kind: 'prefix' | 'exact';
|
|
28
|
+
path: string;
|
|
29
|
+
handler: (req: IncomingMessage, res: ServerResponse) => unknown;
|
|
30
|
+
}): Disposer;
|
|
31
|
+
};
|
|
32
|
+
agents: {
|
|
33
|
+
get(sessionId: string): {
|
|
34
|
+
inject(message: unknown): unknown;
|
|
35
|
+
} | undefined;
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
export type HostOptions = {
|
|
39
|
+
/** Overrides the `dino editor mcp` command (tests). */
|
|
40
|
+
client?: Pick<McpStdioClient, 'listTools' | 'callTool' | 'close'>;
|
|
41
|
+
/** Debounce before a changed selection is queued for the agent. */
|
|
42
|
+
contextDebounceMs?: number;
|
|
43
|
+
log?: (message: string) => void;
|
|
44
|
+
};
|
|
45
|
+
type Runtime = {
|
|
46
|
+
node: string;
|
|
47
|
+
cli: string;
|
|
48
|
+
};
|
|
49
|
+
/** Where `dino` lives: recorded by the build / `dino editor install dsh`, else next to this plugin. */
|
|
50
|
+
export declare function resolveRuntime(pluginLib?: string, env?: NodeJS.ProcessEnv): Runtime;
|
|
51
|
+
export declare function apply(ctx: DshContext, options?: HostOptions): void;
|
|
52
|
+
export declare function allowedOrigin(req: Pick<IncomingMessage, 'headers'>): boolean;
|
|
53
|
+
export {};
|