@stackmemoryai/stackmemory 1.12.0 → 1.14.0

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 (162) hide show
  1. package/LICENSE +131 -64
  2. package/README.md +3 -1
  3. package/bin/claude-sm +16 -1
  4. package/bin/claude-smd +16 -1
  5. package/bin/codex-smd +16 -1
  6. package/bin/gemini-sm +16 -1
  7. package/bin/hermes-sm +21 -0
  8. package/bin/hermes-smd +21 -0
  9. package/bin/opencode-sm +16 -1
  10. package/dist/src/cli/codex-sm.js +51 -11
  11. package/dist/src/cli/commands/brain.js +206 -0
  12. package/dist/src/cli/commands/company-os.js +184 -0
  13. package/dist/src/cli/commands/context.js +5 -0
  14. package/dist/src/cli/commands/operator.js +127 -0
  15. package/dist/src/cli/commands/orchestrate.js +2 -0
  16. package/dist/src/cli/commands/orchestrator.js +3 -2
  17. package/dist/src/cli/commands/patterns.js +254 -0
  18. package/dist/src/cli/commands/portal.js +161 -0
  19. package/dist/src/cli/commands/scaffold.js +92 -0
  20. package/dist/src/cli/commands/setup.js +1 -4
  21. package/dist/src/cli/commands/sync.js +253 -0
  22. package/dist/src/cli/commands/tasks.js +130 -1
  23. package/dist/src/cli/commands/vision.js +221 -0
  24. package/dist/src/cli/hermes-sm.js +224 -0
  25. package/dist/src/cli/index.js +15 -10
  26. package/dist/src/cli/utils/real-cli-bin.js +72 -0
  27. package/dist/src/core/brain/brain-store.js +187 -0
  28. package/dist/src/core/brain/brain-sync.js +193 -0
  29. package/dist/src/core/brain/index.js +78 -0
  30. package/dist/src/core/brain/types.js +10 -0
  31. package/dist/src/core/cache/token-estimator.js +24 -1
  32. package/dist/src/core/config/feature-flags.js +2 -6
  33. package/dist/src/core/context/frame-database.js +44 -0
  34. package/dist/src/core/context/recursive-context-manager.js +1 -1
  35. package/dist/src/core/context/rehydration.js +2 -1
  36. package/dist/src/core/database/sqlite-adapter.js +14 -1
  37. package/dist/src/core/models/model-router.js +33 -1
  38. package/dist/src/core/models/provider-pricing.js +58 -4
  39. package/dist/src/core/patterns/index.js +22 -0
  40. package/dist/src/core/patterns/pattern-applier.js +39 -0
  41. package/dist/src/core/patterns/pattern-observer.js +157 -0
  42. package/dist/src/core/patterns/pattern-store.js +259 -0
  43. package/dist/src/core/patterns/types.js +19 -0
  44. package/dist/src/core/retrieval/llm-context-retrieval.js +5 -4
  45. package/dist/src/core/retrieval/unified-context-assembler.js +11 -66
  46. package/dist/src/core/skill-packs/types.js +14 -1
  47. package/dist/src/core/storage/cloud-sync-manager.js +116 -0
  48. package/dist/src/core/storage/cloud-sync.js +574 -0
  49. package/dist/src/core/storage/two-tier-storage.js +5 -1
  50. package/dist/src/core/tasks/master-tasks-template.js +43 -0
  51. package/dist/src/core/tasks/md-task-parser.js +138 -0
  52. package/dist/src/core/vision/index.js +27 -0
  53. package/dist/src/core/vision/signals.js +79 -0
  54. package/dist/src/core/vision/types.js +22 -0
  55. package/dist/src/core/vision/vision-file.js +146 -0
  56. package/dist/src/core/vision/vision-loop.js +220 -0
  57. package/dist/src/core/wiki/wiki-compiler.js +103 -1
  58. package/dist/src/daemon/daemon-config.js +45 -0
  59. package/dist/src/daemon/services/desire-path-service.js +566 -0
  60. package/dist/src/daemon/services/research-stream-service.js +320 -0
  61. package/dist/src/daemon/services/telemetry-service.js +192 -0
  62. package/dist/src/daemon/unified-daemon.js +28 -1
  63. package/dist/src/features/browser/cli-browser-agent.js +417 -0
  64. package/dist/src/features/browser/stagehand-workflows.js +578 -0
  65. package/dist/src/features/operator/adapter-factory.js +62 -0
  66. package/dist/src/features/operator/browser-adapter.js +109 -0
  67. package/dist/src/features/operator/desktop-adapter.js +125 -0
  68. package/dist/src/features/operator/index.js +39 -0
  69. package/dist/src/features/operator/llm-decision.js +137 -0
  70. package/dist/src/features/operator/operator-logger.js +92 -0
  71. package/dist/src/features/operator/overnight-runner.js +327 -0
  72. package/dist/src/features/operator/screen-adapter.js +91 -0
  73. package/dist/src/features/operator/session-manager.js +127 -0
  74. package/dist/src/features/operator/state-machine.js +227 -0
  75. package/dist/src/features/operator/task-queue.js +81 -0
  76. package/dist/src/features/portal/index.js +26 -0
  77. package/dist/src/features/portal/server.js +240 -0
  78. package/dist/src/features/portal/types.js +14 -0
  79. package/dist/src/features/portal/ui.js +195 -0
  80. package/dist/src/features/tasks/task-aware-context.js +2 -1
  81. package/dist/src/features/tui/simple-monitor.js +0 -23
  82. package/dist/src/features/tui/swarm-monitor.js +8 -66
  83. package/dist/src/{integrations/diffmem/index.js → features/web/client/hooks/use-socket.js} +6 -5
  84. package/dist/src/features/web/client/lib/utils.js +12 -0
  85. package/dist/src/features/web/client/stores/session-store.js +12 -0
  86. package/dist/src/features/web/server/gcp-billing.js +76 -0
  87. package/dist/src/features/web/server/index.js +10 -0
  88. package/dist/src/features/web/server/spend-calculator.js +228 -0
  89. package/dist/src/hooks/schemas.js +4 -1
  90. package/dist/src/integrations/anthropic/client.js +3 -2
  91. package/dist/src/integrations/claude-code/agent-bridge.js +0 -3
  92. package/dist/src/integrations/claude-code/subagent-client.js +218 -11
  93. package/dist/src/integrations/claude-code/task-coordinator.js +2 -1
  94. package/dist/src/integrations/linear/webhook-retry.js +196 -0
  95. package/dist/src/integrations/linear/webhook-server.js +18 -22
  96. package/dist/src/integrations/mcp/handlers/cloud-sync-handlers.js +101 -0
  97. package/dist/src/integrations/mcp/handlers/index.js +27 -52
  98. package/dist/src/integrations/mcp/server.js +122 -335
  99. package/dist/src/integrations/mcp/tool-alias-registry.js +0 -73
  100. package/dist/src/integrations/mcp/tool-definitions.js +111 -510
  101. package/dist/src/mcp/stackmemory-mcp-server.js +404 -379
  102. package/dist/src/orchestrators/multimodal/determinism.js +2 -1
  103. package/dist/src/orchestrators/multimodal/harness.js +2 -1
  104. package/dist/src/skills/recursive-agent-orchestrator.js +2 -4
  105. package/dist/src/utils/process-cleanup.js +1 -7
  106. package/docs/README.md +42 -0
  107. package/docs/guides/README_INSTALL.md +208 -0
  108. package/package.json +18 -9
  109. package/scripts/claude-code-wrapper.sh +11 -0
  110. package/scripts/claude-sm-setup.sh +12 -1
  111. package/scripts/codex-wrapper.sh +11 -0
  112. package/scripts/git-hooks/branch-context-manager.sh +11 -0
  113. package/scripts/git-hooks/post-checkout-stackmemory.sh +11 -0
  114. package/scripts/git-hooks/post-commit-stackmemory.sh +11 -0
  115. package/scripts/git-hooks/pre-commit-stackmemory.sh +11 -0
  116. package/scripts/hooks/cleanup-shell.sh +12 -1
  117. package/scripts/hooks/task-complete.sh +12 -1
  118. package/scripts/install-code-execution-hooks.sh +12 -1
  119. package/scripts/install-sweep-hook.sh +12 -0
  120. package/scripts/install.sh +11 -0
  121. package/scripts/opencode-wrapper.sh +11 -0
  122. package/scripts/portal/cloud-init.yaml +69 -0
  123. package/scripts/portal/setup.sh +69 -0
  124. package/scripts/portal/stackmemory-portal.service +34 -0
  125. package/scripts/setup-claude-integration.sh +12 -1
  126. package/scripts/smoke-init-db.sh +23 -0
  127. package/scripts/stackmemory-daemon.sh +11 -0
  128. package/scripts/verify-dist.cjs +11 -4
  129. package/dist/src/cli/commands/ralph.js +0 -1053
  130. package/dist/src/hooks/diffmem-hooks.js +0 -376
  131. package/dist/src/integrations/diffmem/client.js +0 -208
  132. package/dist/src/integrations/diffmem/config.js +0 -14
  133. package/dist/src/integrations/greptile/client.js +0 -101
  134. package/dist/src/integrations/greptile/config.js +0 -14
  135. package/dist/src/integrations/greptile/index.js +0 -11
  136. package/dist/src/integrations/mcp/handlers/cross-search-handlers.js +0 -188
  137. package/dist/src/integrations/mcp/handlers/diffmem-handlers.js +0 -455
  138. package/dist/src/integrations/mcp/handlers/greptile-handlers.js +0 -456
  139. package/dist/src/integrations/mcp/handlers/provider-handlers.js +0 -227
  140. package/dist/src/integrations/ralph/bridge/ralph-stackmemory-bridge.js +0 -863
  141. package/dist/src/integrations/ralph/context/context-budget-manager.js +0 -308
  142. package/dist/src/integrations/ralph/context/stackmemory-context-loader.js +0 -354
  143. package/dist/src/integrations/ralph/index.js +0 -17
  144. package/dist/src/integrations/ralph/learning/pattern-learner.js +0 -416
  145. package/dist/src/integrations/ralph/lifecycle/iteration-lifecycle.js +0 -448
  146. package/dist/src/integrations/ralph/loopmax.js +0 -488
  147. package/dist/src/integrations/ralph/monitoring/swarm-dashboard.js +0 -293
  148. package/dist/src/integrations/ralph/monitoring/swarm-registry.js +0 -107
  149. package/dist/src/integrations/ralph/orchestration/multi-loop-orchestrator.js +0 -508
  150. package/dist/src/integrations/ralph/patterns/compounding-engineering-pattern.js +0 -407
  151. package/dist/src/integrations/ralph/patterns/extended-coherence-sessions.js +0 -495
  152. package/dist/src/integrations/ralph/patterns/oracle-worker-pattern.js +0 -387
  153. package/dist/src/integrations/ralph/performance/performance-optimizer.js +0 -357
  154. package/dist/src/integrations/ralph/recovery/crash-recovery.js +0 -461
  155. package/dist/src/integrations/ralph/state/state-reconciler.js +0 -420
  156. package/dist/src/integrations/ralph/swarm/git-workflow-manager.js +0 -444
  157. package/dist/src/integrations/ralph/swarm/swarm-coordinator.js +0 -1005
  158. package/dist/src/integrations/ralph/visualization/ralph-debugger.js +0 -635
  159. package/scripts/ralph-loop-implementation.js +0 -404
  160. /package/dist/src/{integrations/diffmem/types.js → core/storage/cloud-sync-types.js} +0 -0
  161. /package/dist/src/{integrations/greptile → features/operator}/types.js +0 -0
  162. /package/dist/src/{integrations/ralph/types.js → features/web/client/next-env.d.js} +0 -0
