total-recall-brain 3.43.2 → 3.44.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 (103) hide show
  1. package/bin/total-recall-server-release.mjs +4 -0
  2. package/docs/reference/cli-reference.md +14 -0
  3. package/package.json +5 -4
  4. package/scaffold/.agent/skills/plugin/SKILL.md +7 -2
  5. package/scaffold/.agent/skills/plugin/evals/README.md +5 -0
  6. package/scaffold/.agent/skills/plugin/evals/cases/01-fabricated-seed.mjs +1 -0
  7. package/scaffold/.agent/skills/plugin/evals/cases/02-reassuring-default.mjs +1 -0
  8. package/scaffold/.agent/skills/plugin/evals/cases/03-declared-template.mjs +1 -0
  9. package/scaffold/.agent/skills/plugin/evals/cases/04-card-collects-credential.mjs +1 -0
  10. package/scaffold/.agent/skills/plugin/evals/cases/05-host-leak-in-scaffold.mjs +1 -0
  11. package/scaffold/.agent/skills/plugin/evals/cases/06-correct-plugin.mjs +1 -0
  12. package/scaffold/.agent/skills/plugin/evals/cases/07-missing-reuse.mjs +11 -0
  13. package/scaffold/.agent/skills/plugin/evals/cases/08-unresolved-owner-command.mjs +12 -0
  14. package/scaffold/.agent/skills/plugin/evals/cases/09-missing-brick.mjs +12 -0
  15. package/scaffold/.agent/skills/plugin/prompts/01-function.md +4 -3
  16. package/scaffold/.agent/skills/plugin/prompts/08-verify.md +1 -0
  17. package/scaffold/.agent/skills/plugin/references/surfaces.md +12 -2
  18. package/scaffold/.agent/skills/plugin/scripts/record.mjs +59 -2
  19. package/scaffold/.agent/skills/total-recall/plugins/auth/README.md +8 -0
  20. package/scaffold/.agent/skills/total-recall/plugins/auth/package-lock.json +14 -13
  21. package/scaffold/.agent/skills/total-recall/plugins/auth/package.json +3 -3
  22. package/scaffold/.agent/skills/total-recall/plugins/auth/plugin.json +1 -1
  23. package/scaffold/.agent/skills/total-recall/plugins/auth/src/cli-gh-login.mjs +102 -0
  24. package/scaffold/.agent/skills/total-recall/plugins/auth/src/cli-secret.mjs +18 -1
  25. package/scaffold/.agent/skills/total-recall/plugins/auth/src/login-projections.mjs +157 -13
  26. package/scaffold/.agent/skills/total-recall/plugins/auth/src/secrets-sync.mjs +161 -17
  27. package/scaffold/.agent/skills/total-recall/plugins/code-quality/README.md +2 -2
  28. package/scaffold/.agent/skills/total-recall/plugins/code-quality/core/check.mjs +39 -6
  29. package/scaffold/.agent/skills/total-recall/plugins/code-quality/core/config.schema.json +2 -1
  30. package/scaffold/.agent/skills/total-recall/plugins/code-quality/package-lock.json +14 -13
  31. package/scaffold/.agent/skills/total-recall/plugins/code-quality/package.json +3 -3
  32. package/scaffold/.agent/skills/total-recall/plugins/code-quality/plugin.json +1 -1
  33. package/scaffold/.agent/skills/total-recall/plugins/composable-cli/package-lock.json +14 -13
  34. package/scaffold/.agent/skills/total-recall/plugins/composable-cli/package.json +3 -3
  35. package/scaffold/.agent/skills/total-recall/plugins/composable-cli/plugin.json +1 -1
  36. package/scaffold/.agent/skills/total-recall/plugins/embeddings/package-lock.json +14 -13
  37. package/scaffold/.agent/skills/total-recall/plugins/embeddings/package.json +3 -3
  38. package/scaffold/.agent/skills/total-recall/plugins/embeddings/plugin.json +1 -1
  39. package/scaffold/.agent/skills/total-recall/plugins/git-sentinel/package-lock.json +14 -13
  40. package/scaffold/.agent/skills/total-recall/plugins/git-sentinel/package.json +3 -3
  41. package/scaffold/.agent/skills/total-recall/plugins/git-sentinel/plugin.json +1 -1
  42. package/scaffold/.agent/skills/total-recall/plugins/mesh/package-lock.json +14 -13
  43. package/scaffold/.agent/skills/total-recall/plugins/mesh/package.json +3 -3
  44. package/scaffold/.agent/skills/total-recall/plugins/mesh/plugin.json +1 -1
  45. package/scaffold/.agent/skills/total-recall/plugins/meta-harness/README.md +38 -5
  46. package/scaffold/.agent/skills/total-recall/plugins/meta-harness/cli.mjs +38 -7
  47. package/scaffold/.agent/skills/total-recall/plugins/meta-harness/package-lock.json +14 -13
  48. package/scaffold/.agent/skills/total-recall/plugins/meta-harness/package.json +3 -3
  49. package/scaffold/.agent/skills/total-recall/plugins/meta-harness/plugin.json +85 -3
  50. package/scaffold/.agent/skills/total-recall/plugins/meta-harness/skills/meta-harness/SKILL.md +2 -1
  51. package/scaffold/.agent/skills/total-recall/plugins/meta-harness/src/adoption.mjs +104 -0
  52. package/scaffold/.agent/skills/total-recall/plugins/meta-harness/src/cascade.mjs +12 -1
  53. package/scaffold/.agent/skills/total-recall/plugins/meta-harness/src/coordinator.mjs +15 -3
  54. package/scaffold/.agent/skills/total-recall/plugins/meta-harness/src/dispatch-request.mjs +38 -0
  55. package/scaffold/.agent/skills/total-recall/plugins/meta-harness/src/dispatch.mjs +42 -11
  56. package/scaffold/.agent/skills/total-recall/plugins/meta-harness/src/executor.mjs +40 -13
  57. package/scaffold/.agent/skills/total-recall/plugins/meta-harness/src/included-usage.mjs +249 -0
  58. package/scaffold/.agent/skills/total-recall/plugins/meta-harness/src/learner.mjs +3 -0
  59. package/scaffold/.agent/skills/total-recall/plugins/meta-harness/src/pool.mjs +16 -8
  60. package/scaffold/.agent/skills/total-recall/plugins/meta-harness/src/process-manager.mjs +1 -0
  61. package/scaffold/.agent/skills/total-recall/plugins/meta-harness/src/reasoning.mjs +5 -0
  62. package/scaffold/.agent/skills/total-recall/plugins/meta-harness/src/remote-operation.mjs +1 -1
  63. package/scaffold/.agent/skills/total-recall/plugins/meta-harness/src/router.mjs +27 -11
  64. package/scaffold/.agent/skills/total-recall/plugins/meta-harness/src/runtime.mjs +28 -6
  65. package/scaffold/.agent/skills/total-recall/plugins/meta-harness/src/usage-queue.mjs +110 -0
  66. package/scaffold/.agent/skills/total-recall/plugins/meta-harness/src/worker.mjs +322 -40
  67. package/scaffold/.agent/skills/total-recall/plugins/openwiki/package-lock.json +14 -13
  68. package/scaffold/.agent/skills/total-recall/plugins/openwiki/package.json +3 -3
  69. package/scaffold/.agent/skills/total-recall/plugins/openwiki/plugin.json +1 -1
  70. package/scaffold/.agent/skills/total-recall/plugins/security/package-lock.json +14 -13
  71. package/scaffold/.agent/skills/total-recall/plugins/security/package.json +3 -3
  72. package/scaffold/.agent/skills/total-recall/plugins/security/plugin.json +1 -1
  73. package/scaffold/.agent/skills/total-recall/plugins/ssss/assets/scaffold.json +5 -5
  74. package/scaffold/.agent/skills/total-recall/plugins/ssss/package-lock.json +6 -6
  75. package/scaffold/.agent/skills/total-recall/plugins/ssss/package.json +2 -2
  76. package/scaffold/.agent/skills/total-recall/plugins/ssss/plugin.json +1 -1
  77. package/src/cli/connect.mjs +2 -29
  78. package/src/cli/context.mjs +1 -0
  79. package/src/cli/ingest-okf.mjs +4 -4
  80. package/src/cli/release.mjs +27 -2
  81. package/src/cli/startup.mjs +1 -0
  82. package/src/cli/update.mjs +14 -3
  83. package/src/core/automatic-brain-updates.mjs +13 -3
  84. package/src/core/autopull-install.mjs +14 -0
  85. package/src/core/brain-updates.mjs +12 -2
  86. package/src/core/context-compactor.mjs +7 -2
  87. package/src/core/context-compiler.mjs +6 -1
  88. package/src/core/context-policy.mjs +7 -3
  89. package/src/core/daemon-control.mjs +22 -0
  90. package/src/core/global-brain-updates.mjs +3 -3
  91. package/src/core/mesh-brain-updates.mjs +20 -5
  92. package/src/core/running-server.mjs +76 -0
  93. package/src/core/server-release.mjs +487 -0
  94. package/src/core/server-restart.mjs +128 -7
  95. package/src/core/source-brain-updates.mjs +35 -6
  96. package/src/core/ssss-kernel-bridge.mjs +1 -2
  97. package/src/core/startup-health.mjs +13 -2
  98. package/src/core/surface.mjs +3 -3
  99. package/src/core/task-context.mjs +9 -8
  100. package/src/core/validated-write.mjs +4 -0
  101. package/src/core/vault-files.mjs +8 -2
  102. package/src/core/vault.mjs +1 -1
  103. package/src/server/index.mjs +17 -1
