@adhdev/daemon-core 0.9.76-rc.21 → 0.9.76-rc.23
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/commands/cli-manager.d.ts +11 -0
- package/dist/git/git-types.d.ts +1 -1
- package/dist/index.js +70 -10
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +71 -11
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/commands/cli-manager.ts +66 -3
- package/src/git/git-commands.ts +5 -1
- package/src/git/git-types.ts +1 -0
- package/src/providers/cli-provider-instance.ts +26 -5
package/package.json
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
import * as os from 'os';
|
|
9
9
|
import * as path from 'path';
|
|
10
10
|
import * as crypto from 'crypto';
|
|
11
|
-
import { existsSync } from 'fs';
|
|
11
|
+
import { existsSync, mkdirSync, writeFileSync } from 'fs';
|
|
12
12
|
import { execFileSync } from 'child_process';
|
|
13
13
|
import chalk from 'chalk';
|
|
14
14
|
import { ProviderCliAdapter } from '../cli-adapters/provider-cli-adapter.js';
|
|
@@ -138,6 +138,56 @@ type CliStartOptions = {
|
|
|
138
138
|
extraEnv?: Record<string, string>;
|
|
139
139
|
};
|
|
140
140
|
|
|
141
|
+
const COORDINATOR_DELEGATED_ENV_UNSETS: Record<string, string> = {
|
|
142
|
+
ADHDEV_INLINE_MESH: '',
|
|
143
|
+
ADHDEV_MCP_TRANSPORT: '',
|
|
144
|
+
ADHDEV_MESH_ID: '',
|
|
145
|
+
HERMES_EPHEMERAL_SYSTEM_PROMPT: '',
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
export interface CoordinatorDelegatedCliLaunchOptionsInput {
|
|
149
|
+
cliType: string;
|
|
150
|
+
workspace: string;
|
|
151
|
+
cliArgs?: string[];
|
|
152
|
+
env?: Record<string, string>;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
export interface CoordinatorDelegatedCliLaunchOptions {
|
|
156
|
+
cliArgs: string[];
|
|
157
|
+
env: Record<string, string>;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
function hasCliArg(args: string[], flag: string): boolean {
|
|
161
|
+
return args.some((arg) => arg === flag || arg.startsWith(`${flag}=`));
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
function ensureEmptyDelegatedMcpConfig(workspace: string): string {
|
|
165
|
+
const baseDir = path.join(os.tmpdir(), 'adhdev-delegated-agent-empty-mcp');
|
|
166
|
+
mkdirSync(baseDir, { recursive: true });
|
|
167
|
+
const workspaceHash = crypto.createHash('sha256').update(path.resolve(workspace || os.tmpdir())).digest('hex').slice(0, 16);
|
|
168
|
+
const filePath = path.join(baseDir, `${workspaceHash}.json`);
|
|
169
|
+
writeFileSync(filePath, JSON.stringify({ mcpServers: {} }, null, 2), 'utf-8');
|
|
170
|
+
return filePath;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
export function buildCoordinatorDelegatedCliLaunchOptions(
|
|
174
|
+
input: CoordinatorDelegatedCliLaunchOptionsInput,
|
|
175
|
+
): CoordinatorDelegatedCliLaunchOptions {
|
|
176
|
+
const cliType = String(input.cliType || '').trim();
|
|
177
|
+
const cliArgs = Array.isArray(input.cliArgs) ? [...input.cliArgs] : [];
|
|
178
|
+
const env: Record<string, string> = { ...(input.env || {}), ...COORDINATOR_DELEGATED_ENV_UNSETS };
|
|
179
|
+
|
|
180
|
+
if (cliType === 'hermes-cli' && !hasCliArg(cliArgs, '--ignore-user-config')) {
|
|
181
|
+
cliArgs.unshift('--ignore-user-config');
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
if (cliType === 'claude-cli' && !hasCliArg(cliArgs, '--mcp-config')) {
|
|
185
|
+
cliArgs.unshift('--mcp-config', ensureEmptyDelegatedMcpConfig(input.workspace));
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
return { cliArgs, env };
|
|
189
|
+
}
|
|
190
|
+
|
|
141
191
|
function isUuid(value: string): boolean {
|
|
142
192
|
return /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(value);
|
|
143
193
|
}
|
|
@@ -909,12 +959,25 @@ export class DaemonCliManager {
|
|
|
909
959
|
const launchSource = resolved.source;
|
|
910
960
|
if (!cliType) throw new Error('cliType required');
|
|
911
961
|
|
|
962
|
+
const settingsOverride = args?.settings && typeof args.settings === 'object' ? args.settings : undefined;
|
|
963
|
+
const delegatedLaunch = settingsOverride?.launchedByCoordinator === true
|
|
964
|
+
? buildCoordinatorDelegatedCliLaunchOptions({
|
|
965
|
+
cliType,
|
|
966
|
+
workspace: dir,
|
|
967
|
+
cliArgs: args?.cliArgs,
|
|
968
|
+
env: args?.env,
|
|
969
|
+
})
|
|
970
|
+
: null;
|
|
912
971
|
const started = await this.startSession(
|
|
913
972
|
cliType,
|
|
914
973
|
dir,
|
|
915
|
-
args?.cliArgs,
|
|
974
|
+
delegatedLaunch ? delegatedLaunch.cliArgs : args?.cliArgs,
|
|
916
975
|
args?.initialModel,
|
|
917
|
-
{
|
|
976
|
+
{
|
|
977
|
+
resumeSessionId: args?.resumeSessionId,
|
|
978
|
+
settingsOverride,
|
|
979
|
+
extraEnv: delegatedLaunch ? delegatedLaunch.env : args?.env,
|
|
980
|
+
},
|
|
918
981
|
);
|
|
919
982
|
|
|
920
983
|
return {
|
package/src/git/git-commands.ts
CHANGED
|
@@ -152,6 +152,7 @@ const FAILURE_REASONS = new Set<GitFailureReason>([
|
|
|
152
152
|
'dirty_index_required',
|
|
153
153
|
'conflict',
|
|
154
154
|
'invalid_args',
|
|
155
|
+
'nothing_to_commit',
|
|
155
156
|
'git_command_failed',
|
|
156
157
|
]);
|
|
157
158
|
|
|
@@ -454,7 +455,10 @@ async function gitCheckpoint(
|
|
|
454
455
|
} catch (err: any) {
|
|
455
456
|
const output = (err?.stdout || '') + (err?.stderr || '');
|
|
456
457
|
if (/nothing to commit/i.test(output)) {
|
|
457
|
-
throw new GitCommandError('
|
|
458
|
+
throw new GitCommandError('nothing_to_commit', 'Nothing to commit — working tree is clean.', {
|
|
459
|
+
stdout: err?.stdout,
|
|
460
|
+
stderr: err?.stderr,
|
|
461
|
+
});
|
|
458
462
|
}
|
|
459
463
|
throw err;
|
|
460
464
|
}
|
package/src/git/git-types.ts
CHANGED
|
@@ -985,12 +985,33 @@ export class CliProviderInstance implements ProviderInstance {
|
|
|
985
985
|
private mergeConversationMessages(parsedMessages: any[]): ChatMessage[] {
|
|
986
986
|
if (this.runtimeMessages.length === 0) return normalizeChatMessages(parsedMessages);
|
|
987
987
|
|
|
988
|
-
|
|
989
|
-
|
|
988
|
+
type MergeEntry = { message: ChatMessage; index: number; source: 'parsed' | 'runtime' };
|
|
989
|
+
const parsedEntries: MergeEntry[] = parsedMessages.map((message, index) => ({
|
|
990
|
+
message,
|
|
991
|
+
index,
|
|
992
|
+
source: 'parsed',
|
|
993
|
+
}));
|
|
994
|
+
const runtimeEntries: MergeEntry[] = this.runtimeMessages.map((entry, index) => ({
|
|
995
|
+
message: entry.message,
|
|
996
|
+
index: parsedMessages.length + index,
|
|
997
|
+
source: 'runtime',
|
|
998
|
+
}));
|
|
999
|
+
const getTime = (message: ChatMessage): number => {
|
|
1000
|
+
const value = typeof message.receivedAt === 'number'
|
|
1001
|
+
? message.receivedAt
|
|
1002
|
+
: typeof message.timestamp === 'number'
|
|
1003
|
+
? message.timestamp
|
|
1004
|
+
: 0;
|
|
1005
|
+
return Number.isFinite(value) && value > 0 ? value : 0;
|
|
1006
|
+
};
|
|
1007
|
+
|
|
1008
|
+
return normalizeChatMessages([...parsedEntries, ...runtimeEntries]
|
|
990
1009
|
.sort((a, b) => {
|
|
991
|
-
const aTime = a.message
|
|
992
|
-
const bTime = b.message
|
|
993
|
-
if (aTime !== bTime) return aTime - bTime;
|
|
1010
|
+
const aTime = getTime(a.message);
|
|
1011
|
+
const bTime = getTime(b.message);
|
|
1012
|
+
if (aTime && bTime && aTime !== bTime) return aTime - bTime;
|
|
1013
|
+
if (aTime && !bTime && a.source === 'runtime' && b.source === 'parsed') return -1;
|
|
1014
|
+
if (!aTime && bTime && a.source === 'parsed' && b.source === 'runtime') return 1;
|
|
994
1015
|
return a.index - b.index;
|
|
995
1016
|
})
|
|
996
1017
|
.map((entry) => entry.message));
|