package/LICENSE CHANGED
@@ -1,64 +1,131 @@
1
- Business Source License 1.1
2
-
3
- Parameters
4
-
5
- Licensor: StackMemory AI
6
- Licensed Work: StackMemory v1.0.0
7
- The Licensed Work is (c) 2026 StackMemory AI
8
- Additional Use Grant: You may make production use of the Licensed Work,
9
- provided such use does not include offering the
10
- Licensed Work to third parties on a hosted or
11
- embedded basis which is competitive with StackMemory
12
- AI's products.
13
- Change Date: 2030-02-10
14
- Change License: MIT
15
-
16
- For information about alternative licensing arrangements for the Licensed
17
- Work, please contact: hello@stackmemory.ai
18
-
19
- Notice
20
-
21
- Business Source License 1.1
22
-
23
- Terms
24
-
25
- The Licensor hereby grants you the right to copy, modify, create
26
- derivative works, redistribute, and make non-production use of the
27
- Licensed Work. The Licensor may make an Additional Use Grant, above,
28
- permitting limited production use.
29
-
30
- Effective on the Change Date, or the fourth anniversary of the first
31
- publicly available distribution of a specific version of the Licensed
32
- Work under this License, whichever comes first, the Licensor hereby
33
- grants you rights under the terms of the Change License, and the rights
34
- granted in the paragraph above terminate.
35
-
36
- If your use of the Licensed Work does not comply with the requirements
37
- currently in effect as described in this License, you must purchase a
38
- commercial license from the Licensor, its affiliated entities, or
39
- authorized resellers, or you must refrain from using the Licensed Work.
40
-
41
- All copies of the original and modified Licensed Work, and derivative
42
- works of the Licensed Work, are subject to this License. This License
43
- applies separately for each version of the Licensed Work and the Change
44
- Date may vary for each version of the Licensed Work released by
45
- Licensor.
46
-
47
- You must conspicuously display this License on each original or modified
48
- copy of the Licensed Work. If you receive the Licensed Work in original
49
- or modified form from a third party, the terms and conditions set forth
50
- in this License apply to your use of that work.
51
-
52
- Any use of the Licensed Work in violation of this License will
53
- automatically terminate your rights under this License for the current
54
- and all other versions of the Licensed Work.
55
-
56
- This License does not grant you any right in any trademark or logo of
57
- Licensor or its affiliates (provided that you may use a trademark or
58
- logo of Licensor as expressly required by this License).
59
-
60
- TO THE EXTENT PERMITTED BY APPLICABLE LAW, THE LICENSED WORK IS
61
- PROVIDED ON AN "AS IS" BASIS. LICENSOR HEREBY DISCLAIMS ALL WARRANTIES
62
- AND CONDITIONS, EXPRESS OR IMPLIED, INCLUDING (WITHOUT LIMITATION)
63
- WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE,
64
- NON-INFRINGEMENT, AND TITLE.
1
+ PolyForm Noncommercial License 1.0.0
2
+
3
+ https://polyformproject.org/licenses/noncommercial/1.0.0
4
+
5
+ Acceptance
6
+
7
+ In order to get any license under these terms, you must agree
8
+ to them as both strict obligations and conditions to all
9
+ your licenses.
10
+
11
+ Copyright License
12
+
13
+ The licensor grants you a copyright license for the
14
+ software to do everything you might do with the software
15
+ that would otherwise infringe the licensor's copyright
16
+ in it for any permitted purpose. However, you may
17
+ only distribute the software according to Distribution
18
+ License and make changes or new works
19
+ based on the software according to Changes and New Works
20
+ License.
21
+
22
+ Distribution License
23
+
24
+ The licensor grants you an additional copyright license
25
+ to distribute copies of the software. Your license
26
+ to distribute covers distributing the software with
27
+ changes and new works permitted by Changes and New Works
28
+ License.
29
+
30
+ Notices
31
+
32
+ You must ensure that anyone who gets a copy of any part of
33
+ the software from you also gets a copy of these terms or the
34
+ URL for them above, as well as copies of any plain-text lines
35
+ beginning with `Required Notice:` that the licensor provided
36
+ with the software. For example:
37
+
38
+ > Required Notice: Copyright StackMemory AI (https://stackmemory.ai)
39
+
40
+ Changes and New Works License
41
+
42
+ The licensor grants you an additional copyright license to
43
+ make changes and new works based on the software for any
44
+ permitted purpose.
45
+
46
+ Patent License
47
+
48
+ The licensor grants you a patent license for the software that
49
+ covers patent claims the licensor can license, or becomes able
50
+ to license, that you would infringe by using the software.
51
+
52
+ Noncommercial Purposes
53
+
54
+ Any noncommercial purpose is a permitted purpose.
55
+
56
+ Personal Uses
57
+
58
+ Personal use for research, experiment, and testing for
59
+ the benefit of public knowledge, personal study, private
60
+ entertainment, hobby projects, amateur pursuits, or religious
61
+ observance, without any anticipated commercial application,
62
+ is use for a permitted purpose.
63
+
64
+ Noncommercial Organizations
65
+
66
+ Use by any charitable organization, educational institution,
67
+ public research organization, public safety or health
68
+ organization, environmental protection organization,
69
+ or government institution is use for a permitted purpose
70
+ regardless of the source of funding or obligations resulting
71
+ from the funding.
72
+
73
+ Fair Use
74
+
75
+ You may have "fair use" rights for the software under the
76
+ law. These terms do not limit them.
77
+
78
+ No Other Rights
79
+
80
+ These terms do not allow you to sublicense or transfer any of
81
+ your licenses to anyone else, or prevent the licensor from
82
+ granting licenses to anyone else. These terms do not imply
83
+ any other licenses.
84
+
85
+ Patent Defense
86
+
87
+ If you make any written claim that the software infringes or
88
+ contributes to infringement of any patent, your patent license
89
+ for the software granted under these terms ends immediately. If
90
+ your company makes such a claim, your patent license ends
91
+ immediately for work on behalf of your company.
92
+
93
+ Violations
94
+
95
+ The first time you are notified in writing that you have
96
+ violated any of these terms, or done anything with the software
97
+ not covered by your licenses, your licenses can nonetheless
98
+ continue if you come into full compliance with these terms,
99
+ and take practical steps to correct past violations, within
100
+ 32 days of receiving notice. Otherwise, all your licenses
101
+ end immediately.
102
+
103
+ No Liability
104
+
105
+ As far as the law allows, the software comes as is, without
106
+ any warranty or condition, and the licensor will not be liable
107
+ to you for any damages arising out of these terms or the use
108
+ or nature of the software, under any kind of legal claim.
109
+
110
+ Definitions
111
+
112
+ The licensor is the individual or entity offering these
113
+ terms, and the software is the software the licensor makes
114
+ available under these terms.
115
+
116
+ You refers to the individual or entity agreeing to these
117
+ terms.
118
+
119
+ Your company is any legal entity, sole proprietorship,
120
+ or other kind of organization that you work for, plus all
121
+ organizations that have control over, are under the control of,
122
+ or are under common control with that organization. Control
123
+ means ownership of substantially all the assets of an entity,
124
+ or the power to direct its management and policies by vote,
125
+ contract, or otherwise. Control can be direct or indirect.
126
+
127
+ Your licenses are all the licenses granted to you for the
128
+ software under these terms.
129
+
130
+ Use means anything you do with the software requiring one
131
+ of your licenses.
package/README.md CHANGED
@@ -512,4 +512,6 @@ Grounded in distributed systems theory: FLP impossibility, Byzantine→Crash con
512
512
 
513
513
  ## License
514
514
 
515
- Licensed under the [Business Source License 1.1](./LICENSE). You can use, modify, and self-host StackMemory freely. The one restriction: you may not offer it as a competing hosted service. The license converts to MIT after 4 years per release.
515
+ Licensed under the [PolyForm Noncommercial License 1.0.0](./LICENSE).
516
+
517
+ Free for personal, research, educational, and noncommercial use. Commercial use requires a separate license from StackMemory AI.
package/bin/claude-sm CHANGED
@@ -3,4 +3,19 @@
3
3
  * Claude-SM CLI Launcher (ESM)
4
4
  * Delegates to built CLI in dist without requiring tsx.
5
5
  */
6
- import('../dist/src/cli/claude-sm.js');
6
+ import { existsSync } from 'fs';
7
+ import { fileURLToPath } from 'url';
8
+ import { dirname, join } from 'path';
9
+
10
+ const __filename = fileURLToPath(import.meta.url);
11
+ const __dirname = dirname(__filename);
12
+ const target = join(__dirname, '../dist/src/cli/claude-sm.js');
13
+
14
+ if (!existsSync(target)) {
15
+ console.error('Error: StackMemory has not been built.');
16
+ console.error(`Missing: ${target}`);
17
+ console.error('Run: npm install && npm run build');
18
+ process.exit(1);
19
+ }
20
+
21
+ import(target);
package/bin/claude-smd CHANGED
@@ -3,4 +3,19 @@
3
3
  * Claude-SM-Danger CLI Launcher (ESM)
4
4
  * Delegates to built CLI in dist without requiring tsx.
5
5
  */
6
- import('../dist/src/cli/claude-sm-danger.js');
6
+ import { existsSync } from 'fs';
7
+ import { fileURLToPath } from 'url';
8
+ import { dirname, join } from 'path';
9
+
10
+ const __filename = fileURLToPath(import.meta.url);
11
+ const __dirname = dirname(__filename);
12
+ const target = join(__dirname, '../dist/src/cli/claude-sm-danger.js');
13
+
14
+ if (!existsSync(target)) {
15
+ console.error('Error: StackMemory has not been built.');
16
+ console.error(`Missing: ${target}`);
17
+ console.error('Run: npm install && npm run build');
18
+ process.exit(1);
19
+ }
20
+
21
+ import(target);
package/bin/codex-smd CHANGED
@@ -3,4 +3,19 @@
3
3
  * Codex-SM-Danger CLI Launcher (ESM)
4
4
  * Delegates to built CLI in dist without requiring tsx.
5
5
  */
6
- import('../dist/src/cli/codex-sm-danger.js');
6
+ import { existsSync } from 'fs';
7
+ import { fileURLToPath } from 'url';
8
+ import { dirname, join } from 'path';
9
+
10
+ const __filename = fileURLToPath(import.meta.url);
11
+ const __dirname = dirname(__filename);
12
+ const target = join(__dirname, '../dist/src/cli/codex-sm-danger.js');
13
+
14
+ if (!existsSync(target)) {
15
+ console.error('Error: StackMemory has not been built.');
16
+ console.error(`Missing: ${target}`);
17
+ console.error('Run: npm install && npm run build');
18
+ process.exit(1);
19
+ }
20
+
21
+ import(target);
package/bin/gemini-sm CHANGED
@@ -3,4 +3,19 @@
3
3
  * Gemini-SM CLI Launcher (ESM)
4
4
  * Delegates to built CLI in dist without requiring tsx.
5
5
  */
6
- import('../dist/src/cli/gemini-sm.js');
6
+ import { existsSync } from 'fs';
7
+ import { fileURLToPath } from 'url';
8
+ import { dirname, join } from 'path';
9
+
10
+ const __filename = fileURLToPath(import.meta.url);
11
+ const __dirname = dirname(__filename);
12
+ const target = join(__dirname, '../dist/src/cli/gemini-sm.js');
13
+
14
+ if (!existsSync(target)) {
15
+ console.error('Error: StackMemory has not been built.');
16
+ console.error(`Missing: ${target}`);
17
+ console.error('Run: npm install && npm run build');
18
+ process.exit(1);
19
+ }
20
+
21
+ import(target);
package/bin/hermes-sm ADDED
@@ -0,0 +1,21 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Hermes-SM CLI Launcher (ESM)
4
+ * Delegates to built CLI in dist without requiring tsx.
5
+ */
6
+ import { existsSync } from 'fs';
7
+ import { fileURLToPath } from 'url';
8
+ import { dirname, join } from 'path';
9
+
10
+ const __filename = fileURLToPath(import.meta.url);
11
+ const __dirname = dirname(__filename);
12
+ const target = join(__dirname, '../dist/src/cli/hermes-sm.js');
13
+
14
+ if (!existsSync(target)) {
15
+ console.error('Error: StackMemory has not been built.');
16
+ console.error(`Missing: ${target}`);
17
+ console.error('Run: npm install && npm run build');
18
+ process.exit(1);
19
+ }
20
+
21
+ import(target);
package/bin/hermes-smd ADDED
@@ -0,0 +1,21 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Hermes-SM-Danger CLI Launcher (ESM) — danger mode
4
+ * Delegates to built CLI in dist without requiring tsx.
5
+ */
6
+ import { existsSync } from 'fs';
7
+ import { fileURLToPath } from 'url';
8
+ import { dirname, join } from 'path';
9
+
10
+ const __filename = fileURLToPath(import.meta.url);
11
+ const __dirname = dirname(__filename);
12
+ const target = join(__dirname, '../dist/src/cli/hermes-sm.js');
13
+
14
+ if (!existsSync(target)) {
15
+ console.error('Error: StackMemory has not been built.');
16
+ console.error(`Missing: ${target}`);
17
+ console.error('Run: npm install && npm run build');
18
+ process.exit(1);
19
+ }
20
+
21
+ import(target);
package/bin/opencode-sm CHANGED
@@ -3,4 +3,19 @@
3
3
  * OpenCode-SM CLI Launcher (ESM)
4
4
  * Delegates to built CLI in dist without requiring tsx.
5
5
  */
6
- import('../dist/src/cli/opencode-sm.js');
6
+ import { existsSync } from 'fs';
7
+ import { fileURLToPath } from 'url';
8
+ import { dirname, join } from 'path';
9
+
10
+ const __filename = fileURLToPath(import.meta.url);
11
+ const __dirname = dirname(__filename);
12
+ const target = join(__dirname, '../dist/src/cli/opencode-sm.js');
13
+
14
+ if (!existsSync(target)) {
15
+ console.error('Error: StackMemory has not been built.');
16
+ console.error(`Missing: ${target}`);
17
+ console.error('Run: npm install && npm run build');
18
+ process.exit(1);
19
+ }
20
+
21
+ import(target);
@@ -11,7 +11,11 @@ import { program } from "commander";
11
11
  import { v4 as uuidv4 } from "uuid";
12
12
  import chalk from "chalk";
13
13
  import { initializeTracing, trace } from "../core/trace/index.js";
14
- import { resolveRealCliBin } from "./utils/real-cli-bin.js";
14
+ import {
15
+ resolveRealCliBin,
16
+ resolveNativeCodexBin,
17
+ resolveNvmBin
18
+ } from "./utils/real-cli-bin.js";
15
19
  import {
16
20
  startDeterminismWatcher,
17
21
  stopDeterminismWatcher
@@ -131,20 +135,15 @@ class CodexSM {
131
135
  explicitBin: this.config.codexBin,
132
136
  envBin: process.env["CODEX_BIN"],
133
137
  preferredPaths: [
134
- path.join(
135
- os.homedir(),
136
- ".nvm",
137
- "versions",
138
- "node",
139
- "v22.22.0",
140
- "bin",
141
- "codex"
142
- ),
138
+ ...resolveNativeCodexBin(),
139
+ // native binary first (no wrapper overhead)
140
+ resolveNvmBin("codex"),
141
+ // dynamic nvm/fnm/volta path
143
142
  "/usr/local/bin/codex",
144
143
  "/opt/homebrew/bin/codex",
145
144
  "/usr/local/bin/codex-cli",
146
145
  "/opt/homebrew/bin/codex-cli"
147
- ],
146
+ ].filter((p) => !!p),
148
147
  pathCommands: ["codex", "codex-cli"]
149
148
  });
