@cleocode/cleo 2026.4.58 → 2026.4.60
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.
- package/dist/cli/index.js +497 -13
- package/dist/cli/index.js.map +3 -3
- package/package.json +8 -8
package/dist/cli/index.js
CHANGED
|
@@ -6,10 +6,16 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
|
6
6
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
7
|
var __getProtoOf = Object.getPrototypeOf;
|
|
8
8
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
10
|
+
get: (a, b2) => (typeof require !== "undefined" ? require : a)[b2]
|
|
11
|
+
}) : x)(function(x) {
|
|
12
|
+
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
13
|
+
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
14
|
+
});
|
|
9
15
|
var __esm = (fn2, res) => function __init() {
|
|
10
16
|
return fn2 && (res = (0, fn2[__getOwnPropNames(fn2)[0]])(fn2 = 0)), res;
|
|
11
17
|
};
|
|
12
|
-
var __commonJS = (cb, mod) => function
|
|
18
|
+
var __commonJS = (cb, mod) => function __require2() {
|
|
13
19
|
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
14
20
|
};
|
|
15
21
|
var __export = (target, all) => {
|
|
@@ -9064,9 +9070,11 @@ __export(brain_schema_exports, {
|
|
|
9064
9070
|
BRAIN_STICKY_COLORS: () => BRAIN_STICKY_COLORS,
|
|
9065
9071
|
BRAIN_STICKY_PRIORITIES: () => BRAIN_STICKY_PRIORITIES,
|
|
9066
9072
|
BRAIN_STICKY_STATUSES: () => BRAIN_STICKY_STATUSES,
|
|
9073
|
+
brainConsolidationEvents: () => brainConsolidationEvents,
|
|
9067
9074
|
brainDecisions: () => brainDecisions,
|
|
9068
9075
|
brainLearnings: () => brainLearnings,
|
|
9069
9076
|
brainMemoryLinks: () => brainMemoryLinks,
|
|
9077
|
+
brainModulators: () => brainModulators,
|
|
9070
9078
|
brainObservations: () => brainObservations,
|
|
9071
9079
|
brainPageEdges: () => brainPageEdges,
|
|
9072
9080
|
brainPageNodes: () => brainPageNodes,
|
|
@@ -9074,10 +9082,11 @@ __export(brain_schema_exports, {
|
|
|
9074
9082
|
brainPlasticityEvents: () => brainPlasticityEvents,
|
|
9075
9083
|
brainRetrievalLog: () => brainRetrievalLog,
|
|
9076
9084
|
brainSchemaMeta: () => brainSchemaMeta,
|
|
9077
|
-
brainStickyNotes: () => brainStickyNotes
|
|
9085
|
+
brainStickyNotes: () => brainStickyNotes,
|
|
9086
|
+
brainWeightHistory: () => brainWeightHistory
|
|
9078
9087
|
});
|
|
9079
9088
|
import { sql as sql2 } from "drizzle-orm";
|
|
9080
|
-
var BRAIN_MEMORY_TIERS, BRAIN_COGNITIVE_TYPES, BRAIN_SOURCE_CONFIDENCE, BRAIN_DECISION_TYPES, BRAIN_CONFIDENCE_LEVELS, BRAIN_OUTCOME_TYPES, BRAIN_PATTERN_TYPES, BRAIN_IMPACT_LEVELS, BRAIN_LINK_TYPES, BRAIN_OBSERVATION_TYPES2, BRAIN_OBSERVATION_SOURCE_TYPES, BRAIN_MEMORY_TYPES, BRAIN_STICKY_STATUSES, BRAIN_STICKY_COLORS, BRAIN_STICKY_PRIORITIES, brainDecisions, brainPatterns, brainLearnings, brainObservations, brainStickyNotes, brainMemoryLinks, brainSchemaMeta, BRAIN_NODE_TYPES, BRAIN_EDGE_TYPES, brainPageNodes, brainPageEdges, brainRetrievalLog, brainPlasticityEvents;
|
|
9089
|
+
var BRAIN_MEMORY_TIERS, BRAIN_COGNITIVE_TYPES, BRAIN_SOURCE_CONFIDENCE, BRAIN_DECISION_TYPES, BRAIN_CONFIDENCE_LEVELS, BRAIN_OUTCOME_TYPES, BRAIN_PATTERN_TYPES, BRAIN_IMPACT_LEVELS, BRAIN_LINK_TYPES, BRAIN_OBSERVATION_TYPES2, BRAIN_OBSERVATION_SOURCE_TYPES, BRAIN_MEMORY_TYPES, BRAIN_STICKY_STATUSES, BRAIN_STICKY_COLORS, BRAIN_STICKY_PRIORITIES, brainDecisions, brainPatterns, brainLearnings, brainObservations, brainStickyNotes, brainMemoryLinks, brainSchemaMeta, BRAIN_NODE_TYPES, BRAIN_EDGE_TYPES, brainPageNodes, brainPageEdges, brainRetrievalLog, brainPlasticityEvents, brainWeightHistory, brainModulators, brainConsolidationEvents;
|
|
9081
9090
|
var init_brain_schema = __esm({
|
|
9082
9091
|
"packages/core/src/store/brain-schema.ts"() {
|
|
9083
9092
|
"use strict";
|
|
@@ -9583,13 +9592,75 @@ var init_brain_schema = __esm({
|
|
|
9583
9592
|
* 'auto:contradiction-detected' | 'auto:consolidation' | 'manual'
|
|
9584
9593
|
*/
|
|
9585
9594
|
provenance: text("provenance"),
|
|
9586
|
-
createdAt: text("created_at").notNull().default(sql2`(datetime('now'))`)
|
|
9595
|
+
createdAt: text("created_at").notNull().default(sql2`(datetime('now'))`),
|
|
9596
|
+
// === T673-M3: Plasticity tracking columns ===
|
|
9597
|
+
/**
|
|
9598
|
+
* ISO 8601 timestamp of the last LTP event applied to this edge.
|
|
9599
|
+
* Used by the decay pass: edges with (now - last_reinforced_at) > decay_threshold_days
|
|
9600
|
+
* receive a per-day weight decay. Null = never reinforced (structural/semantic edges).
|
|
9601
|
+
* Only populated when plasticity_class IN ('hebbian', 'stdp').
|
|
9602
|
+
*
|
|
9603
|
+
* @task T706
|
|
9604
|
+
*/
|
|
9605
|
+
lastReinforcedAt: text("last_reinforced_at"),
|
|
9606
|
+
/**
|
|
9607
|
+
* Count of LTP (potentiation) events applied to this edge lifetime.
|
|
9608
|
+
* Incremented on every LTP write. Used to compute stability_score.
|
|
9609
|
+
*
|
|
9610
|
+
* @task T706
|
|
9611
|
+
*/
|
|
9612
|
+
reinforcementCount: integer("reinforcement_count").notNull().default(0),
|
|
9613
|
+
/**
|
|
9614
|
+
* Plasticity class governing which algorithm(s) write to this edge.
|
|
9615
|
+
*
|
|
9616
|
+
* - 'static': Non-plastic edge (structural, semantic, etc.). Immune to decay.
|
|
9617
|
+
* - 'hebbian': Written by strengthenCoRetrievedEdges. Subject to decay.
|
|
9618
|
+
* - 'stdp': Written or refined by applyStdpPlasticity. Subject to decay + LTD.
|
|
9619
|
+
*
|
|
9620
|
+
* Edges start 'static' for all non-co_retrieved types.
|
|
9621
|
+
* co_retrieved edges start 'hebbian' (seeded by M3 migration), can upgrade to 'stdp'.
|
|
9622
|
+
*
|
|
9623
|
+
* @task T706
|
|
9624
|
+
*/
|
|
9625
|
+
plasticityClass: text("plasticity_class", {
|
|
9626
|
+
enum: ["static", "hebbian", "stdp"]
|
|
9627
|
+
}).notNull().default("static"),
|
|
9628
|
+
/**
|
|
9629
|
+
* ISO 8601 timestamp of the last LTD (depression) event on this edge.
|
|
9630
|
+
* Null = never depressed. Used for debugging and Studio viz animation.
|
|
9631
|
+
*
|
|
9632
|
+
* @task T706
|
|
9633
|
+
*/
|
|
9634
|
+
lastDepressedAt: text("last_depressed_at"),
|
|
9635
|
+
/**
|
|
9636
|
+
* Count of LTD (depression) events applied to this edge lifetime.
|
|
9637
|
+
* Enables analysis of edges that are persistently weakened.
|
|
9638
|
+
*
|
|
9639
|
+
* @task T706
|
|
9640
|
+
*/
|
|
9641
|
+
depressionCount: integer("depression_count").notNull().default(0),
|
|
9642
|
+
/**
|
|
9643
|
+
* Biological-analog stability score: 0.0 (unstable) – 1.0 (consolidated).
|
|
9644
|
+
*
|
|
9645
|
+
* Computed by runConsolidation decay pass as:
|
|
9646
|
+
* stability = tanh(reinforcement_count / 10) × exp(-(days_since_reinforced / 30))
|
|
9647
|
+
*
|
|
9648
|
+
* Null = not yet computed (new edges). Enables fast filtering in decay pass:
|
|
9649
|
+
* edges with stability > 0.9 skip the full decay recalculation.
|
|
9650
|
+
* Updated at session-end consolidation, NOT per-event.
|
|
9651
|
+
*
|
|
9652
|
+
* @task T706
|
|
9653
|
+
*/
|
|
9654
|
+
stabilityScore: real("stability_score")
|
|
9587
9655
|
},
|
|
9588
9656
|
(table) => [
|
|
9589
9657
|
primaryKey({ columns: [table.fromId, table.toId, table.edgeType] }),
|
|
9590
9658
|
index("idx_brain_edges_from").on(table.fromId),
|
|
9591
9659
|
index("idx_brain_edges_to").on(table.toId),
|
|
9592
|
-
index("idx_brain_edges_type").on(table.edgeType)
|
|
9660
|
+
index("idx_brain_edges_type").on(table.edgeType),
|
|
9661
|
+
index("idx_brain_edges_last_reinforced").on(table.lastReinforcedAt),
|
|
9662
|
+
index("idx_brain_edges_plasticity_class").on(table.plasticityClass),
|
|
9663
|
+
index("idx_brain_edges_stability").on(table.stabilityScore)
|
|
9593
9664
|
]
|
|
9594
9665
|
);
|
|
9595
9666
|
brainRetrievalLog = sqliteTable(
|
|
@@ -9598,7 +9669,12 @@ var init_brain_schema = __esm({
|
|
|
9598
9669
|
id: integer("id").primaryKey({ autoIncrement: true }),
|
|
9599
9670
|
/** The search query or fetch IDs that triggered this retrieval. */
|
|
9600
9671
|
query: text("query").notNull(),
|
|
9601
|
-
/**
|
|
9672
|
+
/**
|
|
9673
|
+
* JSON array of entry IDs returned in this retrieval.
|
|
9674
|
+
* Stored as JSON array string: '["obs:A","obs:B"]'.
|
|
9675
|
+
* Always write with JSON.stringify() — NEVER join(',').
|
|
9676
|
+
* Readers call JSON.parse(). Migration M1 converts any pre-existing CSV rows.
|
|
9677
|
+
*/
|
|
9602
9678
|
entryIds: text("entry_ids").notNull(),
|
|
9603
9679
|
/** Number of entries returned. */
|
|
9604
9680
|
entryCount: integer("entry_count").notNull(),
|
|
@@ -9608,12 +9684,26 @@ var init_brain_schema = __esm({
|
|
|
9608
9684
|
tokensUsed: integer("tokens_used"),
|
|
9609
9685
|
/** Session ID (soft FK to tasks.db sessions). Enables grouping retrievals by session for STDP analysis. */
|
|
9610
9686
|
sessionId: text("session_id"),
|
|
9611
|
-
createdAt: text("created_at").notNull().default(sql2`(datetime('now'))`)
|
|
9687
|
+
createdAt: text("created_at").notNull().default(sql2`(datetime('now'))`),
|
|
9688
|
+
// === T673-M1: STDP plasticity columns ===
|
|
9689
|
+
/** Sequence position of this retrieval within a batch query (0-based). */
|
|
9690
|
+
retrievalOrder: integer("retrieval_order"),
|
|
9691
|
+
/** Wall-clock ms since the previous retrieval row in the same batch. */
|
|
9692
|
+
deltaMs: integer("delta_ms"),
|
|
9693
|
+
/**
|
|
9694
|
+
* R-STDP reward signal: scalar [-1.0, +1.0], null = unlabeled.
|
|
9695
|
+
* Populated by backfillRewardSignals() at session end (Step 9a).
|
|
9696
|
+
* +1.0 = task verified and passed | +0.5 = done (unverified) | -0.5 = cancelled.
|
|
9697
|
+
* Per D-BRAIN-VIZ-13. backfillRewardSignals MUST skip rows where
|
|
9698
|
+
* session_id LIKE 'ses_backfill_%' (synthetic historical sessions, no task correlation).
|
|
9699
|
+
*/
|
|
9700
|
+
rewardSignal: real("reward_signal")
|
|
9612
9701
|
},
|
|
9613
9702
|
(table) => [
|
|
9614
9703
|
index("idx_retrieval_log_created").on(table.createdAt),
|
|
9615
9704
|
index("idx_retrieval_log_source").on(table.source),
|
|
9616
|
-
index("idx_retrieval_log_session").on(table.sessionId)
|
|
9705
|
+
index("idx_retrieval_log_session").on(table.sessionId),
|
|
9706
|
+
index("idx_retrieval_log_reward").on(table.rewardSignal)
|
|
9617
9707
|
]
|
|
9618
9708
|
);
|
|
9619
9709
|
brainPlasticityEvents = sqliteTable(
|
|
@@ -9637,14 +9727,182 @@ var init_brain_schema = __esm({
|
|
|
9637
9727
|
/** ISO 8601 timestamp when this event was applied. */
|
|
9638
9728
|
timestamp: text("timestamp").notNull().default(sql2`(datetime('now'))`),
|
|
9639
9729
|
/** Session ID that triggered the STDP pass, if available. */
|
|
9640
|
-
sessionId: text("session_id")
|
|
9730
|
+
sessionId: text("session_id"),
|
|
9731
|
+
// === T673-M2: Observability columns ===
|
|
9732
|
+
/**
|
|
9733
|
+
* Edge weight immediately BEFORE this plasticity event was applied.
|
|
9734
|
+
* Null on the first LTP event that inserts a new edge (edge didn't exist).
|
|
9735
|
+
* Enables "show learning history" in Studio viz without querying brain_weight_history.
|
|
9736
|
+
*
|
|
9737
|
+
* @task T696
|
|
9738
|
+
*/
|
|
9739
|
+
weightBefore: real("weight_before"),
|
|
9740
|
+
/**
|
|
9741
|
+
* Edge weight immediately AFTER this plasticity event was applied.
|
|
9742
|
+
* Computed as CLAMP(weight_before + delta_w, 0.0, 1.0).
|
|
9743
|
+
* Redundant with delta_w but enables fast before/after display without arithmetic.
|
|
9744
|
+
*
|
|
9745
|
+
* @task T696
|
|
9746
|
+
*/
|
|
9747
|
+
weightAfter: real("weight_after"),
|
|
9748
|
+
/**
|
|
9749
|
+
* Soft FK to brain_retrieval_log.id — the retrieval row that triggered this pair.
|
|
9750
|
+
* Null for externally-triggered or legacy events.
|
|
9751
|
+
* Enables: "which memory retrieval caused this edge to strengthen?"
|
|
9752
|
+
*
|
|
9753
|
+
* @task T696
|
|
9754
|
+
*/
|
|
9755
|
+
retrievalLogId: integer("retrieval_log_id"),
|
|
9756
|
+
/**
|
|
9757
|
+
* R-STDP reward signal active when this event fired.
|
|
9758
|
+
* Copied from the retrieval_log row's reward_signal at time of plasticity pass.
|
|
9759
|
+
* Null = unmodulated. Denormalized for fast filtering without a JOIN.
|
|
9760
|
+
*
|
|
9761
|
+
* @task T696
|
|
9762
|
+
*/
|
|
9763
|
+
rewardSignal: real("reward_signal"),
|
|
9764
|
+
/**
|
|
9765
|
+
* Wall-clock milliseconds between the two spikes that generated this event.
|
|
9766
|
+
* Pre-computed at INSERT time — avoids re-deriving from retrieval timestamps.
|
|
9767
|
+
* Enables analysis of STDP window distribution.
|
|
9768
|
+
*
|
|
9769
|
+
* @task T696
|
|
9770
|
+
*/
|
|
9771
|
+
deltaTMs: integer("delta_t_ms")
|
|
9641
9772
|
},
|
|
9642
9773
|
(table) => [
|
|
9643
9774
|
index("idx_plasticity_source").on(table.sourceNode),
|
|
9644
9775
|
index("idx_plasticity_target").on(table.targetNode),
|
|
9645
9776
|
index("idx_plasticity_timestamp").on(table.timestamp),
|
|
9646
9777
|
index("idx_plasticity_session").on(table.sessionId),
|
|
9647
|
-
index("idx_plasticity_kind").on(table.kind)
|
|
9778
|
+
index("idx_plasticity_kind").on(table.kind),
|
|
9779
|
+
index("idx_plasticity_retrieval_log").on(table.retrievalLogId),
|
|
9780
|
+
index("idx_plasticity_reward").on(table.rewardSignal)
|
|
9781
|
+
]
|
|
9782
|
+
);
|
|
9783
|
+
brainWeightHistory = sqliteTable(
|
|
9784
|
+
"brain_weight_history",
|
|
9785
|
+
{
|
|
9786
|
+
id: integer("id").primaryKey({ autoIncrement: true }),
|
|
9787
|
+
/** from_id of the affected brain_page_edges row. */
|
|
9788
|
+
edgeFromId: text("edge_from_id").notNull(),
|
|
9789
|
+
/** to_id of the affected brain_page_edges row. */
|
|
9790
|
+
edgeToId: text("edge_to_id").notNull(),
|
|
9791
|
+
/** Edge type of the affected brain_page_edges row (e.g. 'co_retrieved'). */
|
|
9792
|
+
edgeType: text("edge_type").notNull(),
|
|
9793
|
+
/** Edge weight immediately before this event. Null if the edge was just created. */
|
|
9794
|
+
weightBefore: real("weight_before"),
|
|
9795
|
+
/** Edge weight after this event. CLAMP(weightBefore + deltaWeight, 0, 1). NOT NULL. */
|
|
9796
|
+
weightAfter: real("weight_after").notNull(),
|
|
9797
|
+
/**
|
|
9798
|
+
* Signed weight delta applied to the edge.
|
|
9799
|
+
* Positive = potentiation (LTP/Hebbian), negative = depression (LTD).
|
|
9800
|
+
* Prune events record the final weight that triggered deletion (negative).
|
|
9801
|
+
*/
|
|
9802
|
+
deltaWeight: real("delta_weight").notNull(),
|
|
9803
|
+
/**
|
|
9804
|
+
* Plasticity event kind.
|
|
9805
|
+
* 'ltp' — Long-Term Potentiation (STDP pre-before-post)
|
|
9806
|
+
* 'ltd' — Long-Term Depression (STDP post-before-pre)
|
|
9807
|
+
* 'hebbian' — Co-retrieval Hebbian strengthening
|
|
9808
|
+
* 'decay' — Temporal decay (only prune-triggering decays written here)
|
|
9809
|
+
* 'prune' — Edge deleted (weight fell below min_weight threshold)
|
|
9810
|
+
* 'external' — Manually-applied external weight change
|
|
9811
|
+
*/
|
|
9812
|
+
eventKind: text("event_kind").notNull(),
|
|
9813
|
+
/** Soft FK to brain_plasticity_events.id — the STDP event that caused this. */
|
|
9814
|
+
sourcePlasticityEventId: integer("source_plasticity_event_id"),
|
|
9815
|
+
/** Soft FK to brain_retrieval_log.id — the retrieval batch that triggered this. */
|
|
9816
|
+
retrievalLogId: integer("retrieval_log_id"),
|
|
9817
|
+
/** R-STDP reward signal at time of event (copied from retrieval_log.reward_signal). */
|
|
9818
|
+
rewardSignal: real("reward_signal"),
|
|
9819
|
+
/** ISO 8601 timestamp when this weight change was applied. */
|
|
9820
|
+
changedAt: text("changed_at").notNull().default(sql2`(datetime('now'))`)
|
|
9821
|
+
},
|
|
9822
|
+
(table) => [
|
|
9823
|
+
index("idx_weight_history_edge").on(table.edgeFromId, table.edgeToId, table.edgeType),
|
|
9824
|
+
index("idx_weight_history_from").on(table.edgeFromId),
|
|
9825
|
+
index("idx_weight_history_to").on(table.edgeToId),
|
|
9826
|
+
index("idx_weight_history_changed_at").on(table.changedAt),
|
|
9827
|
+
index("idx_weight_history_event_kind").on(table.eventKind),
|
|
9828
|
+
index("idx_weight_history_plasticity_event").on(table.sourcePlasticityEventId)
|
|
9829
|
+
]
|
|
9830
|
+
);
|
|
9831
|
+
brainModulators = sqliteTable(
|
|
9832
|
+
"brain_modulators",
|
|
9833
|
+
{
|
|
9834
|
+
id: integer("id").primaryKey({ autoIncrement: true }),
|
|
9835
|
+
/**
|
|
9836
|
+
* Modulator event type. String (not enum constraint) for extensibility.
|
|
9837
|
+
* Expected values: 'task_verified'|'task_completed'|'task_cancelled'|
|
|
9838
|
+
* 'owner_verify'|'session_success'|'session_blocker'|'external'
|
|
9839
|
+
*/
|
|
9840
|
+
modulatorType: text("modulator_type").notNull(),
|
|
9841
|
+
/**
|
|
9842
|
+
* Reward valence in range [-1.0, +1.0].
|
|
9843
|
+
* +1.0 = strong reward (verified correct task)
|
|
9844
|
+
* +0.5 = moderate reward (done, unverified)
|
|
9845
|
+
* -0.5 = mild correction (cancelled task)
|
|
9846
|
+
* -1.0 = strong correction (explicit invalidation)
|
|
9847
|
+
* 0.0 = neutral signal
|
|
9848
|
+
*/
|
|
9849
|
+
valence: real("valence").notNull(),
|
|
9850
|
+
/**
|
|
9851
|
+
* Magnitude 0.0–1.0 confidence scaling.
|
|
9852
|
+
* Effective reward = valence × magnitude.
|
|
9853
|
+
* Defaults to 1.0 (full confidence).
|
|
9854
|
+
*/
|
|
9855
|
+
magnitude: real("magnitude").notNull().default(1),
|
|
9856
|
+
/** Polymorphic source event ID — task ID, memory entry ID, or other string ref. */
|
|
9857
|
+
sourceEventId: text("source_event_id"),
|
|
9858
|
+
/** Session ID (soft FK to tasks.db sessions). */
|
|
9859
|
+
sessionId: text("session_id"),
|
|
9860
|
+
/** Human-readable description of why this modulator was emitted. */
|
|
9861
|
+
description: text("description"),
|
|
9862
|
+
/** ISO 8601 timestamp when this modulator event was recorded. */
|
|
9863
|
+
createdAt: text("created_at").notNull().default(sql2`(datetime('now'))`)
|
|
9864
|
+
},
|
|
9865
|
+
(table) => [
|
|
9866
|
+
index("idx_modulators_type").on(table.modulatorType),
|
|
9867
|
+
index("idx_modulators_session").on(table.sessionId),
|
|
9868
|
+
index("idx_modulators_created_at").on(table.createdAt),
|
|
9869
|
+
index("idx_modulators_source_event").on(table.sourceEventId),
|
|
9870
|
+
index("idx_modulators_valence").on(table.valence)
|
|
9871
|
+
]
|
|
9872
|
+
);
|
|
9873
|
+
brainConsolidationEvents = sqliteTable(
|
|
9874
|
+
"brain_consolidation_events",
|
|
9875
|
+
{
|
|
9876
|
+
id: integer("id").primaryKey({ autoIncrement: true }),
|
|
9877
|
+
/**
|
|
9878
|
+
* What triggered this consolidation run. String (not enum constraint) for
|
|
9879
|
+
* forward compatibility with T628 scheduler.
|
|
9880
|
+
* Expected values: 'session_end' | 'maintenance' | 'scheduled' | 'manual'
|
|
9881
|
+
*/
|
|
9882
|
+
trigger: text("trigger").notNull(),
|
|
9883
|
+
/** Session ID that initiated this consolidation (soft FK to tasks.db sessions). */
|
|
9884
|
+
sessionId: text("session_id"),
|
|
9885
|
+
/**
|
|
9886
|
+
* JSON-serialized ConsolidationResult — all per-step counts and metrics.
|
|
9887
|
+
* Shape: { [stepName: string]: { count: number, durationMs?: number } }
|
|
9888
|
+
* Required NOT NULL — every run must record its results for T628 scheduling.
|
|
9889
|
+
*/
|
|
9890
|
+
stepResultsJson: text("step_results_json").notNull(),
|
|
9891
|
+
/** Wall-clock milliseconds from start to completion. Null if run did not complete. */
|
|
9892
|
+
durationMs: integer("duration_ms"),
|
|
9893
|
+
/**
|
|
9894
|
+
* Whether the run succeeded.
|
|
9895
|
+
* Stored as integer(boolean) per Drizzle SQLite boolean convention.
|
|
9896
|
+
* true = completed without unhandled error, false = partial or error.
|
|
9897
|
+
*/
|
|
9898
|
+
succeeded: integer("succeeded", { mode: "boolean" }).notNull().default(true),
|
|
9899
|
+
/** ISO 8601 timestamp when this consolidation run started. */
|
|
9900
|
+
startedAt: text("started_at").notNull().default(sql2`(datetime('now'))`)
|
|
9901
|
+
},
|
|
9902
|
+
(table) => [
|
|
9903
|
+
index("idx_consolidation_events_started_at").on(table.startedAt),
|
|
9904
|
+
index("idx_consolidation_events_trigger").on(table.trigger),
|
|
9905
|
+
index("idx_consolidation_events_session").on(table.sessionId)
|
|
9648
9906
|
]
|
|
9649
9907
|
);
|
|
9650
9908
|
}
|
|
@@ -15063,6 +15321,108 @@ function runBrainMigrations(nativeDb, db) {
|
|
|
15063
15321
|
AND provenance LIKE 'consolidation:%'`
|
|
15064
15322
|
).run();
|
|
15065
15323
|
}
|
|
15324
|
+
if (tableExists(nativeDb, "brain_retrieval_log")) {
|
|
15325
|
+
ensureColumns(
|
|
15326
|
+
nativeDb,
|
|
15327
|
+
"brain_retrieval_log",
|
|
15328
|
+
[
|
|
15329
|
+
{ name: "session_id", ddl: "text" },
|
|
15330
|
+
{ name: "reward_signal", ddl: "real" },
|
|
15331
|
+
{ name: "retrieval_order", ddl: "integer" },
|
|
15332
|
+
{ name: "delta_ms", ddl: "integer" }
|
|
15333
|
+
],
|
|
15334
|
+
"brain"
|
|
15335
|
+
);
|
|
15336
|
+
}
|
|
15337
|
+
if (tableExists(nativeDb, "brain_plasticity_events")) {
|
|
15338
|
+
ensureColumns(
|
|
15339
|
+
nativeDb,
|
|
15340
|
+
"brain_plasticity_events",
|
|
15341
|
+
[
|
|
15342
|
+
{ name: "session_id", ddl: "text" },
|
|
15343
|
+
{ name: "weight_before", ddl: "real" },
|
|
15344
|
+
{ name: "weight_after", ddl: "real" },
|
|
15345
|
+
{ name: "retrieval_log_id", ddl: "integer" },
|
|
15346
|
+
{ name: "reward_signal", ddl: "real" },
|
|
15347
|
+
{ name: "delta_t_ms", ddl: "integer" }
|
|
15348
|
+
],
|
|
15349
|
+
"brain"
|
|
15350
|
+
);
|
|
15351
|
+
}
|
|
15352
|
+
ensureColumns(
|
|
15353
|
+
nativeDb,
|
|
15354
|
+
"brain_page_edges",
|
|
15355
|
+
[
|
|
15356
|
+
{ name: "last_reinforced_at", ddl: "text" },
|
|
15357
|
+
{ name: "reinforcement_count", ddl: "integer NOT NULL DEFAULT 0" },
|
|
15358
|
+
{ name: "plasticity_class", ddl: "text NOT NULL DEFAULT 'static'" },
|
|
15359
|
+
{ name: "last_depressed_at", ddl: "text" },
|
|
15360
|
+
{ name: "depression_count", ddl: "integer NOT NULL DEFAULT 0" },
|
|
15361
|
+
{ name: "stability_score", ddl: "real" }
|
|
15362
|
+
],
|
|
15363
|
+
"brain"
|
|
15364
|
+
);
|
|
15365
|
+
if (tableExists(nativeDb, "brain_page_edges")) {
|
|
15366
|
+
nativeDb.prepare(
|
|
15367
|
+
`UPDATE brain_page_edges SET plasticity_class = 'hebbian'
|
|
15368
|
+
WHERE edge_type = 'co_retrieved' AND plasticity_class = 'static'`
|
|
15369
|
+
).run();
|
|
15370
|
+
}
|
|
15371
|
+
nativeDb.exec(
|
|
15372
|
+
`CREATE TABLE IF NOT EXISTS brain_weight_history (
|
|
15373
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
15374
|
+
edge_from_id TEXT NOT NULL,
|
|
15375
|
+
edge_to_id TEXT NOT NULL,
|
|
15376
|
+
edge_type TEXT NOT NULL,
|
|
15377
|
+
weight_before REAL,
|
|
15378
|
+
weight_after REAL NOT NULL,
|
|
15379
|
+
delta_weight REAL NOT NULL,
|
|
15380
|
+
event_kind TEXT NOT NULL,
|
|
15381
|
+
source_plasticity_event_id INTEGER,
|
|
15382
|
+
retrieval_log_id INTEGER,
|
|
15383
|
+
reward_signal REAL,
|
|
15384
|
+
changed_at TEXT NOT NULL DEFAULT (datetime('now'))
|
|
15385
|
+
)`
|
|
15386
|
+
);
|
|
15387
|
+
nativeDb.exec(
|
|
15388
|
+
`CREATE INDEX IF NOT EXISTS idx_weight_history_edge
|
|
15389
|
+
ON brain_weight_history (edge_from_id, edge_to_id, edge_type)`
|
|
15390
|
+
);
|
|
15391
|
+
nativeDb.exec(
|
|
15392
|
+
`CREATE INDEX IF NOT EXISTS idx_weight_history_changed_at
|
|
15393
|
+
ON brain_weight_history (changed_at)`
|
|
15394
|
+
);
|
|
15395
|
+
nativeDb.exec(
|
|
15396
|
+
`CREATE TABLE IF NOT EXISTS brain_modulators (
|
|
15397
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
15398
|
+
modulator_type TEXT NOT NULL,
|
|
15399
|
+
valence REAL NOT NULL,
|
|
15400
|
+
magnitude REAL NOT NULL DEFAULT 1.0,
|
|
15401
|
+
source_event_id TEXT,
|
|
15402
|
+
session_id TEXT,
|
|
15403
|
+
description TEXT,
|
|
15404
|
+
created_at TEXT NOT NULL DEFAULT (datetime('now'))
|
|
15405
|
+
)`
|
|
15406
|
+
);
|
|
15407
|
+
nativeDb.exec(
|
|
15408
|
+
`CREATE INDEX IF NOT EXISTS idx_modulators_session
|
|
15409
|
+
ON brain_modulators (session_id)`
|
|
15410
|
+
);
|
|
15411
|
+
nativeDb.exec(
|
|
15412
|
+
`CREATE TABLE IF NOT EXISTS brain_consolidation_events (
|
|
15413
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
15414
|
+
trigger TEXT NOT NULL,
|
|
15415
|
+
session_id TEXT,
|
|
15416
|
+
step_results_json TEXT NOT NULL,
|
|
15417
|
+
duration_ms INTEGER,
|
|
15418
|
+
succeeded INTEGER NOT NULL DEFAULT 1,
|
|
15419
|
+
started_at TEXT NOT NULL DEFAULT (datetime('now'))
|
|
15420
|
+
)`
|
|
15421
|
+
);
|
|
15422
|
+
nativeDb.exec(
|
|
15423
|
+
`CREATE INDEX IF NOT EXISTS idx_consolidation_events_started_at
|
|
15424
|
+
ON brain_consolidation_events (started_at)`
|
|
15425
|
+
);
|
|
15066
15426
|
}
|
|
15067
15427
|
function loadBrainVecExtension(nativeDb) {
|
|
15068
15428
|
try {
|
|
@@ -18638,13 +18998,48 @@ var init_adrs = __esm({
|
|
|
18638
18998
|
var brain_accessor_exports = {};
|
|
18639
18999
|
__export(brain_accessor_exports, {
|
|
18640
19000
|
BrainDataAccessor: () => BrainDataAccessor,
|
|
18641
|
-
getBrainAccessor: () => getBrainAccessor
|
|
19001
|
+
getBrainAccessor: () => getBrainAccessor,
|
|
19002
|
+
insertModulatorRow: () => insertModulatorRow,
|
|
19003
|
+
insertWeightHistoryRow: () => insertWeightHistoryRow,
|
|
19004
|
+
logConsolidationComplete: () => logConsolidationComplete,
|
|
19005
|
+
logConsolidationStart: () => logConsolidationStart
|
|
18642
19006
|
});
|
|
18643
19007
|
import { and as and5, asc as asc2, desc as desc2, eq as eq7, gte as gte2, or as or4 } from "drizzle-orm";
|
|
18644
19008
|
async function getBrainAccessor(cwd) {
|
|
18645
19009
|
const db = await getBrainDb(cwd);
|
|
18646
19010
|
return new BrainDataAccessor(db);
|
|
18647
19011
|
}
|
|
19012
|
+
async function insertWeightHistoryRow(cwd, input) {
|
|
19013
|
+
const db = await getBrainDb(cwd);
|
|
19014
|
+
const result = await db.insert(brainWeightHistory).values(input).returning();
|
|
19015
|
+
return result[0];
|
|
19016
|
+
}
|
|
19017
|
+
async function insertModulatorRow(cwd, input) {
|
|
19018
|
+
const db = await getBrainDb(cwd);
|
|
19019
|
+
const result = await db.insert(brainModulators).values(input).returning();
|
|
19020
|
+
return result[0];
|
|
19021
|
+
}
|
|
19022
|
+
async function logConsolidationStart(cwd, trigger, sessionId) {
|
|
19023
|
+
const db = await getBrainDb(cwd);
|
|
19024
|
+
const result = await db.insert(brainConsolidationEvents).values({
|
|
19025
|
+
trigger,
|
|
19026
|
+
sessionId: sessionId ?? null,
|
|
19027
|
+
// stepResultsJson is required NOT NULL — use empty object as placeholder
|
|
19028
|
+
// until logConsolidationComplete updates it with final step results.
|
|
19029
|
+
stepResultsJson: "{}",
|
|
19030
|
+
succeeded: true
|
|
19031
|
+
}).returning({ id: brainConsolidationEvents.id });
|
|
19032
|
+
return result[0].id;
|
|
19033
|
+
}
|
|
19034
|
+
async function logConsolidationComplete(cwd, id, stats2, durationMs, succeeded = true) {
|
|
19035
|
+
const db = await getBrainDb(cwd);
|
|
19036
|
+
const result = await db.update(brainConsolidationEvents).set({
|
|
19037
|
+
stepResultsJson: JSON.stringify(stats2),
|
|
19038
|
+
durationMs,
|
|
19039
|
+
succeeded
|
|
19040
|
+
}).where(eq7(brainConsolidationEvents.id, id)).returning();
|
|
19041
|
+
return result[0];
|
|
19042
|
+
}
|
|
18648
19043
|
var BrainDataAccessor;
|
|
18649
19044
|
var init_brain_accessor = __esm({
|
|
18650
19045
|
"packages/core/src/store/brain-accessor.ts"() {
|
|
@@ -52314,7 +52709,7 @@ async function logRetrieval(projectRoot, query, entryIds, source, tokensUsed, se
|
|
|
52314
52709
|
"INSERT INTO brain_retrieval_log (query, entry_ids, entry_count, source, tokens_used, session_id) VALUES (?, ?, ?, ?, ?, ?)"
|
|
52315
52710
|
).run(
|
|
52316
52711
|
query,
|
|
52317
|
-
|
|
52712
|
+
JSON.stringify(entryIds),
|
|
52318
52713
|
entryIds.length,
|
|
52319
52714
|
source,
|
|
52320
52715
|
tokensUsed ?? null,
|
|
@@ -79319,6 +79714,85 @@ function checkLegacyAgentOutputs(projectRoot) {
|
|
|
79319
79714
|
fix: null
|
|
79320
79715
|
};
|
|
79321
79716
|
}
|
|
79717
|
+
function checkCanonicalRcasdPaths(projectRoot) {
|
|
79718
|
+
const root = projectRoot ?? process.cwd();
|
|
79719
|
+
const cleoDir = join93(root, ".cleo");
|
|
79720
|
+
const failures = [];
|
|
79721
|
+
const deprecatedDirs = ["research", "consensus", "specs", "decomposition"];
|
|
79722
|
+
for (const dir of deprecatedDirs) {
|
|
79723
|
+
const dirPath = join93(cleoDir, dir);
|
|
79724
|
+
if (existsSync91(dirPath)) {
|
|
79725
|
+
try {
|
|
79726
|
+
const entries = __require("node:fs").readdirSync(dirPath).filter(
|
|
79727
|
+
(e) => !e.startsWith(".")
|
|
79728
|
+
);
|
|
79729
|
+
if (entries.length > 0) {
|
|
79730
|
+
failures.push(
|
|
79731
|
+
`deprecated .cleo/${dir}/ contains files (should migrate to .cleo/rcasd/{epicId}/${dir}/)`
|
|
79732
|
+
);
|
|
79733
|
+
}
|
|
79734
|
+
} catch {
|
|
79735
|
+
}
|
|
79736
|
+
}
|
|
79737
|
+
}
|
|
79738
|
+
const rcasdPath = join93(cleoDir, "rcasd");
|
|
79739
|
+
if (existsSync91(rcasdPath)) {
|
|
79740
|
+
try {
|
|
79741
|
+
const rootFiles = __require("node:fs").readdirSync(rcasdPath).filter(
|
|
79742
|
+
(e) => e.endsWith(".md")
|
|
79743
|
+
);
|
|
79744
|
+
if (rootFiles.length > 0) {
|
|
79745
|
+
failures.push(
|
|
79746
|
+
`misplaced .md files in .cleo/rcasd/ root (audit-*.md, etc. should be in .cleo/agent-outputs/)`
|
|
79747
|
+
);
|
|
79748
|
+
}
|
|
79749
|
+
} catch {
|
|
79750
|
+
}
|
|
79751
|
+
}
|
|
79752
|
+
const claudedocsPath = join93(root, "claudedocs");
|
|
79753
|
+
if (existsSync91(claudedocsPath)) {
|
|
79754
|
+
try {
|
|
79755
|
+
const agentOutputs = join93(claudedocsPath, "agent-outputs");
|
|
79756
|
+
if (existsSync91(agentOutputs)) {
|
|
79757
|
+
failures.push(
|
|
79758
|
+
`legacy claudedocs/agent-outputs/ directory exists (should migrate to .cleo/agent-outputs/)`
|
|
79759
|
+
);
|
|
79760
|
+
}
|
|
79761
|
+
} catch {
|
|
79762
|
+
}
|
|
79763
|
+
}
|
|
79764
|
+
if (failures.length > 0) {
|
|
79765
|
+
return {
|
|
79766
|
+
id: "canonical_rcasd_paths",
|
|
79767
|
+
category: "configuration",
|
|
79768
|
+
status: "warning",
|
|
79769
|
+
message: `Canonical path drift detected (ADR-045): ${failures.join("; ")}`,
|
|
79770
|
+
details: {
|
|
79771
|
+
issues: failures,
|
|
79772
|
+
canonical: {
|
|
79773
|
+
rcasdStages: ".cleo/rcasd/{epicId}/{stage}/{epicId}-{stage}.md",
|
|
79774
|
+
agentOutputs: ".cleo/agent-outputs/{taskId}-{slug}.md",
|
|
79775
|
+
publishedSpecs: "docs/specs/SPEC-NAME.md"
|
|
79776
|
+
}
|
|
79777
|
+
},
|
|
79778
|
+
fix: "cleo upgrade (migrates old paths) or manually move files per ADR-045"
|
|
79779
|
+
};
|
|
79780
|
+
}
|
|
79781
|
+
return {
|
|
79782
|
+
id: "canonical_rcasd_paths",
|
|
79783
|
+
category: "configuration",
|
|
79784
|
+
status: "passed",
|
|
79785
|
+
message: "All artifacts at canonical RCASD paths (ADR-045 compliant)",
|
|
79786
|
+
details: {
|
|
79787
|
+
canonical: {
|
|
79788
|
+
rcasdStages: ".cleo/rcasd/{epicId}/{stage}/{epicId}-{stage}.md",
|
|
79789
|
+
agentOutputs: ".cleo/agent-outputs/{taskId}-{slug}.md",
|
|
79790
|
+
publishedSpecs: "docs/specs/SPEC-NAME.md"
|
|
79791
|
+
}
|
|
79792
|
+
},
|
|
79793
|
+
fix: null
|
|
79794
|
+
};
|
|
79795
|
+
}
|
|
79322
79796
|
function checkCaampMarkerIntegrity(projectRoot) {
|
|
79323
79797
|
const root = projectRoot ?? process.cwd();
|
|
79324
79798
|
const files = ["CLAUDE.md", "AGENTS.md"];
|
|
@@ -79631,6 +80105,8 @@ function runAllGlobalChecks(cleoHome, projectRoot) {
|
|
|
79631
80105
|
checkCoreFilesNotIgnored(projectRoot),
|
|
79632
80106
|
checkSqliteNotTracked(projectRoot),
|
|
79633
80107
|
checkLegacyAgentOutputs(projectRoot),
|
|
80108
|
+
// ADR-045 canonical paths check (T708)
|
|
80109
|
+
checkCanonicalRcasdPaths(projectRoot),
|
|
79634
80110
|
// Injection chain checks (T5153)
|
|
79635
80111
|
checkCaampMarkerIntegrity(projectRoot),
|
|
79636
80112
|
checkAtReferenceTargetExists(projectRoot),
|
|
@@ -80855,6 +81331,7 @@ async function coreDoctorReport(projectRoot) {
|
|
|
80855
81331
|
checks.push(mapCheckResult(checkVitalFilesTracked(projectRoot)));
|
|
80856
81332
|
checks.push(mapCheckResult(checkCoreFilesNotIgnored(projectRoot)));
|
|
80857
81333
|
checks.push(mapCheckResult(checkLegacyAgentOutputs(projectRoot)));
|
|
81334
|
+
checks.push(mapCheckResult(checkCanonicalRcasdPaths(projectRoot)));
|
|
80858
81335
|
const cleoGitHeadExists = existsSync92(join94(cleoDir, ".git", "HEAD"));
|
|
80859
81336
|
checks.push({
|
|
80860
81337
|
check: "cleo_git_repo",
|
|
@@ -91994,7 +92471,14 @@ function mapEdge(raw) {
|
|
|
91994
92471
|
edgeType: raw.edge_type,
|
|
91995
92472
|
weight: raw.weight,
|
|
91996
92473
|
provenance: raw.provenance,
|
|
91997
|
-
createdAt: raw.created_at
|
|
92474
|
+
createdAt: raw.created_at,
|
|
92475
|
+
// T673-M3 plasticity columns (default to neutral values if absent from SELECT)
|
|
92476
|
+
lastReinforcedAt: raw.last_reinforced_at ?? null,
|
|
92477
|
+
reinforcementCount: raw.reinforcement_count ?? 0,
|
|
92478
|
+
plasticityClass: raw.plasticity_class ?? "static",
|
|
92479
|
+
lastDepressedAt: raw.last_depressed_at ?? null,
|
|
92480
|
+
depressionCount: raw.depression_count ?? 0,
|
|
92481
|
+
stabilityScore: raw.stability_score ?? null
|
|
91998
92482
|
};
|
|
91999
92483
|
}
|
|
92000
92484
|
async function traceBrainGraph(projectRoot, nodeId, maxDepth = 3) {
|