@@ -0,0 +1,110 @@
1
+ /** SSSS-backed queue for work deferred by included usage limits. */
2
+ import path from 'node:path';
3
+ import { randomUUID } from 'node:crypto';
4
+ import { configDir } from './paths.mjs';
5
+ import { destinationDispatchRequest } from './dispatch-request.mjs';
6
+ import { readIncludedPolicy } from './included-usage.mjs';
7
+
8
+ async function queueStore() {
9
+ const { PluginStateStore } = await import('./ssss-store.mjs');
10
+ return new PluginStateStore(path.join(configDir(), 'usage-queue.json'), 'meta-harness');
11
+ }
12
+
13
+ function readRows(store) {
14
+ const jobs = store.read([]);
15
+ if (!Array.isArray(jobs) || jobs.some(job => !job?.id || typeof job.task !== 'string' || !path.isAbsolute(job.workspace || '') ||
16
+ !['waiting', 'running', 'completed', 'cancelled', 'failed'].includes(job.status))) {
17
+ throw new Error('Invalid included usage queue.');
18
+ }
19
+ return jobs;
20
+ }
21
+
22
+ async function mutateQueue(change) {
23
+ for (let attempt = 0; attempt < 8; attempt += 1) {
24
+ const store = await queueStore();
25
+ const jobs = readRows(store);
26
+ const result = change(jobs);
27
+ try { store.write(jobs); return result; }
28
+ catch (error) { if (!error.message.includes('version conflict') || attempt === 7) throw error; }
29
+ }
30
+ }
31
+
32
+ function publicJob({ replay, task, ...job }) {
33
+ return { ...job, task: task.slice(0, 160), canRetry: Boolean(replay) && !job.needsReview };
34
+ }
35
+
36
+ export async function queueIncludedJob(request, result, { role, replay, launchPrevented = false } = {}) {
37
+ const workspace = request.contextCwd || request.cwd;
38
+ const direct = !replay && role === 'Dispatch' && workspace === request.cwd;
39
+ if (direct) replay = { kind: 'dispatch', request: destinationDispatchRequest(request) };
40
+ const job = {
41
+ id: randomUUID(), status: 'waiting', agent: request.agent, workspace, role: role || 'Dispatch',
42
+ task: String(request.contextTask || request.prompt).slice(0, direct ? 160 : 65536),
43
+ reason: 'included-usage-exhausted',
44
+ resetsAt: Number.isFinite(Date.parse(result.resetsAt)) ? result.resetsAt : null,
45
+ queuedAt: new Date().toISOString(), attempts: 0,
46
+ needsReview: !replay || (!launchPrevented && request.permissions?.write === true),
47
+ replay: replay || null,
48
+ };
49
+ return mutateQueue(jobs => {
50
+ if (jobs.filter(item => ['waiting', 'running'].includes(item.status)).length >= 200) throw new Error('Included usage queue is full.');
51
+ const history = jobs.filter(item => !['waiting', 'running'].includes(item.status)).slice(0, -50);
52
+ for (const item of history) jobs.splice(jobs.indexOf(item), 1);
53
+ jobs.push(job);
54
+ if (Buffer.byteLength(JSON.stringify(jobs)) > 4 * 1024 * 1024) throw new Error('Included usage queue exceeds its storage bound.');
55
+ return publicJob(job);
56
+ });
57
+ }
58
+
59
+ export async function listIncludedJobs() {
60
+ const jobs = readRows(await queueStore());
61
+ return jobs.map(publicJob);
62
+ }
63
+
64
+ function updateJob(jobs, id, change) {
65
+ const index = jobs.findIndex(job => job.id === id);
66
+ if (index < 0) throw new Error('Included usage job was not found.');
67
+ return jobs[index] = change(jobs[index]);
68
+ }
69
+
70
+ export async function cancelIncludedJob(id) {
71
+ return mutateQueue(jobs => publicJob(updateJob(jobs, id, job => {
72
+ if (job.status !== 'waiting') throw new Error('Only a waiting job can be cancelled.');
73
+ return { ...job, status: 'cancelled', replay: null };
74
+ })));
75
+ }
76
+
77
+ /** Claim atomically before retry, so two callers cannot start the same job. */
78
+ export async function retryIncludedJob(id, { dispatch, route, now = Date.now() } = {}) {
79
+ if (!(await readIncludedPolicy()).enabled) throw new Error('Included usage policy must be enabled to retry.');
80
+ const claimed = await mutateQueue(jobs => updateJob(jobs, id, job => {
81
+ if (job.status !== 'waiting') throw new Error('Only a waiting job can be retried.');
82
+ if (job.needsReview || !job.replay) throw new Error('Review the prior attempt and resubmit this task from its original workspace.');
83
+ if (Date.parse(job.resetsAt) > now) throw new Error('The provider-reported reset time has not arrived.');
84
+ return { ...job, status: 'running', attempts: job.attempts + 1, startedAt: new Date(now).toISOString() };
85
+ }));
86
+ let result;
87
+ try {
88
+ if (claimed.replay.kind === 'dispatch') {
89
+ dispatch ??= (await import('./dispatch.mjs')).dispatchWithReceipt;
90
+ result = await dispatch(claimed.replay.request, { role: 'Dispatch', retryId: id });
91
+ } else if (claimed.replay.kind === 'route') {
92
+ route ??= (await import('./cascade.mjs')).executeRoutedTask;
93
+ result = await route(claimed.task, { cwd: claimed.workspace, gate: claimed.replay.gate, gateOptions: claimed.replay.gateOptions,
94
+ route: { selected: claimed.agent }, pool: [claimed.agent], retryId: id });
95
+ } else throw new Error('Unknown included usage job operation.');
96
+ } catch (error) {
97
+ result = { ok: false, failureKind: 'execution', error: error.message };
98
+ }
99
+ const held = ['quota', 'billing-policy', 'auth'].includes(result.failureKind);
100
+ const updated = await mutateQueue(jobs => updateJob(jobs, id, job => {
101
+ if (job.status !== 'running') throw new Error('Included usage job lost its claim.');
102
+ return { ...job, status: result.ok ? 'completed' : held ? 'waiting' : 'failed',
103
+ resetsAt: held && Number.isFinite(Date.parse(result.resetsAt)) ? result.resetsAt : null,
104
+ needsReview: job.needsReview || result.needsReview === true ||
105
+ (held && !result.launchPrevented && (job.replay.kind === 'route' || job.replay.request?.permissions?.write === true)),
106
+ lastError: result.ok ? null : result.error,
107
+ replay: held ? job.replay : null, finishedAt: new Date().toISOString() };
108
+ }));
109
+ return { ...result, job: publicJob(updated) };
110
+ }