hippo-memory 3.3.3 → 3.4.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.
- package/dist/api/context/context-pools.js +2 -1
- package/dist/api/context/user-rule.js +2 -1
- package/dist/api/dashboard/detail.js +2 -1
- package/dist/api/dashboard/live.d.ts +0 -4
- package/dist/api/dashboard/live.js +0 -8
- package/dist/api/memories/conflicts.d.ts +2 -1
- package/dist/api/memories/conflicts.js +3 -8
- package/dist/api/memories/promote.js +6 -2
- package/dist/api/recall/compose.js +2 -1
- package/dist/api/recall/rank-stages.js +2 -1
- package/dist/api/recall/rows.js +2 -1
- package/dist/api/sleep/sleep-run.js +2 -1
- package/dist/api/summary-parents.js +2 -1
- package/dist/base/memory/ambient.js +2 -1
- package/dist/base/memory/entry.d.ts +4 -1
- package/dist/base/memory/entry.js +7 -1
- package/dist/base/memory/half-life-plan.js +6 -4
- package/dist/base/memory/keep-rules.js +2 -1
- package/dist/base/memory/liveness.d.ts +7 -0
- package/dist/base/memory/liveness.js +6 -0
- package/dist/base/memory/markdown.js +15 -5
- package/dist/base/memory/memory-audit.js +2 -1
- package/dist/base/memory/memory-facts.d.ts +0 -2
- package/dist/base/memory/memory-facts.js +0 -2
- package/dist/base/memory/merged-row.js +3 -2
- package/dist/base/memory/rule-replaces.js +2 -1
- package/dist/base/memory/stale-mark.d.ts +9 -0
- package/dist/base/memory/stale-mark.js +18 -0
- package/dist/base/ports/store/conflicts.d.ts +5 -1
- package/dist/base/ports/store/conflicts.js +2 -0
- package/dist/base/ports/store/consolidation.d.ts +51 -2
- package/dist/base/ports/store/consolidation.js +3 -0
- package/dist/base/ports/store/sessions.d.ts +8 -2
- package/dist/base/ports/store/sessions.js +6 -0
- package/dist/base/ports/store/store-effects.d.ts +3 -0
- package/dist/base/scope/live-memory.d.ts +7 -0
- package/dist/base/scope/live-memory.js +10 -0
- package/dist/base/scope/read-admission.js +2 -1
- package/dist/base/util/version.d.ts +1 -1
- package/dist/base/util/version.js +1 -1
- package/dist/db/continuity-tables.d.ts +4 -1
- package/dist/db/continuity-tables.js +21 -12
- package/dist/db/migrate.js +2 -2
- package/dist/db/migrations/index.d.ts +1 -1
- package/dist/db/migrations/index.js +3 -1
- package/dist/db/migrations/v61.js +3 -3
- package/dist/db/migrations/v62.d.ts +3 -0
- package/dist/db/migrations/v62.js +43 -0
- package/dist/db/required-objects.js +2 -1
- package/dist/db/sql-predicates.d.ts +22 -2
- package/dist/db/sql-predicates.js +27 -2
- package/dist/domain/agent-memories/apply.js +2 -1
- package/dist/domain/agent-memories/container-view.js +2 -1
- package/dist/domain/consolidate/conflicts.js +2 -1
- package/dist/domain/consolidate/dag-summary.d.ts +2 -0
- package/dist/domain/consolidate/dag.d.ts +3 -0
- package/dist/domain/consolidate/dag.js +53 -8
- package/dist/domain/consolidate/dedupe.js +2 -1
- package/dist/domain/consolidate/events.d.ts +2 -0
- package/dist/domain/consolidate/llm-passes.js +94 -20
- package/dist/domain/consolidate/merge.js +5 -4
- package/dist/domain/consolidate/retry-holds.d.ts +14 -0
- package/dist/domain/consolidate/retry-holds.js +26 -0
- package/dist/domain/consolidate/run.d.ts +8 -0
- package/dist/domain/consolidate/run.js +2 -0
- package/dist/domain/graph/recall.js +3 -2
- package/dist/domain/learn/churn-stale.js +2 -1
- package/dist/domain/learn/extract.d.ts +10 -0
- package/dist/domain/learn/extract.js +10 -5
- package/dist/domain/learn/invalidation.d.ts +1 -1
- package/dist/domain/learn/invalidation.js +4 -11
- package/dist/domain/objects/decisions.d.ts +2 -2
- package/dist/domain/objects/decisions.js +4 -9
- package/dist/domain/search/as-of.js +3 -2
- package/dist/store/sqlite/capture/compaction-rows.js +9 -2
- package/dist/store/sqlite/connectors/quarantine.js +13 -4
- package/dist/store/sqlite/consolidation/consolidation-summaries.d.ts +4 -5
- package/dist/store/sqlite/consolidation/consolidation-summaries.js +46 -26
- package/dist/store/sqlite/consolidation/consolidation.js +5 -0
- package/dist/store/sqlite/consolidation/empty-extractions.d.ts +14 -0
- package/dist/store/sqlite/consolidation/empty-extractions.js +57 -0
- package/dist/store/sqlite/consolidation/rebuild-holds.d.ts +21 -0
- package/dist/store/sqlite/consolidation/rebuild-holds.js +68 -0
- package/dist/store/sqlite/entries/entry-filter.js +2 -1
- package/dist/store/sqlite/entries/entry-reads.js +2 -1
- package/dist/store/sqlite/entries/entry-writes.js +6 -5
- package/dist/store/sqlite/maintenance/agent-import-steps.js +7 -2
- package/dist/store/sqlite/maintenance/project-tags.js +4 -3
- package/dist/store/sqlite/recall/candidates.js +10 -4
- package/dist/store/sqlite/recall/search-rows.js +4 -3
- package/dist/store/sqlite/reports/dashboard-lists.js +3 -2
- package/dist/store/sqlite/reports/dashboard-reads.js +5 -3
- package/dist/store/sqlite/reports/dashboard-sql.d.ts +0 -3
- package/dist/store/sqlite/reports/dashboard-sql.js +2 -9
- package/dist/store/sqlite/reports/reports.js +2 -1
- package/dist/store/sqlite/review/conflicts.js +7 -1
- package/dist/store/sqlite/runtime/rule-sql.js +2 -1
- package/dist/store/sqlite/runtime/status-transitions.d.ts +98 -0
- package/dist/store/sqlite/runtime/status-transitions.js +105 -0
- package/dist/store/sqlite/sessions/goals.js +11 -12
- package/dist/store/sqlite/sessions/sessions.d.ts +1 -1
- package/dist/store/sqlite/sessions/sessions.js +20 -8
- package/dist/surface/cli/conflicts.js +12 -1
- package/dist/surface/cli/continuity.js +4 -0
- package/dist/surface/cli/print.js +2 -1
- package/dist/surface/cli/verbs/objects.js +2 -2
- package/dist/surface/dashboard/dashboard-actions.js +1 -1
- package/dist/surface/render/sleep-events.js +2 -0
- package/dist-ui/assets/index-Cst0ubfs.js +1 -0
- package/dist-ui/index.html +1 -1
- package/extensions/openclaw-plugin/openclaw.plugin.json +1 -1
- package/extensions/openclaw-plugin/package.json +1 -1
- package/openclaw.plugin.json +1 -1
- package/package.json +1 -1
- package/dist-ui/assets/index-Q9SY-1Bj.js +0 -1
|
@@ -9,6 +9,7 @@ import { EMOTIONAL_MULTIPLIERS, FALLBACK_HALF_LIFE_DAYS, applyLossAversionRatio,
|
|
|
9
9
|
import { KEEP_PAIRS } from '../../../base/memory/keep-rules.js';
|
|
10
10
|
import { PERSONAL_SCOPE_PREFIX, RECALL_DEFAULT_DENY_SCOPES, } from '../../../base/scope/recall-scope.js';
|
|
11
11
|
import { placeholders } from '../../../db/sql.js';
|
|
12
|
+
import { notSupersededIn } from '../../../db/sql-predicates.js';
|
|
12
13
|
import { rewardFactorAt } from '../../../db/decay-key.js';
|
|
13
14
|
import { SPACE_CODES } from '../../rules/copies.js';
|
|
14
15
|
const UNIX_EPOCH_JULIAN_DAY = 2440587.5;
|
|
@@ -59,7 +60,7 @@ export const julianDayOfMs = (msParam) => `(${msParam} / ${DAY_MS}.0 + ${UNIX_EP
|
|
|
59
60
|
// json_each matches the tag as a whole element; substr, not LIKE, keeps the prefix case-sensitive
|
|
60
61
|
// like startsWith.
|
|
61
62
|
const keepPairSql = (p) => ({
|
|
62
|
-
sql: `(
|
|
63
|
+
sql: `(${notSupersededIn()} AND EXISTS (SELECT 1 FROM json_each(CASE WHEN json_valid(tags_json) THEN ` +
|
|
63
64
|
`tags_json ELSE '[]' END) WHERE value = ?) AND substr(source, 1, ${p.sourcePrefix.length}) = ?)`,
|
|
64
65
|
params: [p.tag, p.sourcePrefix],
|
|
65
66
|
});
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import type { DatabaseSyncLike, SqlResult } from '../../../db/index.js';
|
|
2
|
+
import type { ALL_TENANTS } from '../../../base/util/tenant.js';
|
|
3
|
+
declare const TRANSITIONS: {
|
|
4
|
+
readonly compactionDone: {
|
|
5
|
+
readonly table: "compactions";
|
|
6
|
+
readonly key: "id";
|
|
7
|
+
readonly tenant: true;
|
|
8
|
+
readonly from: readonly ["summarised"];
|
|
9
|
+
readonly to: readonly ["done"];
|
|
10
|
+
readonly set: readonly ["items_written"];
|
|
11
|
+
};
|
|
12
|
+
readonly goalComplete: {
|
|
13
|
+
readonly table: "goal_stack";
|
|
14
|
+
readonly key: "id";
|
|
15
|
+
readonly tenant: true;
|
|
16
|
+
readonly from: readonly ["active", "suspended"];
|
|
17
|
+
readonly to: readonly ["completed"];
|
|
18
|
+
readonly set: readonly ["completed_at", "outcome_score"];
|
|
19
|
+
};
|
|
20
|
+
readonly goalResume: {
|
|
21
|
+
readonly table: "goal_stack";
|
|
22
|
+
readonly key: "id";
|
|
23
|
+
readonly tenant: true;
|
|
24
|
+
readonly from: readonly ["suspended"];
|
|
25
|
+
readonly to: readonly ["active"];
|
|
26
|
+
readonly set: readonly [];
|
|
27
|
+
};
|
|
28
|
+
readonly conflictStale: {
|
|
29
|
+
readonly table: "memory_conflicts";
|
|
30
|
+
readonly key: "id";
|
|
31
|
+
readonly tenant: false;
|
|
32
|
+
readonly from: readonly ["open"];
|
|
33
|
+
readonly to: readonly ["resolved"];
|
|
34
|
+
readonly set: readonly ["updated_at"];
|
|
35
|
+
};
|
|
36
|
+
readonly quarantineApprove: {
|
|
37
|
+
readonly table: "memory_quarantine";
|
|
38
|
+
readonly key: "memory_id";
|
|
39
|
+
readonly tenant: true;
|
|
40
|
+
readonly from: readonly ["pending"];
|
|
41
|
+
readonly to: readonly ["approved"];
|
|
42
|
+
readonly set: readonly ["decided_at", "decided_by"];
|
|
43
|
+
};
|
|
44
|
+
readonly quarantineReject: {
|
|
45
|
+
readonly table: "memory_quarantine";
|
|
46
|
+
readonly key: "memory_id";
|
|
47
|
+
readonly tenant: true;
|
|
48
|
+
readonly from: readonly ["pending"];
|
|
49
|
+
readonly to: readonly ["rejected"];
|
|
50
|
+
readonly set: readonly ["decided_at", "decided_by"];
|
|
51
|
+
};
|
|
52
|
+
readonly snapshotClose: {
|
|
53
|
+
readonly table: "task_snapshots";
|
|
54
|
+
readonly key: "id";
|
|
55
|
+
readonly tenant: true;
|
|
56
|
+
readonly from: readonly ["active"];
|
|
57
|
+
readonly to: readonly ["cleared", "done", "session-ended"];
|
|
58
|
+
readonly set: readonly ["updated_at"];
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
type Transitions = typeof TRANSITIONS;
|
|
62
|
+
/** The name of one guarded status move. */
|
|
63
|
+
export type TransitionName = keyof Transitions;
|
|
64
|
+
type ToOf<N extends TransitionName> = Transitions[N]['to'][number];
|
|
65
|
+
type SetOf<N extends TransitionName> = Transitions[N]['set'][number];
|
|
66
|
+
type TenantPart<N extends TransitionName> = Transitions[N]['tenant'] extends true ? {
|
|
67
|
+
readonly tenantId: string;
|
|
68
|
+
} : {
|
|
69
|
+
readonly tenantId: typeof ALL_TENANTS;
|
|
70
|
+
};
|
|
71
|
+
type SetPart<N extends TransitionName> = [SetOf<N>] extends [never] ? {
|
|
72
|
+
readonly set?: undefined;
|
|
73
|
+
} : {
|
|
74
|
+
readonly set: {
|
|
75
|
+
readonly [C in SetOf<N>]: SqlResult;
|
|
76
|
+
};
|
|
77
|
+
};
|
|
78
|
+
type MoveParts<N extends TransitionName> = {
|
|
79
|
+
readonly to: ToOf<N>;
|
|
80
|
+
} & TenantPart<N> & SetPart<N>;
|
|
81
|
+
/** The rows to move, the status to move them to, and the columns the move sets with it. */
|
|
82
|
+
export type StatusMove<N extends TransitionName> = MoveParts<N> & {
|
|
83
|
+
readonly ids: readonly (string | number)[];
|
|
84
|
+
};
|
|
85
|
+
/** One row to move: `StatusMove` with a single `id`. */
|
|
86
|
+
export type OneStatusMove<N extends TransitionName> = MoveParts<N> & {
|
|
87
|
+
readonly id: string | number;
|
|
88
|
+
};
|
|
89
|
+
/** The error for a target status outside the transition's list, naming the statuses allowed. */
|
|
90
|
+
export declare function badStatusTarget(name: TransitionName, to: string): Error;
|
|
91
|
+
/** Moves the keyed rows that are in one of the transition's from-statuses to `to`, and returns how
|
|
92
|
+
* many it moved: 0 when none was in a from-status. Throws when `to` is not one of its targets. */
|
|
93
|
+
export declare function moveStatus<N extends TransitionName>(db: DatabaseSyncLike, name: N, move: StatusMove<N>): number;
|
|
94
|
+
/** `moveStatus` for one row whose write scope already read its status: a row that left its
|
|
95
|
+
* from-status since then throws, so the scope undoes its writes. */
|
|
96
|
+
export declare function moveOneStatus<N extends TransitionName>(db: DatabaseSyncLike, name: N, move: OneStatusMove<N>): void;
|
|
97
|
+
export {};
|
|
98
|
+
//# sourceMappingURL=status-transitions.d.ts.map
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { placeholders } from '../../../db/sql.js';
|
|
2
|
+
import { cachedStatement } from '../../../db/statement-cache.js';
|
|
3
|
+
import { SNAPSHOT_CLOSE_STATUSES } from '../../../base/ports/store/sessions.js';
|
|
4
|
+
// Table, key and column names reach the SQL only through this map, never from a caller.
|
|
5
|
+
const TRANSITIONS = {
|
|
6
|
+
compactionDone: {
|
|
7
|
+
table: 'compactions',
|
|
8
|
+
key: 'id',
|
|
9
|
+
tenant: true,
|
|
10
|
+
from: ['summarised'],
|
|
11
|
+
to: ['done'],
|
|
12
|
+
set: ['items_written'],
|
|
13
|
+
},
|
|
14
|
+
goalComplete: {
|
|
15
|
+
table: 'goal_stack',
|
|
16
|
+
key: 'id',
|
|
17
|
+
tenant: true,
|
|
18
|
+
from: ['active', 'suspended'],
|
|
19
|
+
to: ['completed'],
|
|
20
|
+
set: ['completed_at', 'outcome_score'],
|
|
21
|
+
},
|
|
22
|
+
goalResume: {
|
|
23
|
+
table: 'goal_stack',
|
|
24
|
+
key: 'id',
|
|
25
|
+
tenant: true,
|
|
26
|
+
from: ['suspended'],
|
|
27
|
+
to: ['active'],
|
|
28
|
+
set: [],
|
|
29
|
+
},
|
|
30
|
+
conflictStale: {
|
|
31
|
+
table: 'memory_conflicts',
|
|
32
|
+
key: 'id',
|
|
33
|
+
tenant: false,
|
|
34
|
+
from: ['open'],
|
|
35
|
+
to: ['resolved'],
|
|
36
|
+
set: ['updated_at'],
|
|
37
|
+
},
|
|
38
|
+
quarantineApprove: {
|
|
39
|
+
table: 'memory_quarantine',
|
|
40
|
+
key: 'memory_id',
|
|
41
|
+
tenant: true,
|
|
42
|
+
from: ['pending'],
|
|
43
|
+
to: ['approved'],
|
|
44
|
+
set: ['decided_at', 'decided_by'],
|
|
45
|
+
},
|
|
46
|
+
quarantineReject: {
|
|
47
|
+
table: 'memory_quarantine',
|
|
48
|
+
key: 'memory_id',
|
|
49
|
+
tenant: true,
|
|
50
|
+
from: ['pending'],
|
|
51
|
+
to: ['rejected'],
|
|
52
|
+
set: ['decided_at', 'decided_by'],
|
|
53
|
+
},
|
|
54
|
+
snapshotClose: {
|
|
55
|
+
table: 'task_snapshots',
|
|
56
|
+
key: 'id',
|
|
57
|
+
tenant: true,
|
|
58
|
+
from: ['active'],
|
|
59
|
+
to: SNAPSHOT_CLOSE_STATUSES,
|
|
60
|
+
set: ['updated_at'],
|
|
61
|
+
},
|
|
62
|
+
};
|
|
63
|
+
function updateSql(spec) {
|
|
64
|
+
const sets = ['status = ?', ...spec.set.map((column) => `${column} = ?`)].join(', ');
|
|
65
|
+
const tenant = spec.tenant ? ' AND tenant_id = ?' : '';
|
|
66
|
+
return (`UPDATE ${spec.table} SET ${sets} WHERE ${spec.key} IN (SELECT value FROM json_each(?))${tenant} ` +
|
|
67
|
+
`AND status IN (${placeholders(spec.from.length)})`);
|
|
68
|
+
}
|
|
69
|
+
/** The error for a target status outside the transition's list, naming the statuses allowed. */
|
|
70
|
+
export function badStatusTarget(name, to) {
|
|
71
|
+
const spec = TRANSITIONS[name];
|
|
72
|
+
return new Error(`invalid ${spec.table} status "${to}": use ${spec.to.join(' | ')}`);
|
|
73
|
+
}
|
|
74
|
+
function applyMove(db, name, move) {
|
|
75
|
+
const spec = TRANSITIONS[name];
|
|
76
|
+
const { to, ids, tenantId, set = {} } = move;
|
|
77
|
+
if (!spec.to.includes(to))
|
|
78
|
+
throw badStatusTarget(name, to);
|
|
79
|
+
if (ids.length === 0)
|
|
80
|
+
return 0;
|
|
81
|
+
const params = [
|
|
82
|
+
to,
|
|
83
|
+
...spec.set.map((column) => set[column]),
|
|
84
|
+
JSON.stringify(ids),
|
|
85
|
+
...(spec.tenant ? [tenantId] : []),
|
|
86
|
+
...spec.from,
|
|
87
|
+
];
|
|
88
|
+
const result = cachedStatement(db, updateSql(spec)).run(...params);
|
|
89
|
+
return Number(result.changes ?? 0);
|
|
90
|
+
}
|
|
91
|
+
/** Moves the keyed rows that are in one of the transition's from-statuses to `to`, and returns how
|
|
92
|
+
* many it moved: 0 when none was in a from-status. Throws when `to` is not one of its targets. */
|
|
93
|
+
export function moveStatus(db, name, move) {
|
|
94
|
+
return applyMove(db, name, move);
|
|
95
|
+
}
|
|
96
|
+
/** `moveStatus` for one row whose write scope already read its status: a row that left its
|
|
97
|
+
* from-status since then throws, so the scope undoes its writes. */
|
|
98
|
+
export function moveOneStatus(db, name, move) {
|
|
99
|
+
const { id, to, tenantId, set } = move;
|
|
100
|
+
if (applyMove(db, name, { ids: [id], to, tenantId, set }) === 1)
|
|
101
|
+
return;
|
|
102
|
+
const spec = TRANSITIONS[name];
|
|
103
|
+
throw new Error(`${spec.table} row ${id} left ${spec.from.join(' | ')} before its status move`);
|
|
104
|
+
}
|
|
105
|
+
//# sourceMappingURL=status-transitions.js.map
|
|
@@ -5,6 +5,7 @@ import { bound } from '../runtime/bound.js';
|
|
|
5
5
|
import { cachedStatement } from '../../../db/statement-cache.js';
|
|
6
6
|
import { generateId } from '../../../base/memory/entry.js';
|
|
7
7
|
import { handleStamp } from '../runtime/handle-clock.js';
|
|
8
|
+
import { moveOneStatus, moveStatus } from '../runtime/status-transitions.js';
|
|
8
9
|
// The goal stack's rules: its ids, its depth cap, the parent check, a new goal and policy, and
|
|
9
10
|
// the strength a completed goal passes to the memories recalled under it.
|
|
10
11
|
// The CLI prints these ids and the sequential-learning adapter reads them back as 16 hex
|
|
@@ -222,19 +223,17 @@ function completeGoal(db, tenantId, goalId, opts) {
|
|
|
222
223
|
const completedAt = handleStamp(db);
|
|
223
224
|
const score = opts.outcomeScore ?? null;
|
|
224
225
|
withWriteScope(db, 'complete_goal', () => {
|
|
225
|
-
const goalRow = cachedStatement(db, `SELECT created_at
|
|
226
|
+
const goalRow = cachedStatement(db, `SELECT created_at FROM goal_stack WHERE id = ? AND tenant_id = ?`).get(goalId, tenantId);
|
|
226
227
|
if (!goalRow)
|
|
227
228
|
return;
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
`).run(completedAt, score, goalId, tenantId);
|
|
237
|
-
if (score !== null && !opts.noPropagate) {
|
|
229
|
+
// A goal that is already completed moves no row, so a second call neither restamps nor rescales.
|
|
230
|
+
const moved = moveStatus(db, 'goalComplete', {
|
|
231
|
+
tenantId,
|
|
232
|
+
ids: [goalId],
|
|
233
|
+
to: 'completed',
|
|
234
|
+
set: { completed_at: completedAt, outcome_score: score },
|
|
235
|
+
});
|
|
236
|
+
if (moved === 1 && score !== null && !opts.noPropagate) {
|
|
238
237
|
const multiplier = goalOutcomeMultiplier(score);
|
|
239
238
|
if (multiplier !== 1) {
|
|
240
239
|
const since = goalRow.created_at;
|
|
@@ -266,7 +265,7 @@ function resumeGoal(db, tenantId, goalId) {
|
|
|
266
265
|
if (!row || row.status !== 'suspended')
|
|
267
266
|
return;
|
|
268
267
|
enforceDepthCapWithinTx(db, tenantId, row.session_id);
|
|
269
|
-
|
|
268
|
+
moveOneStatus(db, 'goalResume', { tenantId, id: goalId, to: 'active' });
|
|
270
269
|
});
|
|
271
270
|
}
|
|
272
271
|
const goalsBodies = {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type DatabaseSyncLike } from '../../../db/index.js';
|
|
2
|
-
import type
|
|
2
|
+
import { type SessionEvent, type Sessions } from '../../../base/ports/store/sessions.js';
|
|
3
3
|
import type { UntracedSession } from '../../../base/ports/store/consolidation.js';
|
|
4
4
|
import type { Handles } from '../runtime/open.js';
|
|
5
5
|
export declare function listSessionEvents(db: DatabaseSyncLike, tenantId: string, options?: {
|
|
@@ -6,6 +6,7 @@ import { raiseMinBinary } from '../../../db/meta.js';
|
|
|
6
6
|
import { assertTenantId } from '../../../base/scope/tenant-id.js';
|
|
7
7
|
import { TASK_OWNER_MIN_BINARY } from '../../../base/util/version.js';
|
|
8
8
|
import { SESSION_EVENT_COLUMNS, rowToSessionEvent } from '../runtime/rows.js';
|
|
9
|
+
import { isSnapshotCloseStatus, } from '../../../base/ports/store/sessions.js';
|
|
9
10
|
import { removeActiveTaskMirror, writeRecentSessionMirror } from './session-mirrors.js';
|
|
10
11
|
import { continuityStamp } from '../../../base/ports/store/types.js';
|
|
11
12
|
import { parseStoredObject } from '../../../base/util/stored-json.js';
|
|
@@ -17,27 +18,38 @@ import { cachedStatement } from '../../../db/statement-cache.js';
|
|
|
17
18
|
import { RECENT_MIRROR_EVENTS, TRACE_EVENT_ROWS } from '../../rules/windows.js';
|
|
18
19
|
import { SESSION_EVENT_LIMIT, WM_MAX_ENTRIES } from '../../../base/util/limits.js';
|
|
19
20
|
import { handleNow, handleStamp } from '../runtime/handle-clock.js';
|
|
21
|
+
import { badStatusTarget, moveOneStatus } from '../runtime/status-transitions.js';
|
|
22
|
+
/** `status` as a close status, or a throw before any write that names the statuses allowed. */
|
|
23
|
+
function requireSnapshotCloseStatus(status) {
|
|
24
|
+
if (isSnapshotCloseStatus(status))
|
|
25
|
+
return status;
|
|
26
|
+
throw badStatusTarget('snapshotClose', status);
|
|
27
|
+
}
|
|
20
28
|
/** Rows closed: the tenant's newest active snapshot, whoever saved it, or none. */
|
|
21
29
|
function clearActiveTaskSnapshot(db, files, tenantId, clearedStatus) {
|
|
22
30
|
const { hippoRoot } = files;
|
|
23
31
|
assertTenantId('clearActiveTaskSnapshot', tenantId);
|
|
24
32
|
assertKeyedOnSharedStore('clearActiveTaskSnapshot', files, undefined);
|
|
33
|
+
const to = requireSnapshotCloseStatus(clearedStatus);
|
|
25
34
|
const now = handleStamp(db);
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
35
|
+
// The read and the move share one write scope, so a second clear finds no active row.
|
|
36
|
+
const closed = withWriteScope(db, 'clear_snapshot', () => {
|
|
37
|
+
const active = cachedStatement(db, `SELECT id FROM task_snapshots WHERE status = 'active' AND tenant_id = ? ORDER BY updated_at DESC, id DESC ` +
|
|
38
|
+
`LIMIT 1`).get(tenantId);
|
|
39
|
+
if (!active?.id)
|
|
40
|
+
return 0;
|
|
41
|
+
moveOneStatus(db, 'snapshotClose', { id: active.id, to, tenantId, set: { updated_at: now } });
|
|
42
|
+
return 1;
|
|
43
|
+
});
|
|
33
44
|
removeActiveTaskMirror(hippoRoot, tenantId);
|
|
34
|
-
return
|
|
45
|
+
return closed;
|
|
35
46
|
}
|
|
36
47
|
/** Close the `active` task snapshot(s) owned by `sessionId` at session end; the WHERE scopes on
|
|
37
48
|
* `session_id` too so an ending session can never close a newer session's snapshot. Returns the
|
|
38
49
|
* number of rows closed. */
|
|
39
50
|
function closeTaskSnapshotsForSession(db, { tenantId, sessionId, status }, key) {
|
|
40
51
|
assertTenantId('closeTaskSnapshotsForSession', tenantId);
|
|
52
|
+
requireSnapshotCloseStatus(status);
|
|
41
53
|
if (key)
|
|
42
54
|
continuityStamp(key);
|
|
43
55
|
// a partial key is a caller bug, so fail loud rather than close nothing
|
|
@@ -9,10 +9,21 @@ import { requireInit } from './shared.js';
|
|
|
9
9
|
import { fmt } from './print.js';
|
|
10
10
|
import { printJsonList } from './json-list.js';
|
|
11
11
|
import { fail } from './exit.js';
|
|
12
|
+
import { CONFLICT_STATUSES } from '../../base/ports/store/conflicts.js';
|
|
12
13
|
const CONFLICT_PREVIEW_CHARS = 120;
|
|
14
|
+
/** `--status` as a conflict status or '*', or exit 1 with the message that lists every allowed value. */
|
|
15
|
+
function conflictStatusFilter(status) {
|
|
16
|
+
if (status === '*')
|
|
17
|
+
return status;
|
|
18
|
+
const found = CONFLICT_STATUSES.find((s) => s === status);
|
|
19
|
+
if (found === undefined) {
|
|
20
|
+
fail(`Invalid --status: "${status}". Must be one of: ${[...CONFLICT_STATUSES, '*'].join(' | ')}.`);
|
|
21
|
+
}
|
|
22
|
+
return found;
|
|
23
|
+
}
|
|
13
24
|
export async function handleConflicts({ hippoRoot, tenantId, flags, }) {
|
|
14
25
|
requireInit(hippoRoot);
|
|
15
|
-
const status = stringFlagOrExit(flags, 'status') ?? 'open';
|
|
26
|
+
const status = conflictStatusFilter(stringFlagOrExit(flags, 'status') ?? 'open');
|
|
16
27
|
const ctx = cliApiContext(hippoRoot, tenantId);
|
|
17
28
|
const read = (page) => api.conflictList(ctx, status, { everyTenant: true }, page);
|
|
18
29
|
if (boolFlag(flags, 'json')) {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// Where-you-left-off verbs that read or save the live state: snapshot, current and working memory.
|
|
2
2
|
import { CONTINUITY_EVENT_LIMIT, continuityLatest } from '../../api/continuity/continuity.js';
|
|
3
3
|
import { cliApiContext, cliStore } from './api-context.js';
|
|
4
|
+
import { SNAPSHOT_CLOSE_STATUSES, isSnapshotCloseStatus, } from '../../base/ports/store/sessions.js';
|
|
4
5
|
import { snapshotJson } from '../../api/continuity/continuity-json.js';
|
|
5
6
|
import { requireInit } from './shared.js';
|
|
6
7
|
import { printActiveTaskSnapshot } from './print.js';
|
|
@@ -34,6 +35,9 @@ async function snapshotSave(hippoRoot, tenantId, flags) {
|
|
|
34
35
|
}
|
|
35
36
|
async function snapshotClear(hippoRoot, tenantId, flags) {
|
|
36
37
|
const status = stringFlagOrExit(flags, 'status') ?? 'cleared';
|
|
38
|
+
if (!isSnapshotCloseStatus(status)) {
|
|
39
|
+
fail(`Invalid --status: "${status}". Must be one of: ${SNAPSHOT_CLOSE_STATUSES.join(' | ')}.`);
|
|
40
|
+
}
|
|
37
41
|
const cleared = await cliStore(hippoRoot).sessions.clear(tenantId, 'snapshot', { status });
|
|
38
42
|
if (cleared === 0) {
|
|
39
43
|
console.log('No active task snapshot to clear.');
|
|
@@ -4,6 +4,7 @@ import { recallJsonRow } from '../../api/recall/rows.js';
|
|
|
4
4
|
import { summaryLine } from '../../base/memory/agent-memory-report.js';
|
|
5
5
|
import { handoffSectionText, snapshotSectionText, snapshotText, sessionTrailText, handoffText, } from '../../api/context/context-render.js';
|
|
6
6
|
import { printError } from './output.js';
|
|
7
|
+
import { isSuperseded } from '../../base/memory/liveness.js';
|
|
7
8
|
export function fmt(n, digits = 2) {
|
|
8
9
|
return n.toFixed(digits);
|
|
9
10
|
}
|
|
@@ -16,7 +17,7 @@ export function recallEntryText({ r, query, showWhy, isGlobal, now, }) {
|
|
|
16
17
|
const graphMark = r.graphVia ? ` [graph: ${r.graphVia.hops}hop ${r.graphVia.relType}]` : '';
|
|
17
18
|
const lines = [
|
|
18
19
|
`--- ${e.id} [${e.layer}] ` +
|
|
19
|
-
`${confLabel}${isGlobal ? ' [global]' : ''}${e
|
|
20
|
+
`${confLabel}${isGlobal ? ' [global]' : ''}${isSuperseded(e) ? ' [superseded]' : ''}${graphMark} ` +
|
|
20
21
|
`score=${fmt(r.score, 3)} strength=${fmt(e.strength)}`,
|
|
21
22
|
` [${'█'.repeat(bars)}${'░'.repeat(10 - bars)}] tags: ${e.tags.join(', ') || 'none'} | retrieved: ` +
|
|
22
23
|
`${e.retrievalCount}x`,
|
|
@@ -180,8 +180,8 @@ export const OBJECT_VERBS = {
|
|
|
180
180
|
--id <memory-id> Invalidate exactly one memory (instead of a pattern)
|
|
181
181
|
--dry-run Preview what would be hit; writes nothing
|
|
182
182
|
Note: a pattern equal to the system tag
|
|
183
|
-
'invalidated'
|
|
184
|
-
|
|
183
|
+
'invalidated' matches every previously invalidated
|
|
184
|
+
memory; their half-life is not halved again
|
|
185
185
|
--reason "<why>" Optional: what replaced it
|
|
186
186
|
invalidate --churn FE2: tag memories 'churn-stale' whose named file
|
|
187
187
|
changed or was deleted, or whose named symbol or
|
|
@@ -4,7 +4,7 @@ import { memoryGet } from '../../api/memories/memories.js';
|
|
|
4
4
|
import { BadRequestError, ConflictError, NotFoundError } from '../../base/errors/api-errors.js';
|
|
5
5
|
import { RawAppendOnlyError } from '../../base/errors/raw-append-only.js';
|
|
6
6
|
import { ParamError, parseMemoryId } from './dashboard-params.js';
|
|
7
|
-
import { isLiveMemory } from '../../
|
|
7
|
+
import { isLiveMemory } from '../../base/scope/live-memory.js';
|
|
8
8
|
function notFound() {
|
|
9
9
|
return { status: 404, body: { error: 'Not found' }, changed: false };
|
|
10
10
|
}
|
|
@@ -20,6 +20,8 @@ function dagRebuildLine(e) {
|
|
|
20
20
|
parts.push(`${e.zeroChildSkipped} zero-child-skipped`);
|
|
21
21
|
if (e.failed > 0)
|
|
22
22
|
parts.push(`${e.failed} failed`);
|
|
23
|
+
if (e.held > 0)
|
|
24
|
+
parts.push(`${e.held} held`);
|
|
23
25
|
if (e.cappedAt !== null)
|
|
24
26
|
parts.push(`CAPPED@${e.cappedAt}`);
|
|
25
27
|
return ` 🌳 DAG rebuild: ${parts.join(', ')}`;
|