150
149
  }
@@ -202,6 +201,46 @@ class CodexSM {
202
201
  } catch {
203
202
  }
204
203
  }
204
+ /**
205
+ * Emit context budget advice based on tool-call count from checkpoint state.
206
+ * Mirrors the Claude Code context-budget.js hook.
207
+ */
208
+ emitContextBudgetAdvice() {
209
+ const COMPACT_SUGGEST = 50;
210
+ const COMPACT_STRONG = 65;
211
+ const RESTART_RECOMMEND = 80;
212
+ try {
213
+ const stateFile = path.join(
214
+ os.homedir(),
215
+ ".stackmemory",
216
+ `checkpoint-state-${this.config.instanceId}.json`
217
+ );
218
+ if (!fs.existsSync(stateFile)) return;
219
+ const state = JSON.parse(fs.readFileSync(stateFile, "utf-8"));
220
+ const cwd = process.cwd();
221
+ const toolCount = state.projects?.[cwd]?.toolCount || 0;
222
+ if (toolCount >= RESTART_RECOMMEND) {
223
+ console.log(
224
+ chalk.yellow(
225
+ `[CONTEXT_BUDGET] ${toolCount} tool calls (~150K+ tokens). Recommend: save context then start fresh session.`
226
+ )
227
+ );
228
+ } else if (toolCount >= COMPACT_STRONG) {
229
+ console.log(
230
+ chalk.yellow(
231
+ `[CONTEXT_BUDGET] ${toolCount} tool calls (~100-130K tokens). Context heavy \u2014 consider compacting or restarting.`
232
+ )
233
+ );
234
+ } else if (toolCount >= COMPACT_SUGGEST) {
235
+ console.log(
236
+ chalk.gray(
237
+ `[CONTEXT_BUDGET] ${toolCount} tool calls (~80-100K tokens). Context getting heavy.`
238
+ )
239
+ );
240
+ }
241
+ } catch {
242
+ }
243
+ }
205
244
  loadContext() {
206
245
  if (!this.config.contextEnabled) return;
207
246
  try {
@@ -494,6 +533,7 @@ class CodexSM {
494
533
  });
495
534
  } catch {
496
535
  }
