@thispointon/kondi-chat 0.1.2

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 (108) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +556 -0
  3. package/bin/kondi-chat +56 -0
  4. package/bin/kondi-chat.js +72 -0
  5. package/package.json +55 -0
  6. package/scripts/demo.tape +49 -0
  7. package/scripts/postinstall.cjs +103 -0
  8. package/src/audit/analytics.ts +261 -0
  9. package/src/audit/ledger.ts +253 -0
  10. package/src/audit/telemetry.ts +165 -0
  11. package/src/cli/backend.ts +675 -0
  12. package/src/cli/commands.ts +419 -0
  13. package/src/cli/help.ts +182 -0
  14. package/src/cli/submit-helpers.ts +159 -0
  15. package/src/cli/submit.ts +539 -0
  16. package/src/cli/wizard.ts +121 -0
  17. package/src/context/bootstrap.ts +138 -0
  18. package/src/context/budget.ts +100 -0
  19. package/src/context/manager.ts +666 -0
  20. package/src/context/memory.ts +160 -0
  21. package/src/context/preflight.ts +176 -0
  22. package/src/context/project-brain.ts +101 -0
  23. package/src/context/receipts.ts +108 -0
  24. package/src/context/skills.ts +154 -0
  25. package/src/context/symbol-index.ts +240 -0
  26. package/src/council/profiles.ts +137 -0
  27. package/src/council/tool.ts +138 -0
  28. package/src/council-engine/cli/council-artifacts.ts +230 -0
  29. package/src/council-engine/cli/council-config.ts +178 -0
  30. package/src/council-engine/cli/council-session-export.ts +116 -0
  31. package/src/council-engine/cli/kondi.ts +98 -0
  32. package/src/council-engine/cli/llm-caller.ts +229 -0
  33. package/src/council-engine/cli/localStorage-shim.ts +119 -0
  34. package/src/council-engine/cli/node-platform.ts +68 -0
  35. package/src/council-engine/cli/run-council.ts +481 -0
  36. package/src/council-engine/cli/run-pipeline.ts +772 -0
  37. package/src/council-engine/cli/session-export.ts +153 -0
  38. package/src/council-engine/configs/councils/analysis.json +101 -0
  39. package/src/council-engine/configs/councils/code-planning.json +86 -0
  40. package/src/council-engine/configs/councils/coding.json +89 -0
  41. package/src/council-engine/configs/councils/debate.json +97 -0
  42. package/src/council-engine/configs/councils/solo-claude.json +34 -0
  43. package/src/council-engine/configs/councils/solo-gpt.json +34 -0
  44. package/src/council-engine/council/coding-orchestrator.ts +1205 -0
  45. package/src/council-engine/council/context-bootstrap.ts +147 -0
  46. package/src/council-engine/council/context-inspection.ts +42 -0
  47. package/src/council-engine/council/context-store.ts +763 -0
  48. package/src/council-engine/council/deliberation-orchestrator.ts +2762 -0
  49. package/src/council-engine/council/factory.ts +164 -0
  50. package/src/council-engine/council/index.ts +201 -0
  51. package/src/council-engine/council/ledger-store.ts +438 -0
  52. package/src/council-engine/council/prompts.ts +1689 -0
  53. package/src/council-engine/council/storage-cleanup.ts +164 -0
  54. package/src/council-engine/council/store.ts +1110 -0
  55. package/src/council-engine/council/synthesis.ts +291 -0
  56. package/src/council-engine/council/types.ts +845 -0
  57. package/src/council-engine/council/validation.ts +613 -0
  58. package/src/council-engine/pipeline/build-detect.ts +73 -0
  59. package/src/council-engine/pipeline/executor.ts +1048 -0
  60. package/src/council-engine/pipeline/index.ts +9 -0
  61. package/src/council-engine/pipeline/install-detect.ts +84 -0
  62. package/src/council-engine/pipeline/memory-store.ts +182 -0
  63. package/src/council-engine/pipeline/output-parsers.ts +146 -0
  64. package/src/council-engine/pipeline/run-output.ts +149 -0
  65. package/src/council-engine/pipeline/session-import.ts +177 -0
  66. package/src/council-engine/pipeline/store.ts +753 -0
  67. package/src/council-engine/pipeline/test-detect.ts +82 -0
  68. package/src/council-engine/pipeline/types.ts +401 -0
  69. package/src/council-engine/services/deliberationSummary.ts +114 -0
  70. package/src/council-engine/tsconfig.json +16 -0
  71. package/src/council-engine/types/mcp.ts +122 -0
  72. package/src/council-engine/utils/filterTools.ts +73 -0
  73. package/src/engine/apply.ts +238 -0
  74. package/src/engine/checkpoints.ts +237 -0
  75. package/src/engine/consultants.ts +347 -0
  76. package/src/engine/diff.ts +171 -0
  77. package/src/engine/errors.ts +102 -0
  78. package/src/engine/git-tools.ts +246 -0
  79. package/src/engine/hooks.ts +181 -0
  80. package/src/engine/loop-guard.ts +155 -0
  81. package/src/engine/permissions.ts +293 -0
  82. package/src/engine/pipeline.ts +376 -0
  83. package/src/engine/sub-agents.ts +133 -0
  84. package/src/engine/task-card.ts +185 -0
  85. package/src/engine/task-router.ts +256 -0
  86. package/src/engine/task-store.ts +86 -0
  87. package/src/engine/tools.ts +783 -0
  88. package/src/engine/verify.ts +111 -0
  89. package/src/mcp/client.ts +225 -0
  90. package/src/mcp/config.ts +120 -0
  91. package/src/mcp/tool-manager.ts +192 -0
  92. package/src/mcp/types.ts +61 -0
  93. package/src/providers/llm-caller.ts +943 -0
  94. package/src/providers/rate-limiter.ts +238 -0
  95. package/src/router/NOTES.md +28 -0
  96. package/src/router/collector.ts +474 -0
  97. package/src/router/embeddings.ts +286 -0
  98. package/src/router/index.ts +299 -0
  99. package/src/router/intent-router.ts +225 -0
  100. package/src/router/nn-router.ts +205 -0
  101. package/src/router/profiles.ts +309 -0
  102. package/src/router/registry.ts +565 -0
  103. package/src/router/rules.ts +274 -0
  104. package/src/router/train.py +408 -0
  105. package/src/session/store.ts +211 -0
  106. package/src/test-utils/mock-llm.ts +39 -0
  107. package/src/types.ts +322 -0
  108. package/src/web/manager.ts +311 -0
