@adhdev/daemon-core 0.9.82-rc.361 → 0.9.82-rc.363

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.
Files changed (33) hide show
  1. package/dist/cli-adapters/cli-state-engine.d.ts +1 -1
  2. package/dist/cli-adapters/provider-cli-shared.d.ts +10 -0
  3. package/dist/commands/low-family/coordinator-prompt.d.ts +9 -0
  4. package/dist/commands/low-family/daemon-lifecycle.d.ts +2 -0
  5. package/dist/commands/low-family/diagnostics.d.ts +2 -0
  6. package/dist/commands/low-family/mesh-ledger.d.ts +10 -0
  7. package/dist/commands/low-family/mesh-node-logs.d.ts +2 -0
  8. package/dist/commands/low-family/notification.d.ts +2 -0
  9. package/dist/commands/low-family/status-meta.d.ts +2 -0
  10. package/dist/commands/low-family/types.d.ts +17 -0
  11. package/dist/index.js +2290 -2177
  12. package/dist/index.js.map +1 -1
  13. package/dist/index.mjs +2296 -2183
  14. package/dist/index.mjs.map +1 -1
  15. package/dist/mesh/mesh-events-utils.d.ts +1 -0
  16. package/dist/providers/cli-provider-instance.d.ts +2 -0
  17. package/package.json +2 -2
  18. package/src/cli-adapters/cli-state-engine.ts +7 -1
  19. package/src/cli-adapters/provider-cli-adapter.ts +1 -0
  20. package/src/cli-adapters/provider-cli-shared.ts +10 -0
  21. package/src/commands/low-family/coordinator-prompt.ts +72 -0
  22. package/src/commands/low-family/daemon-lifecycle.ts +107 -0
  23. package/src/commands/low-family/diagnostics.ts +57 -0
  24. package/src/commands/low-family/index.ts +14 -0
  25. package/src/commands/low-family/mesh-ledger.ts +62 -0
  26. package/src/commands/low-family/mesh-node-logs.ts +81 -0
  27. package/src/commands/low-family/notification.ts +116 -0
  28. package/src/commands/low-family/status-meta.ts +112 -0
  29. package/src/commands/low-family/types.ts +20 -0
  30. package/src/commands/router.ts +8 -522
  31. package/src/mesh/mesh-events-coordinator.ts +37 -0
  32. package/src/mesh/mesh-events-utils.ts +28 -2
  33. package/src/providers/cli-provider-instance.ts +46 -0
