@adhdev/daemon-core 0.9.50 → 0.9.51
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 +461 -399
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +457 -395
- 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/commands/chat-commands.ts +73 -0
package/package.json
CHANGED
|
@@ -3,6 +3,10 @@
|
|
|
3
3
|
* setMode, changeModel, setThoughtLevel, resolveAction, chatHistory
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
+
import * as fs from 'node:fs';
|
|
7
|
+
import * as os from 'node:os';
|
|
8
|
+
import * as path from 'node:path';
|
|
9
|
+
import { randomUUID } from 'node:crypto';
|
|
6
10
|
import type { CommandResult, CommandHelpers } from './handler.js';
|
|
7
11
|
import type { CliAdapter } from '../cli-adapter-types.js';
|
|
8
12
|
import { flattenContent, normalizeInputEnvelope, type InputEnvelope, type ProviderModule, type ProviderScripts } from '../providers/contracts.js';
|
|
@@ -652,6 +656,61 @@ function buildDebugBundleText(bundle: Record<string, unknown>): string {
|
|
|
652
656
|
].join('\n');
|
|
653
657
|
}
|
|
654
658
|
|
|
659
|
+
function getChatDebugBundleDir(): string {
|
|
660
|
+
const override = typeof process.env.ADHDEV_DEBUG_BUNDLE_DIR === 'string'
|
|
661
|
+
? process.env.ADHDEV_DEBUG_BUNDLE_DIR.trim()
|
|
662
|
+
: '';
|
|
663
|
+
return override || path.join(os.homedir(), '.adhdev', 'debug-bundles', 'chat');
|
|
664
|
+
}
|
|
665
|
+
|
|
666
|
+
function safeBundleIdSegment(value: unknown, fallback: string): string {
|
|
667
|
+
const normalized = String(value || fallback)
|
|
668
|
+
.trim()
|
|
669
|
+
.replace(/[^A-Za-z0-9_.-]+/g, '-')
|
|
670
|
+
.replace(/^-+|-+$/g, '')
|
|
671
|
+
.slice(0, 80);
|
|
672
|
+
return normalized || fallback;
|
|
673
|
+
}
|
|
674
|
+
|
|
675
|
+
function createChatDebugBundleId(targetSessionId: string): string {
|
|
676
|
+
const timestamp = new Date().toISOString().replace(/[-:.]/g, '').replace('T', 'T').replace('Z', 'Z');
|
|
677
|
+
const sessionSegment = safeBundleIdSegment(targetSessionId, 'unknown-session');
|
|
678
|
+
return `chat-debug-${timestamp}-${sessionSegment}-${randomUUID().slice(0, 8)}`;
|
|
679
|
+
}
|
|
680
|
+
|
|
681
|
+
function buildChatDebugBundleSummary(bundle: Record<string, unknown>): Record<string, unknown> {
|
|
682
|
+
const target = bundle.target && typeof bundle.target === 'object' ? bundle.target as Record<string, unknown> : {};
|
|
683
|
+
const readChat = bundle.readChat && typeof bundle.readChat === 'object' ? bundle.readChat as Record<string, unknown> : {};
|
|
684
|
+
const cli = bundle.cli && typeof bundle.cli === 'object' ? bundle.cli as Record<string, unknown> : null;
|
|
685
|
+
const frontend = bundle.frontend && typeof bundle.frontend === 'object' ? bundle.frontend as Record<string, unknown> : null;
|
|
686
|
+
return {
|
|
687
|
+
createdAt: bundle.createdAt,
|
|
688
|
+
targetSessionId: target.targetSessionId,
|
|
689
|
+
providerType: target.providerType,
|
|
690
|
+
transport: target.transport,
|
|
691
|
+
readChatSuccess: readChat.success,
|
|
692
|
+
readChatStatus: readChat.status,
|
|
693
|
+
readChatTotalMessages: readChat.totalMessages,
|
|
694
|
+
cliStatus: cli?.status,
|
|
695
|
+
cliMessageCount: cli?.messageCount,
|
|
696
|
+
hasFrontendSnapshot: !!frontend,
|
|
697
|
+
};
|
|
698
|
+
}
|
|
699
|
+
|
|
700
|
+
function storeChatDebugBundleOnDaemon(bundle: Record<string, unknown>, targetSessionId: string): { bundleId: string; savedPath: string; sizeBytes: number } {
|
|
701
|
+
const bundleId = createChatDebugBundleId(targetSessionId);
|
|
702
|
+
const dir = getChatDebugBundleDir();
|
|
703
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
704
|
+
const savedPath = path.join(dir, `${bundleId}.json`);
|
|
705
|
+
const json = `${JSON.stringify(bundle, null, 2)}\n`;
|
|
706
|
+
fs.writeFileSync(savedPath, json, { encoding: 'utf8', mode: 0o600 });
|
|
707
|
+
return { bundleId, savedPath, sizeBytes: Buffer.byteLength(json, 'utf8') };
|
|
708
|
+
}
|
|
709
|
+
|
|
710
|
+
function isDaemonFileDebugDelivery(args: any): boolean {
|
|
711
|
+
return args?.delivery === 'daemon_file' || args?.delivery === 'file';
|
|
712
|
+
}
|
|
713
|
+
|
|
655
714
|
export async function handleGetChatDebugBundle(h: CommandHelpers, args: any): Promise<CommandResult> {
|
|
656
715
|
const targetSessionId = typeof args?.targetSessionId === 'string' ? args.targetSessionId.trim() : '';
|
|
657
716
|
if (!targetSessionId && !h.currentSession) {
|
|
@@ -751,6 +810,20 @@ export async function handleGetChatDebugBundle(h: CommandHelpers, args: any): Pr
|
|
|
751
810
|
};
|
|
752
811
|
|
|
753
812
|
const bundle = sanitizeDebugBundleValue(rawBundle) as Record<string, unknown>;
|
|
813
|
+
if (isDaemonFileDebugDelivery(args)) {
|
|
814
|
+
const summary = buildChatDebugBundleSummary(bundle);
|
|
815
|
+
const stored = storeChatDebugBundleOnDaemon(bundle, targetSessionId || String(summary.targetSessionId || 'unknown-session'));
|
|
816
|
+
LOG.info('Command', `[get_chat_debug_bundle] saved daemon_file bundle id=${stored.bundleId} path=${stored.savedPath} sizeBytes=${stored.sizeBytes} targetSessionId=${summary.targetSessionId || ''} providerType=${summary.providerType || ''} transport=${summary.transport || ''}`);
|
|
817
|
+
return {
|
|
818
|
+
success: true,
|
|
819
|
+
delivery: 'daemon_file',
|
|
820
|
+
bundleId: stored.bundleId,
|
|
821
|
+
savedPath: stored.savedPath,
|
|
822
|
+
sizeBytes: stored.sizeBytes,
|
|
823
|
+
createdAt: bundle.createdAt,
|
|
824
|
+
summary,
|
|
825
|
+
};
|
|
826
|
+
}
|
|
754
827
|
return {
|
|
755
828
|
success: true,
|
|
756
829
|
bundle,
|