@kontextmind/kxm 0.7.115 → 0.7.118

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.
@@ -0,0 +1,175 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * Interactive Demo for KXM Task & Plan TUI Overlay.
5
+ *
6
+ * Demonstrates:
7
+ * - Collapsible overlay (Ctrl+O or F2 to toggle collapsed strip vs 3-pane view)
8
+ * - Auto-Dispatch toggle (press 'a')
9
+ * - Full Workflow History view (press 'h')
10
+ * - Dual History Export (press 'x' in history view)
11
+ * - Plan Optimizer (press 'o')
12
+ * - Task Reordering & navigation
13
+ */
14
+
15
+ import { ProcessTerminal, TuiAltScreen } from "@earendil-works/pi-tui";
16
+ import { createKxmTuiRegistry } from "../packages/core/tui/dist/index.js";
17
+ import { createKxmTuiOmpOverlay } from "../packages/core/tui/dist/index.js";
18
+ import { createDefaultKxmTuiTheme } from "../packages/core/tui/dist/index.js";
19
+ import { exportWorkflowHistory } from "../packages/core/tui/dist/index.js";
20
+ import { evaluatePlanOptimizations, applyPlanOptimizations } from "../packages/core/tui/dist/index.js";
21
+
22
+ const registry = createKxmTuiRegistry();
23
+
24
+ // Register mock workflow tasks and stages
25
+ registry.register({
26
+ source: "kxm/demo",
27
+ listSections: () => [
28
+ {
29
+ id: "active_stage",
30
+ title: "Stage 2: Implementation (Active)",
31
+ fields: [
32
+ {
33
+ id: "task_1",
34
+ label: "● task_1: Generate PKCE verifier",
35
+ value: "Passed (omp/claude-sonnet) ⏱ 12s",
36
+ status: "saved",
37
+ },
38
+ {
39
+ id: "task_2",
40
+ label: "● task_2: Exchange route /v1/auth/exchange",
41
+ value: "Passed (omp/claude-sonnet) ⏱ 28s",
42
+ status: "saved",
43
+ },
44
+ {
45
+ id: "task_3",
46
+ label: "◐ task_3: Validate refresh rotation",
47
+ value: "Attempt 2/3 (pi/qwen3) ⏱ 14s",
48
+ status: "busy",
49
+ },
50
+ ],
51
+ },
52
+ {
53
+ id: "upcoming_queue",
54
+ title: "Upcoming Tasks & Lookahead",
55
+ fields: [
56
+ {
57
+ id: "task_4",
58
+ label: "◌ task_4: Write unit tests",
59
+ value: "Role: implementer (pi/qwen3) [Requires: task_3]",
60
+ },
61
+ {
62
+ id: "task_5",
63
+ label: "◌ task_5: Document auth endpoints",
64
+ value: "Role: doc-writer (omp/gemini) [Ready]",
65
+ },
66
+ {
67
+ id: "task_6",
68
+ label: "◌ task_6: Security critic audit",
69
+ value: "Role: security-critic (claude) [Requires: task_4]",
70
+ },
71
+ ],
72
+ },
73
+ ],
74
+ handlers: {},
75
+ });
76
+
77
+ const terminal = new ProcessTerminal();
78
+ const tui = new TuiAltScreen(terminal, false, undefined, { mouse: true });
79
+ const theme = createDefaultKxmTuiTheme();
80
+
81
+ let finished = false;
82
+
83
+ const overlay = createKxmTuiOmpOverlay({
84
+ registry,
85
+ tui: {
86
+ requestRender: () => {
87
+ tui.requestRender();
88
+ },
89
+ },
90
+ theme: theme,
91
+ title: "KXM Task & Plan Overlay Demo",
92
+ goal: "Implement OAuth PKCE & Token Refresh (#14)",
93
+ autoDispatch: false,
94
+ onToggleAutoDispatch: (auto) => {
95
+ // notified
96
+ },
97
+ onRunOptimizer: async () => {
98
+ const sampleTasks = [
99
+ {
100
+ id: "task_4",
101
+ title: "Write unit tests",
102
+ stageId: "s2",
103
+ role: "implementer",
104
+ harness: "pi",
105
+ model: "claude-3-5-sonnet",
106
+ dependencies: [],
107
+ category: "test",
108
+ },
109
+ {
110
+ id: "task_5",
111
+ title: "Document auth endpoints",
112
+ stageId: "s2",
113
+ role: "doc-writer",
114
+ harness: "omp",
115
+ model: "claude-3-5-sonnet",
116
+ dependencies: [],
117
+ category: "docs",
118
+ },
119
+ ];
120
+ const result = evaluatePlanOptimizations(sampleTasks);
121
+ // proposal computed
122
+ },
123
+ onExportHistory: async (format) => {
124
+ const sampleEvents = [
125
+ {
126
+ id: "ev_1",
127
+ timestamp: new Date().toISOString(),
128
+ category: "task",
129
+ title: "Generate PKCE verifier",
130
+ status: "passed",
131
+ role: "implementer",
132
+ harness: "omp",
133
+ model: "claude-sonnet",
134
+ durationMs: 12000,
135
+ costUsd: 0.018,
136
+ artifacts: ["src/auth/pkce.ts"],
137
+ },
138
+ {
139
+ id: "ev_2",
140
+ timestamp: new Date().toISOString(),
141
+ category: "task",
142
+ title: "Validate refresh rotation",
143
+ status: "passed",
144
+ role: "implementer",
145
+ harness: "pi",
146
+ model: "qwen3-coder",
147
+ durationMs: 14000,
148
+ costUsd: 0.003,
149
+ },
150
+ ];
151
+ return exportWorkflowHistory("run_demo_8f3a", sampleEvents, ".kxm/assets/retrospectives");
152
+ },
153
+ done: () => {
154
+ finished = true;
155
+ tui.stop();
156
+ process.exit(0);
157
+ },
158
+ });
159
+
160
+ tui.start({
161
+ render: (width) => overlay.render(width),
162
+ handleInput: (data) => {
163
+ // q to quit demo
164
+ if (data === "q" || data === "\x03") {
165
+ overlay.dispose();
166
+ return;
167
+ }
168
+ overlay.handleInput(data);
169
+ },
170
+ invalidate: () => overlay.invalidate(),
171
+ });
172
+
173
+ process.on("SIGINT", () => {
174
+ overlay.dispose();
175
+ });