@adhdev/daemon-core 0.8.5 → 0.8.7
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/index.js +83 -6
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +83 -6
- package/dist/index.mjs.map +1 -1
- package/node_modules/@adhdev/session-host-core/package.json +1 -1
- package/package.json +1 -1
- package/src/cli-adapters/provider-cli-adapter.ts +63 -7
- package/src/daemon/dev-auto-implement.ts +40 -0
package/package.json
CHANGED
|
@@ -357,6 +357,12 @@ function normalizeScreenSnapshot(text: string): string {
|
|
|
357
357
|
.trim();
|
|
358
358
|
}
|
|
359
359
|
|
|
360
|
+
function normalizeComparableMessageContent(text: string): string {
|
|
361
|
+
return String(text || '')
|
|
362
|
+
.replace(/\s+/g, ' ')
|
|
363
|
+
.trim();
|
|
364
|
+
}
|
|
365
|
+
|
|
360
366
|
/**
|
|
361
367
|
* Normalize provider.json for auto-implement approval detection.
|
|
362
368
|
* Kept for backward compat with dev-server auto-impl pipeline only.
|
|
@@ -486,15 +492,60 @@ export class ProviderCliAdapter implements CliAdapter {
|
|
|
486
492
|
}
|
|
487
493
|
|
|
488
494
|
private normalizeParsedMessages(parsedMessages: any[]): CliChatMessage[] {
|
|
495
|
+
const referenceMessages = [...this.committedMessages];
|
|
496
|
+
const usedReferenceIndexes = new Set<number>();
|
|
497
|
+
const now = Date.now();
|
|
498
|
+
|
|
499
|
+
const findReferenceTimestamp = (role: 'user' | 'assistant', content: string, parsedIndex: number): number | undefined => {
|
|
500
|
+
const normalizedContent = normalizeComparableMessageContent(content);
|
|
501
|
+
if (!normalizedContent) return undefined;
|
|
502
|
+
|
|
503
|
+
const sameIndex = referenceMessages[parsedIndex];
|
|
504
|
+
if (
|
|
505
|
+
sameIndex
|
|
506
|
+
&& !usedReferenceIndexes.has(parsedIndex)
|
|
507
|
+
&& sameIndex.role === role
|
|
508
|
+
&& normalizeComparableMessageContent(sameIndex.content) === normalizedContent
|
|
509
|
+
&& typeof sameIndex.timestamp === 'number'
|
|
510
|
+
&& Number.isFinite(sameIndex.timestamp)
|
|
511
|
+
) {
|
|
512
|
+
usedReferenceIndexes.add(parsedIndex);
|
|
513
|
+
return sameIndex.timestamp;
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
for (let i = 0; i < referenceMessages.length; i++) {
|
|
517
|
+
if (usedReferenceIndexes.has(i)) continue;
|
|
518
|
+
const candidate = referenceMessages[i];
|
|
519
|
+
if (!candidate || candidate.role !== role) continue;
|
|
520
|
+
const candidateContent = normalizeComparableMessageContent(candidate.content);
|
|
521
|
+
if (!candidateContent) continue;
|
|
522
|
+
const exactMatch = candidateContent === normalizedContent;
|
|
523
|
+
const fuzzyMatch = candidateContent.includes(normalizedContent) || normalizedContent.includes(candidateContent);
|
|
524
|
+
if (!exactMatch && !fuzzyMatch) continue;
|
|
525
|
+
if (typeof candidate.timestamp === 'number' && Number.isFinite(candidate.timestamp)) {
|
|
526
|
+
usedReferenceIndexes.add(i);
|
|
527
|
+
return candidate.timestamp;
|
|
528
|
+
}
|
|
529
|
+
}
|
|
530
|
+
|
|
531
|
+
return undefined;
|
|
532
|
+
};
|
|
533
|
+
|
|
489
534
|
return parsedMessages
|
|
490
535
|
.filter((message) => message && (message.role === 'user' || message.role === 'assistant'))
|
|
491
|
-
.map((message) =>
|
|
492
|
-
role
|
|
493
|
-
content
|
|
494
|
-
|
|
536
|
+
.map((message, index) => {
|
|
537
|
+
const role = message.role as 'user' | 'assistant';
|
|
538
|
+
const content = typeof message.content === 'string' ? message.content : String(message.content || '');
|
|
539
|
+
const parsedTimestamp = typeof message.timestamp === 'number' && Number.isFinite(message.timestamp)
|
|
495
540
|
? message.timestamp
|
|
496
|
-
:
|
|
497
|
-
|
|
541
|
+
: undefined;
|
|
542
|
+
const referenceTimestamp = parsedTimestamp ?? findReferenceTimestamp(role, content, index);
|
|
543
|
+
return {
|
|
544
|
+
role,
|
|
545
|
+
content,
|
|
546
|
+
timestamp: referenceTimestamp ?? now,
|
|
547
|
+
};
|
|
548
|
+
});
|
|
498
549
|
}
|
|
499
550
|
|
|
500
551
|
private sliceFromOffset(text: string, start: number): string {
|
|
@@ -749,12 +800,17 @@ export class ProviderCliAdapter implements CliAdapter {
|
|
|
749
800
|
|| isScriptBinary(binaryPath)
|
|
750
801
|
|| !looksLikeMachOOrElf(binaryPath)
|
|
751
802
|
);
|
|
752
|
-
|
|
803
|
+
// On Windows, .cmd/.bat shims cannot be spawned directly — must go through cmd.exe
|
|
804
|
+
const isCmdShim = isWin && /\.(cmd|bat)$/i.test(binaryPath);
|
|
805
|
+
const useShell = isWin ? (!!spawnConfig.shell || isCmdShim) : useShellUnix;
|
|
753
806
|
|
|
754
807
|
if (useShell) {
|
|
755
808
|
if (!spawnConfig.shell && !isWin) {
|
|
756
809
|
LOG.info('CLI', `[${this.cliType}] Using login shell (script shim or non-native binary)`);
|
|
757
810
|
}
|
|
811
|
+
if (isCmdShim) {
|
|
812
|
+
LOG.info('CLI', `[${this.cliType}] Using cmd.exe shell for .cmd/.bat shim: ${binaryPath}`);
|
|
813
|
+
}
|
|
758
814
|
shellCmd = isWin ? 'cmd.exe' : (process.env.SHELL || '/bin/zsh');
|
|
759
815
|
if (isWin) {
|
|
760
816
|
// On Windows, pass binaryPath and args as separate items so node-pty's
|
|
@@ -516,6 +516,8 @@ export async function handleAutoImplement(ctx: DevServerContext, type: string, r
|
|
|
516
516
|
let approvalBuffer = '';
|
|
517
517
|
let lastApprovalTime = 0;
|
|
518
518
|
let completionSignalSeen = false;
|
|
519
|
+
let autoStopTimer: ReturnType<typeof setTimeout> | null = null;
|
|
520
|
+
let autoStopIssued = false;
|
|
519
521
|
|
|
520
522
|
try {
|
|
521
523
|
const { normalizeCliProviderForRuntime } = await import('../cli-adapters/provider-cli-adapter.js');
|
|
@@ -566,8 +568,40 @@ export async function handleAutoImplement(ctx: DevServerContext, type: string, r
|
|
|
566
568
|
}
|
|
567
569
|
};
|
|
568
570
|
|
|
571
|
+
const clearAutoStopTimer = () => {
|
|
572
|
+
if (autoStopTimer) {
|
|
573
|
+
clearTimeout(autoStopTimer);
|
|
574
|
+
autoStopTimer = null;
|
|
575
|
+
}
|
|
576
|
+
};
|
|
577
|
+
|
|
578
|
+
const scheduleAutoStopForVerification = () => {
|
|
579
|
+
if (!verification || command !== 'codex' || completionSignalSeen || autoStopIssued) return;
|
|
580
|
+
const elapsed = Date.now() - spawnedAt;
|
|
581
|
+
if (elapsed < 30000) return;
|
|
582
|
+
clearAutoStopTimer();
|
|
583
|
+
autoStopTimer = setTimeout(() => {
|
|
584
|
+
if (!ctx.autoImplProcess || completionSignalSeen || autoStopIssued) return;
|
|
585
|
+
autoStopIssued = true;
|
|
586
|
+
ctx.log(`Auto-implement output quiet for 30s after ${Math.round((Date.now() - spawnedAt) / 1000)}s. Interrupting agent and switching to daemon verification.`);
|
|
587
|
+
sendAutoImplSSE(ctx, {
|
|
588
|
+
event: 'output',
|
|
589
|
+
data: {
|
|
590
|
+
chunk: '\n[🤖 ADHDev Pipeline] Agent output quiet. Interrupting and running daemon verification...\n',
|
|
591
|
+
stream: 'stdout',
|
|
592
|
+
},
|
|
593
|
+
});
|
|
594
|
+
try {
|
|
595
|
+
(ctx.autoImplProcess as any).kill('SIGINT');
|
|
596
|
+
} catch {
|
|
597
|
+
// ignore
|
|
598
|
+
}
|
|
599
|
+
}, 30000);
|
|
600
|
+
};
|
|
601
|
+
|
|
569
602
|
const finalizeCliAutoImpl = async (code: number | null) => {
|
|
570
603
|
ctx.autoImplProcess = null;
|
|
604
|
+
clearAutoStopTimer();
|
|
571
605
|
let success = completionSignalSeen || code === 0;
|
|
572
606
|
let message = success
|
|
573
607
|
? (completionSignalSeen && code !== 0 ? '✅ Auto-implement complete (completion signal)' : '✅ Auto-implement complete')
|
|
@@ -620,12 +654,14 @@ export async function handleAutoImplement(ctx: DevServerContext, type: string, r
|
|
|
620
654
|
if (isPty) {
|
|
621
655
|
child.onData((data: string) => {
|
|
622
656
|
stdout += data;
|
|
657
|
+
clearAutoStopTimer();
|
|
623
658
|
if (data.includes('\x1b[6n')) {
|
|
624
659
|
child.write('\x1b[12;1R');
|
|
625
660
|
ctx.log('Terminal CPR request (\\x1b[6n) intercepted in PTY, responding with dummy coordinates [12;1R]');
|
|
626
661
|
}
|
|
627
662
|
checkAutoApproval(data, (s) => child.write(s));
|
|
628
663
|
sendAutoImplSSE(ctx, { event: 'output', data: { chunk: data, stream: 'stdout' } });
|
|
664
|
+
scheduleAutoStopForVerification();
|
|
629
665
|
});
|
|
630
666
|
child.onExit(({ exitCode: code }: { exitCode: number }) => {
|
|
631
667
|
void finalizeCliAutoImpl(code);
|
|
@@ -634,15 +670,19 @@ export async function handleAutoImplement(ctx: DevServerContext, type: string, r
|
|
|
634
670
|
child.stdout?.on('data', (d: Buffer) => {
|
|
635
671
|
const chunk = d.toString();
|
|
636
672
|
stdout += chunk;
|
|
673
|
+
clearAutoStopTimer();
|
|
637
674
|
if (chunk.includes('\x1b[6n')) child.stdin?.write('\x1b[1;1R');
|
|
638
675
|
checkAutoApproval(chunk, (s) => child.stdin?.write(s));
|
|
639
676
|
sendAutoImplSSE(ctx, { event: 'output', data: { chunk, stream: 'stdout' } });
|
|
677
|
+
scheduleAutoStopForVerification();
|
|
640
678
|
});
|
|
641
679
|
child.stderr?.on('data', (d: Buffer) => {
|
|
642
680
|
const chunk = d.toString();
|
|
643
681
|
stderr += chunk;
|
|
682
|
+
clearAutoStopTimer();
|
|
644
683
|
checkAutoApproval(chunk, (s) => child.stdin?.write(s));
|
|
645
684
|
sendAutoImplSSE(ctx, { event: 'output', data: { chunk, stream: 'stderr' } });
|
|
685
|
+
scheduleAutoStopForVerification();
|
|
646
686
|
});
|
|
647
687
|
child.on('exit', (code: number) => {
|
|
648
688
|
void finalizeCliAutoImpl(code);
|