@@ -0,0 +1,112 @@
1
+ /**
2
+ * RF-ROUTER LOW family — status/metadata + user-name commands.
3
+ *
4
+ * Extracted verbatim from DaemonCommandRouter.executeDaemonCommand. Each handler
5
+ * reads only ctx.deps (+ process-global config/status builders) and returns the
6
+ * same CommandRouterResult the inlined case did. get_session_info aggregates the
7
+ * session/coordinator registries the router already holds via deps; none of these
8
+ * touch the router's inline-mesh cache or other instance state.
9
+ */
10
+ import { loadConfig, updateConfig } from '../../config/config.js';
11
+ import { buildMachineInfo, buildStatusSnapshot } from '../../status/snapshot.js';
12
+ import { getDaemonBuildInfo } from '../../build-info.js';
13
+ import { getCoordinatorForSession } from '../../mesh/coordinator-registry.js';
14
+ import type { LowFamilyContext, LowFamilyHandler } from './types.js';
15
+
16
+ export const statusMetaHandlers: Record<string, LowFamilyHandler> = {
17
+ set_user_name: async (_ctx: LowFamilyContext, args: any) => {
18
+ const name = args?.userName;
19
+ if (!name || typeof name !== 'string') throw new Error('userName required');
20
+ updateConfig({ userName: name });
21
+ return { success: true, userName: name };
22
+ },
23
+
24
+ get_status_metadata: async (ctx: LowFamilyContext, _args: any) => {
25
+ const snapshot = buildStatusSnapshot({
26
+ allStates: ctx.deps.instanceManager.collectAllStates(),
27
+ cdpManagers: ctx.deps.cdpManagers,
28
+ providerLoader: ctx.deps.providerLoader,
29
+ detectedIdes: ctx.deps.detectedIdes.value,
30
+ instanceId: ctx.deps.statusInstanceId || loadConfig().machineId || 'daemon',
31
+ version: ctx.deps.statusVersion || 'unknown',
32
+ profile: 'metadata',
33
+ });
34
+ // Surface the daemon's build stamp so coordinators (mesh_status)
35
+ // can detect a running daemon that predates a just-merged fix and
36
+ // is awaiting deploy/restart. Sibling of `status` to avoid
37
+ // perturbing the dashboard status snapshot shape.
38
+ return { success: true, status: snapshot, daemonBuild: getDaemonBuildInfo() };
39
+ },
40
+
41
+ get_machine_runtime_stats: async (_ctx: LowFamilyContext, _args: any) => {
42
+ return {
43
+ success: true,
44
+ machine: buildMachineInfo('full'),
45
+ timestamp: Date.now(),
46
+ };
47
+ },
48
+
49
+ // Session-info popup data. Aggregates whatever the daemon knows
50
+ // about a single live session into one envelope so the dashboard
51
+ // doesn't need to stitch together status + coordinator registry +
52
+ // session registry on the client. Includes the actual system
53
+ // prompt that was injected at launch when the session is a mesh
54
+ // coordinator — that's the "what prompt did the agent see?"
55
+ // question the info-icon dialog is meant to answer.
56
+ get_session_info: async (ctx: LowFamilyContext, args: any) => {
57
+ const sessionId = typeof args?.targetSessionId === 'string' ? args.targetSessionId.trim()
58
+ : typeof args?.sessionId === 'string' ? args.sessionId.trim() : '';
59
+ if (!sessionId) return { success: false, error: 'targetSessionId required' };
60
+ // Fetch both lookups up front. We used to bail with "Session not
61
+ // found" when sessionRegistry forgot the SID (auto-cleanup,
62
+ // daemon restart with the session not yet restored, etc), which
63
+ // hid the coordinator-side metadata even though the
64
+ // coordinator-registry still has it. Now we return whichever
65
+ // side we have. The dashboard renders "no coordinator-specific
66
+ // prompt" only when *neither* side knows the session.
67
+ const target = ctx.deps.sessionRegistry.get(sessionId);
68
+ const coord = getCoordinatorForSession(sessionId);
69
+ if (!target && !coord) return { success: false, error: 'Session not found', sessionId };
70
+ const adapter = target
71
+ ? ctx.deps.cliManager.findAdapter(target.providerType, { instanceKey: sessionId })?.adapter
72
+ : undefined;
73
+ const runtimeMeta = (adapter && typeof (adapter as any).getRuntimeMetadata === 'function')
74
+ ? (adapter as any).getRuntimeMetadata()
75
+ : undefined;
76
+ // Launch metadata (args / cwd / extra-env keys / providerSessionId) is
77
+ // derived from the live adapter's spawn plan; only available while the
78
+ // adapter is alive (resumed-from-history sessions report nothing here).
79
+ const launchInfo = (adapter && typeof (adapter as any).getLaunchInfo === 'function')
80
+ ? (adapter as any).getLaunchInfo()
81
+ : undefined;
82
+ const providerType = target?.providerType || coord?.cliType || '';
83
+ const providerMetaForSession = providerType
84
+ ? ctx.deps.providerLoader.resolve?.(providerType) || ctx.deps.providerLoader.getMeta(providerType)
85
+ : undefined;
86
+ return {
87
+ success: true,
88
+ session: {
89
+ sessionId,
90
+ providerType,
91
+ providerName: providerMetaForSession?.name,
92
+ transport: target?.transport,
93
+ workspace: (target as any)?.workspace || coord?.workspace,
94
+ spawnedAtMs: (target as any)?.spawnedAtMs || coord?.startedAt,
95
+ // providerSessionId now comes from the live adapter's launch info
96
+ // (the registry target never carried it — it was always undefined).
97
+ providerSessionId: launchInfo?.providerSessionId || (target as any)?.providerSessionId,
98
+ runtimeMetadata: runtimeMeta,
99
+ launch: launchInfo,
100
+ },
101
+ coordinator: coord ? {
102
+ meshId: coord.meshId,
103
+ startedAt: coord.startedAt,
104
+ cliType: coord.cliType,
105
+ systemPrompt: coord.systemPrompt,
106
+ extraSystemPrompt: coord.extraSystemPrompt,
107
+ injection: coord.injection,
108
+ mcpConfigPath: coord.mcpConfigPath,
109
+ } : null,
110
+ };
111
+ },
112
+ };
@@ -10,8 +10,28 @@
10
10
  */
11
11
  import type { CommandRouterDeps, CommandRouterResult } from '../router.js';
12
12
 
13
+ /** Mesh record resolved from the router's inline-mesh cache + local config. */
14
+ export type ResolvedMeshForCommand = {
15
+ mesh: any;
16
+ inline: boolean;
17
+ source: 'inline_cache' | 'inline_bootstrap' | 'local_config';
18
+ } | null;
19
+
13
20
  export interface LowFamilyContext {
14
21
  deps: CommandRouterDeps;
22
+ /**
23
+ * Bound `DaemonCommandRouter.getMeshForCommand`. A handful of LOW handlers
24
+ * (mesh-node-logs) must resolve a mesh node's owning daemonId from the
25
+ * router's inline-mesh cache, which is router instance state not present in
26
+ * `deps`. The router injects it at dispatch; handlers that don't need it
27
+ * ignore it. Optional so unit tests can omit it (and assert the guarded
28
+ * fallback) without constructing a full router.
29
+ */
30
+ getMeshForCommand?: (
31
+ meshId: string,
32
+ inlineMesh?: unknown,
33
+ options?: { preferInline?: boolean },
34
+ ) => Promise<ResolvedMeshForCommand>;
15
35
  }
16
36
 
17
37
  export type LowFamilyHandler = (ctx: LowFamilyContext, args: any) => Promise<CommandRouterResult>;