brainclaw 0.19.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 (128) hide show
  1. package/LICENSE +74 -0
  2. package/README.md +226 -0
  3. package/dist/cli.js +1037 -0
  4. package/dist/commands/accept.js +149 -0
  5. package/dist/commands/adapter-openclaw-import.js +75 -0
  6. package/dist/commands/add-step.js +35 -0
  7. package/dist/commands/agent-board.js +106 -0
  8. package/dist/commands/audit.js +35 -0
  9. package/dist/commands/bootstrap.js +34 -0
  10. package/dist/commands/capability.js +104 -0
  11. package/dist/commands/changes.js +112 -0
  12. package/dist/commands/check-constraints.js +63 -0
  13. package/dist/commands/claim-resource.js +54 -0
  14. package/dist/commands/claim.js +92 -0
  15. package/dist/commands/complete-step.js +34 -0
  16. package/dist/commands/constraint.js +44 -0
  17. package/dist/commands/context-diff.js +32 -0
  18. package/dist/commands/context.js +63 -0
  19. package/dist/commands/decision.js +45 -0
  20. package/dist/commands/delete-plan.js +20 -0
  21. package/dist/commands/diff.js +99 -0
  22. package/dist/commands/doctor.js +1275 -0
  23. package/dist/commands/enable-agent.js +63 -0
  24. package/dist/commands/env.js +46 -0
  25. package/dist/commands/estimation-report.js +167 -0
  26. package/dist/commands/explore.js +47 -0
  27. package/dist/commands/export.js +381 -0
  28. package/dist/commands/handoff.js +63 -0
  29. package/dist/commands/history.js +22 -0
  30. package/dist/commands/hooks.js +123 -0
  31. package/dist/commands/init.js +356 -0
  32. package/dist/commands/install-hooks.js +115 -0
  33. package/dist/commands/instruction.js +56 -0
  34. package/dist/commands/list-agents.js +44 -0
  35. package/dist/commands/list-claims.js +45 -0
  36. package/dist/commands/list-instructions.js +50 -0
  37. package/dist/commands/list-plans.js +48 -0
  38. package/dist/commands/mcp-worker.js +12 -0
  39. package/dist/commands/mcp.js +2272 -0
  40. package/dist/commands/memory.js +283 -0
  41. package/dist/commands/metrics.js +175 -0
  42. package/dist/commands/plan-resource.js +62 -0
  43. package/dist/commands/plan.js +76 -0
  44. package/dist/commands/prune-candidates.js +36 -0
  45. package/dist/commands/prune.js +48 -0
  46. package/dist/commands/pull.js +25 -0
  47. package/dist/commands/push.js +28 -0
  48. package/dist/commands/rebuild.js +14 -0
  49. package/dist/commands/reflect-runtime-note.js +74 -0
  50. package/dist/commands/reflect.js +286 -0
  51. package/dist/commands/register-agent.js +29 -0
  52. package/dist/commands/reject.js +52 -0
  53. package/dist/commands/release-claim.js +41 -0
  54. package/dist/commands/release-claims.js +67 -0
  55. package/dist/commands/review.js +242 -0
  56. package/dist/commands/rollback.js +156 -0
  57. package/dist/commands/runtime-note.js +144 -0
  58. package/dist/commands/runtime-status.js +49 -0
  59. package/dist/commands/search.js +36 -0
  60. package/dist/commands/session-end.js +187 -0
  61. package/dist/commands/session-start.js +147 -0
  62. package/dist/commands/set-trust.js +92 -0
  63. package/dist/commands/setup.js +446 -0
  64. package/dist/commands/show-candidate.js +31 -0
  65. package/dist/commands/star-candidate.js +28 -0
  66. package/dist/commands/status.js +133 -0
  67. package/dist/commands/sync.js +159 -0
  68. package/dist/commands/tool.js +126 -0
  69. package/dist/commands/trap.js +74 -0
  70. package/dist/commands/update-handoff.js +23 -0
  71. package/dist/commands/update-plan.js +37 -0
  72. package/dist/commands/upgrade.js +382 -0
  73. package/dist/commands/use-candidate.js +35 -0
  74. package/dist/commands/version.js +96 -0
  75. package/dist/commands/watch.js +215 -0
  76. package/dist/commands/whoami.js +104 -0
  77. package/dist/core/agent-context.js +340 -0
  78. package/dist/core/agent-files.js +874 -0
  79. package/dist/core/agent-integrations.js +135 -0
  80. package/dist/core/agent-inventory.js +401 -0
  81. package/dist/core/agent-registry.js +420 -0
  82. package/dist/core/ai-agent-detection.js +140 -0
  83. package/dist/core/audit.js +85 -0
  84. package/dist/core/bootstrap.js +658 -0
  85. package/dist/core/brainclaw-version.js +433 -0
  86. package/dist/core/candidates.js +137 -0
  87. package/dist/core/circuit-breaker.js +118 -0
  88. package/dist/core/claims.js +72 -0
  89. package/dist/core/config.js +86 -0
  90. package/dist/core/context-diff.js +122 -0
  91. package/dist/core/context.js +1212 -0
  92. package/dist/core/contradictions.js +270 -0
  93. package/dist/core/coordination.js +86 -0
  94. package/dist/core/cross-project.js +99 -0
  95. package/dist/core/duplicates.js +72 -0
  96. package/dist/core/event-log.js +152 -0
  97. package/dist/core/events.js +56 -0
  98. package/dist/core/execution-context.js +204 -0
  99. package/dist/core/freshness.js +87 -0
  100. package/dist/core/global-registry.js +182 -0
  101. package/dist/core/host.js +10 -0
  102. package/dist/core/identity.js +151 -0
  103. package/dist/core/ids.js +56 -0
  104. package/dist/core/input-validation.js +81 -0
  105. package/dist/core/instructions.js +117 -0
  106. package/dist/core/io.js +191 -0
  107. package/dist/core/json-store.js +63 -0
  108. package/dist/core/lifecycle.js +45 -0
  109. package/dist/core/lock.js +129 -0
  110. package/dist/core/logger.js +49 -0
  111. package/dist/core/machine-profile.js +332 -0
  112. package/dist/core/markdown.js +120 -0
  113. package/dist/core/memory-git.js +133 -0
  114. package/dist/core/migration.js +247 -0
  115. package/dist/core/project-registry.js +64 -0
  116. package/dist/core/reflection-safety.js +21 -0
  117. package/dist/core/repo-analysis.js +133 -0
  118. package/dist/core/reputation.js +409 -0
  119. package/dist/core/runtime.js +134 -0
  120. package/dist/core/schema.js +580 -0
  121. package/dist/core/search.js +115 -0
  122. package/dist/core/security.js +66 -0
  123. package/dist/core/setup-state.js +50 -0
  124. package/dist/core/state.js +83 -0
  125. package/dist/core/store-resolution.js +119 -0
  126. package/dist/core/sync-remote.js +83 -0
  127. package/dist/core/traps.js +86 -0
  128. package/package.json +60 -0