536
+ this.emitContextBudgetAdvice();
497
537
  if (this.config.tracingEnabled) {
498
538
  const summary = trace.getExecutionSummary();
499
539
  console.log();
@@ -0,0 +1,206 @@
1
+ import { fileURLToPath as __fileURLToPath } from 'url';
2
+ import { dirname as __pathDirname } from 'path';
3
+ const __filename = __fileURLToPath(import.meta.url);
4
+ const __dirname = __pathDirname(__filename);
5
+ import { Command } from "commander";
6
+ import chalk from "chalk";
7
+ import { openBrain } from "../../core/brain/index.js";
8
+ function fmtEntry(e, verbose = false) {
9
+ const id = chalk.dim(e.entryId.slice(0, 8));
10
+ const kind = chalk.cyan(e.kind.padEnd(10));
11
+ const agent = chalk.magenta(`@${e.agent}`);
12
+ const when = new Date(e.createdAt).toISOString().slice(0, 10);
13
+ const head = `${id} ${kind} ${agent} ${chalk.gray(when)} ${chalk.bold(e.title)}`;
14
+ if (!verbose) {
15
+ const concl = e.conclusion ? `
16
+ ${chalk.green("\u2192")} ${e.conclusion}` : "";
17
+ return head + concl;
18
+ }
19
+ const lines = [head];
20
+ if (e.summary) lines.push(` ${chalk.gray("summary:")} ${e.summary}`);
21
+ if (e.conclusion)
22
+ lines.push(` ${chalk.green("conclusion:")} ${e.conclusion}`);
23
+ if (e.tags.length)
24
+ lines.push(` ${chalk.gray("tags:")} ${e.tags.join(", ")}`);
25
+ if (e.refs.length)
26
+ lines.push(` ${chalk.gray("refs:")} ${e.refs.join(", ")}`);
27
+ lines.push(` ${chalk.gray("confidence:")} ${e.confidence}`);
28
+ return lines.join("\n");
29
+ }
30
+ function createBrainCommand() {
31
+ const cmd = new Command("brain").description("Shared, compounding context state (per repo + org)").addHelpText(
32
+ "after",
33
+ `
34
+ Examples:
35
+ stackmemory brain record --kind experiment \\
36
+ --title "Retry with jitter cut 5xx" \\
37
+ --summary "Tried exp backoff + jitter on the sync client" \\
38
+ --conclusion "p99 errors dropped 60%; ship it" --tags sync,reliability
39
+ stackmemory brain recall "retry" Search this repo's brain
40
+ stackmemory brain recall "auth" --org Search the whole org
41
+ stackmemory brain list --limit 10
42
+ stackmemory brain show <id>
43
+ stackmemory brain sync Push + pull online
44
+ stackmemory brain status
45
+
46
+ Every agent (Claude, Codex, OpenCode, Hermes) shares this brain \u2014 log
47
+ experiment conclusions so mutual thinking compounds. See docs/guides/BRAIN.md.
48
+ `
49
+ );
50
+ cmd.command("record").description("Record an experiment / decision / insight / note").option("--title <title>", "Short title (required)").option("--summary <text>", "What was done / context").option("--conclusion <text>", "What was concluded (the payload)").option("--kind <kind>", "experiment | decision | insight | note", "note").option("--agent <name>", "Agent that produced this", "claude").option("--tags <tags>", "Comma-separated tags").option("--refs <refs>", "Comma-separated refs (issues, commits, files)").option("--confidence <n>", "Confidence 0..1", "0.7").option("--json", "Output as JSON").action((options) => {
51
+ if (!options.title) {
52
+ console.error(chalk.red("--title is required"));
53
+ process.exit(1);
54
+ }
55
+ const ctx = openBrain();
56
+ try {
57
+ const entry = ctx.store.record({
58
+ title: options.title,
59
+ summary: options.summary,
60
+ conclusion: options.conclusion,
61
+ kind: options.kind,
62
+ agent: options.agent,
63
+ tags: splitList(options.tags),
64
+ refs: splitList(options.refs),
65
+ confidence: parseFloat(options.confidence)
66
+ });
67
+ if (options.json) {
68
+ console.log(JSON.stringify(entry, null, 2));
69
+ } else {
70
+ console.log(
71
+ chalk.green("\u2713 recorded"),
72
+ chalk.dim(entry.entryId.slice(0, 8))
73
+ );
74
+ console.log(fmtEntry(entry));
75
+ }
76
+ } finally {
77
+ ctx.close();
78
+ }
79
+ });
80
+ cmd.command("recall").description("Search the brain (this repo by default, --org for the org)").argument("[query]", "Free-text query").option("--org", "Search across the whole org (all repos)").option("--agent <name>", "Filter by agent").option("--kind <kind>", "Filter by kind").option("--limit <n>", "Max results", "20").option("--all", "Include superseded entries").option("--json", "Output as JSON").action((query, options) => {
81
+ const ctx = openBrain();
82
+ try {
83
+ const q = {
84
+ org: !!options.org,
85
+ limit: parseInt(options.limit, 10),
86
+ includeSuperseded: !!options.all,
87
+ ...query ? { text: query } : {},
88
+ ...options.agent ? { agent: options.agent } : {},
89
+ ...options.kind ? { kind: options.kind } : {}
90
+ };
91
+ const results = ctx.store.recall(q);
92
+ if (options.json) {
93
+ console.log(JSON.stringify(results, null, 2));
94
+ return;
95
+ }
96
+ if (results.length === 0) {
97
+ console.log(chalk.yellow("No matching brain entries."));
98
+ return;
99
+ }
100
+ const scope = options.org ? "org" : "repo";
101
+ console.log(chalk.bold(`${results.length} result(s) [${scope}]`));
102
+ for (const e of results) console.log("\n" + fmtEntry(e));
103
+ } finally {
104
+ ctx.close();
105
+ }
106
+ });
107
+ cmd.command("list").description("List recent brain entries for this repo").option("--limit <n>", "Max results", "20").option("--json", "Output as JSON").action((options) => {
108
+ const ctx = openBrain();
109
+ try {
110
+ const results = ctx.store.recall({
111
+ limit: parseInt(options.limit, 10)
112
+ });
113
+ if (options.json) {
114
+ console.log(JSON.stringify(results, null, 2));
115
+ return;
116
+ }
117
+ if (results.length === 0) {
118
+ console.log(chalk.yellow("Brain is empty for this repo."));
119
+ return;
120
+ }
121
+ for (const e of results) console.log(fmtEntry(e) + "\n");
122
+ } finally {
123
+ ctx.close();
124
+ }
125
+ });
126
+ cmd.command("show").description("Show a single entry in full").argument("<id>", "Entry id (or prefix)").option("--json", "Output as JSON").action((id, options) => {
127
+ const ctx = openBrain();
128
+ try {
129
+ const entry = ctx.store.get(id);
130
+ if (!entry) {
131
+ console.error(chalk.red(`No entry matching '${id}'`));
132
+ process.exit(1);
133
+ }
134
+ console.log(
135
+ options.json ? JSON.stringify(entry, null, 2) : fmtEntry(entry, true)
136
+ );
137
+ } finally {
138
+ ctx.close();
139
+ }
140
+ });
141
+ cmd.command("sync").description("Push + pull brain entries online").option("--push", "Push only").option("--pull", "Pull only").option("--json", "Output as JSON").action(async (options) => {
142
+ const ctx = openBrain();
143
+ try {
144
+ if (!ctx.sync) {
145
+ console.error(
146
+ chalk.yellow(
147
+ "Online brain not configured. Run `stackmemory login`."
148
+ )
149
+ );
150
+ process.exit(1);
151
+ }
152
+ const result = options.push ? await ctx.sync.push() : options.pull ? await ctx.sync.pull() : await ctx.sync.sync();
153
+ if (options.json) {
154
+ console.log(JSON.stringify(result, null, 2));
155
+ } else if (result.success) {
156
+ console.log(
157
+ chalk.green(
158
+ `\u2713 pushed ${result.pushed}, pulled ${result.pulled} (applied ${result.applied})`
159
+ )
160
+ );
161
+ } else {
162
+ console.error(chalk.red(`Sync failed: ${result.error}`));
163
+ process.exit(1);
164
+ }
165
+ } finally {
166
+ ctx.close();
167
+ }
168
+ });
169
+ cmd.command("status").description("Show brain scope + entry counts").option("--json", "Output as JSON").action((options) => {
170
+ const ctx = openBrain();
171
+ try {
172
+ const status = {
173
+ projectId: ctx.projectId,
174
+ workspaceId: ctx.workspaceId || null,
175
+ repoEntries: ctx.store.count(false),
176
+ orgEntries: ctx.workspaceId ? ctx.store.count(true) : 0,
177
+ online: !!ctx.sync
178
+ };
179
+ if (options.json) {
180
+ console.log(JSON.stringify(status, null, 2));
181
+ return;
182
+ }
183
+ console.log(chalk.bold("Brain Status"));
184
+ console.log(` Repo (project): ${status.projectId}`);
185
+ console.log(
186
+ ` Org (workspace): ${status.workspaceId ?? chalk.dim("not logged in")}`
187
+ );
188
+ console.log(` Repo entries: ${status.repoEntries}`);
189
+ if (ctx.workspaceId)
190
+ console.log(` Org entries: ${status.orgEntries}`);
191
+ console.log(
192
+ ` Online sync: ${status.online ? chalk.green("configured") : chalk.dim("local-only")}`
193
+ );
194
+ } finally {
195
+ ctx.close();
196
+ }
197
+ });
198
+ return cmd;
199
+ }
200
+ function splitList(v) {
201
+ if (!v) return [];
202
+ return v.split(",").map((s) => s.trim()).filter(Boolean);
203
+ }
204
+ export {
205
+ createBrainCommand
206
+ };