@@ -0,0 +1,164 @@
1
+ /**
2
+ * Council: Data Store
3
+ * In-memory primary storage for all council artifact data (context, ledger, patches, etc.).
4
+ *
5
+ * This mirrors the CLI's localStorage-shim pattern: an in-memory Map that has
6
+ * no size limit. localStorage is used as a best-effort cache for same-session
7
+ * UI observation — quota errors are silently ignored because the authoritative
8
+ * data lives in the Map.
9
+ *
10
+ * This gives each council true storage isolation:
11
+ * - Councils never compete for the same 5MB localStorage pool.
12
+ * - One council's data can never crowd out another's.
13
+ * - Pipeline executions finish every time, regardless of how many councils run.
14
+ *
15
+ * Deliberation history is NEVER destroyed. The pipeline executor saves full
16
+ * deliberation output to disk via `platform.saveDeliberationOutput()` for
17
+ * long-term preservation.
18
+ */
19
+
20
+ // ============================================================================
21
+ // In-Memory Data Store (primary authority for council artifact data)
22
+ // ============================================================================
23
+
24
+ const MAX_ENTRIES = 10000;
25
+
26
+ class CouncilDataStore {
27
+ private cache = new Map<string, string>();
28
+
29
+ getItem(key: string): string | null {
30
+ // Primary: in-memory cache
31
+ const cached = this.cache.get(key);
32
+ if (cached !== undefined) {
33
+ // Move to end for LRU ordering
34
+ this.cache.delete(key);
35
+ this.cache.set(key, cached);
36
+ return cached;
37
+ }
38
+
39
+ // Fallback: localStorage (picks up data from prior sessions / initial load)
40
+ try {
41
+ const val = localStorage.getItem(key);
42
+ if (val !== null) {
43
+ this.cache.set(key, val); // promote to in-memory
44
+ return val;
45
+ }
46
+ } catch { /* ignore */ }
47
+
48
+ return null;
49
+ }
50
+
51
+ setItem(key: string, value: string): void {
52
+ // Evict oldest entries if at capacity
53
+ if (!this.cache.has(key) && this.cache.size >= MAX_ENTRIES) {
54
+ const oldest = this.cache.keys().next().value;
55
+ if (oldest !== undefined) this.cache.delete(oldest);
56
+ }
57
+ this.cache.set(key, value);
58
+
59
+ // Secondary: best-effort localStorage mirror for UI observation.
60
+ // Quota errors are harmless because the data is safe in memory.
61
+ try {
62
+ localStorage.setItem(key, value);
63
+ } catch {
64
+ // Silently ignore — data is authoritative in the Map.
65
+ // This is the normal path once localStorage fills up.
66
+ }
67
+ }
68
+
69
+ removeItem(key: string): void {
70
+ this.cache.delete(key);
71
+ try { localStorage.removeItem(key); } catch { /* ignore */ }
72
+ }
73
+
74
+ /**
75
+ * Persistent save: same as setItem but throws on localStorage failure.
76
+ * Used for data that MUST survive app restarts (e.g. pipeline definitions).
77
+ */
78
+ setItemPersistent(key: string, value: string): void {
79
+ this.cache.set(key, value);
80
+ localStorage.setItem(key, value);
81
+ }
82
+
83
+ /**
84
+ * Number of keys in the merged view (in-memory + localStorage).
85
+ * Used by stores that iterate over keys.
86
+ */
87
+ get length(): number {
88
+ return this.allKeys().length;
89
+ }
90
+
91
+ /**
92
+ * Get key at index in the merged view.
93
+ */
94
+ key(index: number): string | null {
95
+ const keys = this.allKeys();
96
+ return keys[index] ?? null;
97
+ }
98
+
99
+ /**
100
+ * Merged set of all keys from both in-memory cache and localStorage.
101
+ */
102
+ private allKeys(): string[] {
103
+ const keys = new Set<string>();
104
+ for (const k of this.cache.keys()) keys.add(k);
105
+ try {
106
+ for (let i = 0; i < localStorage.length; i++) {
107
+ const k = localStorage.key(i);
108
+ if (k) keys.add(k);
109
+ }
110
+ } catch { /* ignore */ }
111
+ return [...keys];
112
+ }
113
+ }
114
+
115
+ // Singleton — all council stores share this instance
116
+ export const councilDataStore = new CouncilDataStore();
117
+
118
+ // ============================================================================
119
+ // Convenience wrappers (used by context-store, ledger-store)
120
+ // ============================================================================
121
+
122
+ /**
123
+ * Save to the council data store. Never throws.
124
+ * The old `saveWithRetry` escalated cleanup and could still throw.
125
+ * This version always succeeds because the in-memory Map has no quota.
126
+ */
127
+ export function saveWithRetry(key: string, data: string, _activeCouncilId?: string): void {
128
+ councilDataStore.setItem(key, data);
129
+ }
130
+
131
+ /**
132
+ * Strip a completed council in the mcp-councils localStorage key.
133
+ * Removes messages and deliberationState to keep the mcp-councils key small.
134
+ * The full deliberation data is preserved in memory and saved to disk.
135
+ */
136
+ export function stripCompletedCouncil(councilId: string): void {
137
+ try {
138
+ const raw = localStorage.getItem('mcp-councils');
139
+ if (!raw) return;
140
+ const data = JSON.parse(raw);
141
+ if (!data.councils || !Array.isArray(data.councils)) return;
142
+
143
+ const idx = data.councils.findIndex((c: any) => c.id === councilId);
144
+ if (idx === -1) return;
145
+
146
+ const council = data.councils[idx];
147
+ // Strip large fields from the localStorage copy only.
148
+ // The authoritative data remains in the in-memory store.
149
+ council.messages = [];
150
+ council.deliberationState = undefined;
151
+ if (council.sharedContext) {
152
+ council.sharedContext.data = undefined;
153
+ council.sharedContext.documents = [];
154
+ }
155
+
156
+ data.councils[idx] = council;
157
+ data.lastUpdated = new Date().toISOString();
158
+ localStorage.setItem('mcp-councils', JSON.stringify(data));
159
+ console.log(`[CouncilDataStore] Stripped localStorage copy of council ${councilId.slice(0, 8)}`);
160
+ } catch (err) {
161
+ // Non-fatal — localStorage is just a cache
162
+ console.warn('[CouncilDataStore] Failed to strip council in localStorage:', err);
163
+ }
164
+ }