@@ -0,0 +1,72 @@
1
+ import crypto from 'node:crypto';
2
+ import fs from 'node:fs';
3
+ import { ClaimSchema } from './schema.js';
4
+ import { resolveEntityDir } from './io.js';
5
+ import { nowISO } from './ids.js';
6
+ import { JsonStore } from './json-store.js';
7
+ function claimsDir(cwd, mode = 'read') {
8
+ return resolveEntityDir('claims', cwd ?? process.cwd(), mode);
9
+ }
10
+ export function ensureClaimsDir(cwd) {
11
+ const dir = claimsDir(cwd, 'write');
12
+ if (!fs.existsSync(dir)) {
13
+ fs.mkdirSync(dir, { recursive: true });
14
+ }
15
+ }
16
+ function claimStore(cwd) {
17
+ return new JsonStore({
18
+ dirPath: claimsDir(cwd, 'read'),
19
+ documentType: 'claim',
20
+ getId: (claim) => claim.id,
21
+ sort: (a, b) => a.created_at.localeCompare(b.created_at),
22
+ });
23
+ }
24
+ export function saveClaim(claim, cwd) {
25
+ ensureClaimsDir(cwd);
26
+ const writeStore = new JsonStore({
27
+ dirPath: claimsDir(cwd, 'write'),
28
+ documentType: 'claim',
29
+ getId: (c) => c.id,
30
+ sort: (a, b) => a.created_at.localeCompare(b.created_at),
31
+ });
32
+ writeStore.save(ClaimSchema.parse(claim));
33
+ }
34
+ export function loadClaim(id, cwd) {
35
+ return claimStore(cwd).load(id);
36
+ }
37
+ export function listClaims(cwd) {
38
+ return claimStore(cwd).list();
39
+ }
40
+ export function releaseClaim(id, cwd) {
41
+ const claim = loadClaim(id, cwd);
42
+ claim.status = 'released';
43
+ claim.released_at = nowISO();
44
+ saveClaim(claim, cwd);
45
+ return claim;
46
+ }
47
+ export function generateClaimId() {
48
+ const rand = crypto.randomBytes(4).toString('hex');
49
+ return `clm_${rand}`;
50
+ }
51
+ export function isClaimExpired(claim) {
52
+ if (!claim.expires_at)
53
+ return false;
54
+ return new Date(claim.expires_at) < new Date();
55
+ }
56
+ /** Mark active claims past their expires_at as released. Returns count of expired claims. */
57
+ export function expireStaleActiveClaims(cwd) {
58
+ const store = claimStore(cwd);
59
+ const all = store.list();
60
+ let count = 0;
61
+ const now = nowISO();
62
+ for (const claim of all) {
63
+ if (claim.status === 'active' && isClaimExpired(claim)) {
64
+ claim.status = 'released';
65
+ claim.released_at = now;
66
+ store.save(claim);
67
+ count++;
68
+ }
69
+ }
70
+ return count;
71
+ }
72
+ //# sourceMappingURL=claims.js.map
@@ -0,0 +1,86 @@
1
+ import { ConfigSchema } from './schema.js';
2
+ import { memoryPath } from './io.js';
3
+ import { loadVersionedYamlFile, saveVersionedYamlFile } from './migration.js';
4
+ const CONFIG_FILE = 'config.yaml';
5
+ export function defaultConfig(projectName, options = {}) {
6
+ return {
7
+ schema_version: 2,
8
+ version: 1,
9
+ project_name: projectName,
10
+ project_id: options.projectId,
11
+ current_agent: options.currentAgent,
12
+ current_agent_id: options.currentAgentId,
13
+ storage_dir: options.storageDir ?? '.brainclaw',
14
+ topology: options.topology ?? 'embedded',
15
+ ignore_strategy: options.ignoreStrategy ?? 'none',
16
+ project_mode: options.projectMode ?? 'auto',
17
+ projects: {
18
+ strategy: options.projectStrategy ?? 'manual',
19
+ known: [],
20
+ },
21
+ profile: 'dev',
22
+ target_audience: 'human',
23
+ openclaw_bridge: false,
24
+ telemetry: false,
25
+ allow_network: false,
26
+ redaction: {
27
+ enabled: true,
28
+ patterns: [
29
+ '(?i)api[_-]?key',
30
+ '(?i)secret',
31
+ '(?i)token',
32
+ '(?i)password',
33
+ ],
34
+ },
35
+ sensitive_paths: ['.env', 'secrets/', '.git/', 'node_modules/'],
36
+ security: {
37
+ mode: 'warn',
38
+ strict_redaction: false,
39
+ block_sensitive_paths: true,
40
+ },
41
+ markdown: {
42
+ max_items_per_section: 20,
43
+ compact_mode: false,
44
+ },
45
+ reflective_memory: {
46
+ enabled: true,
47
+ auto_accept: false,
48
+ max_pending: 50,
49
+ promotion_stars_threshold: 3,
50
+ promotion_uses_threshold: 2,
51
+ prune_rejected_after_days: 30,
52
+ auto_promote_trusted: false,
53
+ auto_promote_score_threshold: 5,
54
+ circuit_breaker_threshold: 5,
55
+ circuit_breaker_window_days: 7,
56
+ },
57
+ governance: {
58
+ approval_policy: 'review',
59
+ curators: [],
60
+ review_sla_hours: 24,
61
+ },
62
+ reputation: {
63
+ enabled: false,
64
+ visibility: 'internal-only',
65
+ decay_days: 30,
66
+ ranking_weight: 0.15,
67
+ resume_weight: 0.35,
68
+ mcp_exposure: false,
69
+ },
70
+ agent_integrations: {
71
+ declarations: [],
72
+ },
73
+ cross_project_links: [],
74
+ implicit_session_ttl: '4h',
75
+ auto_reflect_notes: false,
76
+ };
77
+ }
78
+ export function loadConfig(cwd, preferredDirName) {
79
+ const filepath = memoryPath(CONFIG_FILE, cwd, preferredDirName);
80
+ return loadVersionedYamlFile('config', filepath).document;
81
+ }
82
+ export function saveConfig(config, cwd, preferredDirName) {
83
+ const filepath = memoryPath(CONFIG_FILE, cwd, preferredDirName);
84
+ saveVersionedYamlFile('config', filepath, ConfigSchema.parse(config));
85
+ }
86
+ //# sourceMappingURL=config.js.map
@@ -0,0 +1,122 @@
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
3
+ import { readAuditLog } from './audit.js';
4
+ import { listCandidates } from './candidates.js';
5
+ import { readContextMarker } from './freshness.js';
6
+ import { memoryDir, resolveEntityDir } from './io.js';
7
+ import { logger } from './logger.js';
8
+ import { loadVersionedJsonFile } from './migration.js';
9
+ import { SessionSnapshotSchema } from './schema.js';
10
+ import { loadState } from './state.js';
11
+ export function resolveContextDiffSince(options) {
12
+ if (options.since) {
13
+ return { since: options.since };
14
+ }
15
+ if (options.session) {
16
+ const snapshot = loadSessionSnapshot(options.session, options.cwd);
17
+ if (snapshot?.started_at) {
18
+ return { since: snapshot.started_at, since_session: options.session };
19
+ }
20
+ const sessionEntry = readAuditLog({ action: 'session_start', itemId: options.session }, options.cwd)[0];
21
+ if (sessionEntry?.timestamp) {
22
+ return { since: sessionEntry.timestamp, since_session: options.session };
23
+ }
24
+ return { since_session: options.session };
25
+ }
26
+ const marker = readContextMarker(options.cwd);
27
+ if (marker?.read_at) {
28
+ return { since: marker.read_at };
29
+ }
30
+ return {};
31
+ }
32
+ function loadSessionSnapshot(sessionId, cwd) {
33
+ const snapshotPath = path.join(resolveEntityDir('sessions', cwd ?? process.cwd(), 'read'), `${sessionId}.json`);
34
+ if (!fs.existsSync(snapshotPath)) {
35
+ return undefined;
36
+ }
37
+ try {
38
+ return SessionSnapshotSchema.parse(loadVersionedJsonFile('session_snapshot', snapshotPath).document);
39
+ }
40
+ catch {
41
+ return undefined;
42
+ }
43
+ }
44
+ export function buildContextDiff(options = {}) {
45
+ const resolved = resolveContextDiffSince(options);
46
+ if (!resolved.since) {
47
+ return undefined;
48
+ }
49
+ const state = loadState(options.cwd);
50
+ const pendingCandidates = listCandidates('pending', options.cwd).filter((item) => item.created_at >= resolved.since);
51
+ const constraints = state.active_constraints.filter((item) => item.created_at >= resolved.since);
52
+ const decisions = state.recent_decisions.filter((item) => item.created_at >= resolved.since);
53
+ const traps = state.known_traps.filter((item) => item.created_at >= resolved.since);
54
+ const handoffs = state.open_handoffs.filter((item) => item.created_at >= resolved.since);
55
+ const changedItems = options.includeItems
56
+ ? [
57
+ ...constraints.map((item) => toChangedItem('constraint', item)),
58
+ ...decisions.map((item) => toChangedItem('decision', item)),
59
+ ...traps.map((item) => toChangedItem('trap', item)),
60
+ ...handoffs.map((item) => toChangedItem('handoff', item)),
61
+ ...pendingCandidates.map((item) => toChangedItem('candidate', item)),
62
+ ].sort((a, b) => b.created_at.localeCompare(a.created_at))
63
+ : undefined;
64
+ const counts = {
65
+ constraints: constraints.length,
66
+ decisions: decisions.length,
67
+ traps: traps.length,
68
+ handoffs: handoffs.length,
69
+ pending_candidates: pendingCandidates.length,
70
+ total: constraints.length + decisions.length + traps.length + handoffs.length + pendingCandidates.length,
71
+ };
72
+ return {
73
+ since: resolved.since,
74
+ since_session: resolved.since_session,
75
+ summary: buildContextDiffSummary(counts),
76
+ counts,
77
+ changed_items: changedItems,
78
+ };
79
+ }
80
+ export function readLastContextTimestamp(cwd) {
81
+ const marker = readContextMarker(cwd);
82
+ if (marker?.read_at) {
83
+ return marker.read_at;
84
+ }
85
+ const markerPath = path.join(memoryDir(cwd), '.last-context');
86
+ if (fs.existsSync(markerPath)) {
87
+ try {
88
+ const parsed = JSON.parse(fs.readFileSync(markerPath, 'utf-8'));
89
+ return parsed.read_at;
90
+ }
91
+ catch (error) {
92
+ logger.debug('Failed to parse context marker fallback:', error);
93
+ }
94
+ }
95
+ return undefined;
96
+ }
97
+ export function buildContextDiffSummary(counts) {
98
+ if (counts.total === 0) {
99
+ return 'No memory changes detected';
100
+ }
101
+ const parts = [];
102
+ if (counts.constraints > 0)
103
+ parts.push(`${counts.constraints} constraint${counts.constraints > 1 ? 's' : ''}`);
104
+ if (counts.decisions > 0)
105
+ parts.push(`${counts.decisions} decision${counts.decisions > 1 ? 's' : ''}`);
106
+ if (counts.traps > 0)
107
+ parts.push(`${counts.traps} trap${counts.traps > 1 ? 's' : ''}`);
108
+ if (counts.handoffs > 0)
109
+ parts.push(`${counts.handoffs} handoff${counts.handoffs > 1 ? 's' : ''}`);
110
+ if (counts.pending_candidates > 0)
111
+ parts.push(`${counts.pending_candidates} pending candidate${counts.pending_candidates > 1 ? 's' : ''}`);
112
+ return parts.join(', ');
113
+ }
114
+ function toChangedItem(section, item) {
115
+ return {
116
+ section,
117
+ id: item.id,
118
+ text: item.text,
119
+ created_at: item.created_at,
120
+ };
121
+ }
122
+ //# sourceMappingURL=context-diff.js.map