blun-king-cli 9.1.642 → 9.1.644
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/LIESMICH.txt +18 -0
- package/README.md +20 -6
- package/bin/blun.js +3 -3
- package/bin/king.js +3 -3
- package/bin/launcher-mode.js +125 -126
- package/bin/launcher-runtime.js +603 -616
- package/bin/plugin-bootstrap.js +339 -405
- package/bin/rename-private-staging.cjs +2 -2
- package/bin/retired-bundled-plugins.cjs +84 -0
- package/bin/startup-security-host.cjs +105 -0
- package/bin/startup-security.cjs +9 -105
- package/bin/startup-warning-policy.cjs +22 -0
- package/bin/update-lease-installer.cjs +125 -0
- package/bin/update-lease-sockets.cjs +228 -0
- package/bin/update-lease.js +22 -327
- package/bin/verify-bundled-agent-sources.cjs +2 -4
- package/blun.mjs +78 -193
- package/bundled-agent-sources.json +1 -552
- package/package.json +4 -6
- package/tool-liveness642/index.cjs +7 -0
- package/tool-liveness642/queue-delivery.cjs +109 -0
- package/tool-liveness642/receipt.json +40 -0
- package/tool-liveness642/shell-yield.cjs +43 -0
- package/tool-liveness642/task-wait.cjs +45 -0
- package/versionierung/BELEG.json +43 -0
- package/versionierung/LIESMICH.md +5 -0
- package/versionierung/urspruenglicher-overlay-beleg.json +39 -0
- package/worker-host.mjs +48 -128
- package/agent-spine-plugin/.claude-plugin/marketplace.json +0 -20
- package/agent-spine-plugin/.claude-plugin/plugin.json +0 -14
- package/agent-spine-plugin/.codex-plugin/plugin.json +0 -47
- package/agent-spine-plugin/.mcp.json +0 -8
- package/agent-spine-plugin/CHANGELOG.md +0 -1614
- package/agent-spine-plugin/LICENSE +0 -186
- package/agent-spine-plugin/README.md +0 -432
- package/agent-spine-plugin/assets/agentspine-banner.svg +0 -32
- package/agent-spine-plugin/bin/agentspine-mcp.js +0 -4
- package/agent-spine-plugin/bin/agentspine.js +0 -7
- package/agent-spine-plugin/blun.plugin.json +0 -68
- package/agent-spine-plugin/docs/acceptance.md +0 -61
- package/agent-spine-plugin/docs/artifact-evaluation.md +0 -93
- package/agent-spine-plugin/docs/host-integration.md +0 -193
- package/agent-spine-plugin/docs/preflight-recall.md +0 -71
- package/agent-spine-plugin/docs/preservation-contract.md +0 -53
- package/agent-spine-plugin/docs/quality-gates.md +0 -50
- package/agent-spine-plugin/docs/session-timeline.md +0 -112
- package/agent-spine-plugin/docs/source-roots.md +0 -113
- package/agent-spine-plugin/docs/world-model.md +0 -119
- package/agent-spine-plugin/hooks/codex.json +0 -47
- package/agent-spine-plugin/hooks/hooks.json +0 -106
- package/agent-spine-plugin/hooks/version.json +0 -5
- package/agent-spine-plugin/package.json +0 -77
- package/agent-spine-plugin/scripts/check-codex-install.js +0 -226
- package/agent-spine-plugin/scripts/check-hosts.js +0 -208
- package/agent-spine-plugin/scripts/check-install-hook.js +0 -227
- package/agent-spine-plugin/scripts/check-install-selfstarter.js +0 -154
- package/agent-spine-plugin/scripts/check-install.js +0 -478
- package/agent-spine-plugin/scripts/check-line-budget.js +0 -58
- package/agent-spine-plugin/scripts/check-syntax.js +0 -29
- package/agent-spine-plugin/scripts/github-actions.js +0 -11
- package/agent-spine-plugin/scripts/hermetic-process.js +0 -191
- package/agent-spine-plugin/scripts/release-check.js +0 -150
- package/agent-spine-plugin/scripts/run-acceptance.js +0 -19
- package/agent-spine-plugin/scripts/run-checks.js +0 -50
- package/agent-spine-plugin/scripts/run-tests-hermetic.js +0 -112
- package/agent-spine-plugin/skills/agent-spine/SKILL.md +0 -99
- package/agent-spine-plugin/spine-example/1-identity.md +0 -12
- package/agent-spine-plugin/spine-example/2-voice.md +0 -6
- package/agent-spine-plugin/spine-example/3-conduct.md +0 -8
- package/agent-spine-plugin/spine-example/4-history.md +0 -4
- package/agent-spine-plugin/src/cli-agent.js +0 -315
- package/agent-spine-plugin/src/cli-attention.js +0 -95
- package/agent-spine-plugin/src/cli-autonomy.js +0 -36
- package/agent-spine-plugin/src/cli-common.js +0 -71
- package/agent-spine-plugin/src/cli-continuity.js +0 -116
- package/agent-spine-plugin/src/cli-core.js +0 -128
- package/agent-spine-plugin/src/cli-diagnostics.js +0 -291
- package/agent-spine-plugin/src/cli-host.js +0 -21
- package/agent-spine-plugin/src/cli-learning.js +0 -320
- package/agent-spine-plugin/src/cli-premortem.js +0 -16
- package/agent-spine-plugin/src/cli-sharing.js +0 -230
- package/agent-spine-plugin/src/cli.js +0 -181
- package/agent-spine-plugin/src/codex-reader-launcher.js +0 -182
- package/agent-spine-plugin/src/hook.js +0 -500
- package/agent-spine-plugin/src/index.js +0 -108
- package/agent-spine-plugin/src/lib/acceptance.js +0 -435
- package/agent-spine-plugin/src/lib/action-lesson-recall.js +0 -118
- package/agent-spine-plugin/src/lib/attention-context.js +0 -167
- package/agent-spine-plugin/src/lib/attention-events.js +0 -113
- package/agent-spine-plugin/src/lib/attention-privacy.js +0 -72
- package/agent-spine-plugin/src/lib/attention-schema.js +0 -164
- package/agent-spine-plugin/src/lib/attention-storage.js +0 -93
- package/agent-spine-plugin/src/lib/attention.js +0 -164
- package/agent-spine-plugin/src/lib/audit-premortem.js +0 -223
- package/agent-spine-plugin/src/lib/audit.js +0 -401
- package/agent-spine-plugin/src/lib/authentication.js +0 -515
- package/agent-spine-plugin/src/lib/autonomy-policy.js +0 -110
- package/agent-spine-plugin/src/lib/autonomy-store.js +0 -202
- package/agent-spine-plugin/src/lib/autonomy.js +0 -8
- package/agent-spine-plugin/src/lib/briefing.js +0 -493
- package/agent-spine-plugin/src/lib/catalog-document-read.js +0 -51
- package/agent-spine-plugin/src/lib/catalog.js +0 -167
- package/agent-spine-plugin/src/lib/channel-continuity.js +0 -19
- package/agent-spine-plugin/src/lib/channel-runtime.js +0 -665
- package/agent-spine-plugin/src/lib/codex-installation.js +0 -231
- package/agent-spine-plugin/src/lib/codex-skill-installation.js +0 -211
- package/agent-spine-plugin/src/lib/context.js +0 -156
- package/agent-spine-plugin/src/lib/continuity.js +0 -338
- package/agent-spine-plugin/src/lib/coordination.js +0 -577
- package/agent-spine-plugin/src/lib/delivery-agent-usage.js +0 -231
- package/agent-spine-plugin/src/lib/delivery-assignment.js +0 -220
- package/agent-spine-plugin/src/lib/delivery-command-actions.js +0 -462
- package/agent-spine-plugin/src/lib/delivery-knowledge.js +0 -78
- package/agent-spine-plugin/src/lib/delivery-premortem-binding.js +0 -107
- package/agent-spine-plugin/src/lib/delivery-premortem-closure.js +0 -171
- package/agent-spine-plugin/src/lib/delivery-premortem-codec.js +0 -45
- package/agent-spine-plugin/src/lib/delivery-premortem-correction.js +0 -101
- package/agent-spine-plugin/src/lib/delivery-premortem-file.js +0 -21
- package/agent-spine-plugin/src/lib/delivery-premortem-index.js +0 -493
- package/agent-spine-plugin/src/lib/delivery-premortem-inspection.js +0 -37
- package/agent-spine-plugin/src/lib/delivery-premortem-recovery.js +0 -120
- package/agent-spine-plugin/src/lib/delivery-premortem-rejection.js +0 -65
- package/agent-spine-plugin/src/lib/delivery-premortem-results.js +0 -28
- package/agent-spine-plugin/src/lib/delivery-premortem-session-guard.js +0 -46
- package/agent-spine-plugin/src/lib/delivery-premortem-write-ledger.js +0 -285
- package/agent-spine-plugin/src/lib/delivery-premortem.js +0 -499
- package/agent-spine-plugin/src/lib/delivery-shell-heredoc.js +0 -115
- package/agent-spine-plugin/src/lib/delivery-shell-substitutions.js +0 -111
- package/agent-spine-plugin/src/lib/delivery-shell-wrapper.js +0 -64
- package/agent-spine-plugin/src/lib/delivery-target.js +0 -73
- package/agent-spine-plugin/src/lib/delivery-verification.js +0 -445
- package/agent-spine-plugin/src/lib/documents.js +0 -239
- package/agent-spine-plugin/src/lib/feed-transport.js +0 -499
- package/agent-spine-plugin/src/lib/filesystem-retry.js +0 -34
- package/agent-spine-plugin/src/lib/gateway-common.js +0 -68
- package/agent-spine-plugin/src/lib/gateway-control.js +0 -370
- package/agent-spine-plugin/src/lib/gateway-delivery.js +0 -103
- package/agent-spine-plugin/src/lib/gateway-execution.js +0 -350
- package/agent-spine-plugin/src/lib/gateway-group-response.js +0 -128
- package/agent-spine-plugin/src/lib/gateway-host-fencing.js +0 -92
- package/agent-spine-plugin/src/lib/gateway-host-lifecycle.js +0 -193
- package/agent-spine-plugin/src/lib/gateway-inspection.js +0 -85
- package/agent-spine-plugin/src/lib/gateway-knowledge.js +0 -129
- package/agent-spine-plugin/src/lib/gateway-policy-provenance.js +0 -197
- package/agent-spine-plugin/src/lib/gateway-premortem-disposition.js +0 -82
- package/agent-spine-plugin/src/lib/gateway-premortem.js +0 -363
- package/agent-spine-plugin/src/lib/gateway-prepared-host.js +0 -28
- package/agent-spine-plugin/src/lib/gateway-runs.js +0 -345
- package/agent-spine-plugin/src/lib/gateway-runtime-identity.js +0 -31
- package/agent-spine-plugin/src/lib/gateway-runtime-records.js +0 -21
- package/agent-spine-plugin/src/lib/gateway-runtime.js +0 -18
- package/agent-spine-plugin/src/lib/gateway-state-transaction.js +0 -356
- package/agent-spine-plugin/src/lib/gateway-state.js +0 -344
- package/agent-spine-plugin/src/lib/graph.js +0 -337
- package/agent-spine-plugin/src/lib/hook-artifact-guards.js +0 -356
- package/agent-spine-plugin/src/lib/hook-audit.js +0 -43
- package/agent-spine-plugin/src/lib/hook-briefing-use.js +0 -78
- package/agent-spine-plugin/src/lib/hook-context.js +0 -441
- package/agent-spine-plugin/src/lib/hook-final-message.js +0 -26
- package/agent-spine-plugin/src/lib/hook-input.js +0 -27
- package/agent-spine-plugin/src/lib/hook-output.js +0 -284
- package/agent-spine-plugin/src/lib/hook-premortem.js +0 -257
- package/agent-spine-plugin/src/lib/hook-process-advisory.js +0 -36
- package/agent-spine-plugin/src/lib/hook-protection.js +0 -95
- package/agent-spine-plugin/src/lib/hook-stop-verification.js +0 -84
- package/agent-spine-plugin/src/lib/hook-timeline.js +0 -102
- package/agent-spine-plugin/src/lib/host-instruction-budget.js +0 -11
- package/agent-spine-plugin/src/lib/https-transport.js +0 -392
- package/agent-spine-plugin/src/lib/identifier-analysis.js +0 -446
- package/agent-spine-plugin/src/lib/indexed-memory-offline.js +0 -40
- package/agent-spine-plugin/src/lib/indexed-memory.js +0 -298
- package/agent-spine-plugin/src/lib/knowledge-evidence.js +0 -431
- package/agent-spine-plugin/src/lib/learning-applications.js +0 -441
- package/agent-spine-plugin/src/lib/learning-artifact-evaluator.js +0 -114
- package/agent-spine-plugin/src/lib/learning-candidates.js +0 -274
- package/agent-spine-plugin/src/lib/learning-context.js +0 -137
- package/agent-spine-plugin/src/lib/learning-delivery-contracts.js +0 -310
- package/agent-spine-plugin/src/lib/learning-evaluation-contracts.js +0 -350
- package/agent-spine-plugin/src/lib/learning-evaluation-registration.js +0 -372
- package/agent-spine-plugin/src/lib/learning-evaluation-revocation.js +0 -292
- package/agent-spine-plugin/src/lib/learning-evidence-contracts.js +0 -321
- package/agent-spine-plugin/src/lib/learning-findings.js +0 -458
- package/agent-spine-plugin/src/lib/learning-measurement-contracts.js +0 -285
- package/agent-spine-plugin/src/lib/learning-measurements.js +0 -265
- package/agent-spine-plugin/src/lib/learning-outcome-contracts.js +0 -165
- package/agent-spine-plugin/src/lib/learning-outcomes.js +0 -343
- package/agent-spine-plugin/src/lib/learning-reconciliation.js +0 -290
- package/agent-spine-plugin/src/lib/learning-retry-contracts.js +0 -188
- package/agent-spine-plugin/src/lib/learning-schema.js +0 -229
- package/agent-spine-plugin/src/lib/learning-scope-targets.js +0 -424
- package/agent-spine-plugin/src/lib/learning-state-upgrade.js +0 -477
- package/agent-spine-plugin/src/lib/learning-status-configuration.js +0 -476
- package/agent-spine-plugin/src/lib/learning-storage.js +0 -203
- package/agent-spine-plugin/src/lib/learning-trial-recovery.js +0 -218
- package/agent-spine-plugin/src/lib/learning-validation-contracts.js +0 -375
- package/agent-spine-plugin/src/lib/learning-validation-renewal.js +0 -298
- package/agent-spine-plugin/src/lib/learning-validation-runtime.js +0 -234
- package/agent-spine-plugin/src/lib/learning.js +0 -36
- package/agent-spine-plugin/src/lib/lesson-recall-session.js +0 -172
- package/agent-spine-plugin/src/lib/mcp-autonomy-tools.js +0 -37
- package/agent-spine-plugin/src/lib/mcp-delivery-completion.js +0 -124
- package/agent-spine-plugin/src/lib/mcp-delivery-tools.js +0 -45
- package/agent-spine-plugin/src/lib/mcp-premortem.js +0 -68
- package/agent-spine-plugin/src/lib/mcp-runtime.js +0 -355
- package/agent-spine-plugin/src/lib/mcp-source-context.js +0 -61
- package/agent-spine-plugin/src/lib/mcp-timeline-tools.js +0 -240
- package/agent-spine-plugin/src/lib/mcp-world-tools.js +0 -52
- package/agent-spine-plugin/src/lib/object-transport.js +0 -206
- package/agent-spine-plugin/src/lib/owned-file-lock.js +0 -182
- package/agent-spine-plugin/src/lib/paths.js +0 -109
- package/agent-spine-plugin/src/lib/peer-transport.js +0 -283
- package/agent-spine-plugin/src/lib/persona-runtime.js +0 -581
- package/agent-spine-plugin/src/lib/pre-answer-timeline-recall.js +0 -104
- package/agent-spine-plugin/src/lib/preflight-delivery-id.js +0 -27
- package/agent-spine-plugin/src/lib/preflight.js +0 -688
- package/agent-spine-plugin/src/lib/project-portfolio.js +0 -176
- package/agent-spine-plugin/src/lib/runtime.js +0 -13
- package/agent-spine-plugin/src/lib/selfstarter-core.js +0 -382
- package/agent-spine-plugin/src/lib/selfstarter-jobs.js +0 -149
- package/agent-spine-plugin/src/lib/selfstarter-lease.js +0 -204
- package/agent-spine-plugin/src/lib/selfstarter-policy.js +0 -90
- package/agent-spine-plugin/src/lib/selfstarter-workspace.js +0 -111
- package/agent-spine-plugin/src/lib/selfstarter.js +0 -11
- package/agent-spine-plugin/src/lib/session-timeline-auth.js +0 -316
- package/agent-spine-plugin/src/lib/session-timeline-codex.js +0 -69
- package/agent-spine-plugin/src/lib/session-timeline-contract.js +0 -56
- package/agent-spine-plugin/src/lib/session-timeline-enrollment-source.js +0 -38
- package/agent-spine-plugin/src/lib/session-timeline-enrollment-storage.js +0 -128
- package/agent-spine-plugin/src/lib/session-timeline-enrollment-transport.js +0 -15
- package/agent-spine-plugin/src/lib/session-timeline-enrollment.js +0 -478
- package/agent-spine-plugin/src/lib/session-timeline-event-extract.js +0 -186
- package/agent-spine-plugin/src/lib/session-timeline-host-origin.js +0 -73
- package/agent-spine-plugin/src/lib/session-timeline-host-receipt.js +0 -117
- package/agent-spine-plugin/src/lib/session-timeline-invocation.js +0 -201
- package/agent-spine-plugin/src/lib/session-timeline-king.js +0 -93
- package/agent-spine-plugin/src/lib/session-timeline-prior.js +0 -57
- package/agent-spine-plugin/src/lib/session-timeline-provider.js +0 -36
- package/agent-spine-plugin/src/lib/session-timeline-query.js +0 -56
- package/agent-spine-plugin/src/lib/session-timeline-results.js +0 -56
- package/agent-spine-plugin/src/lib/session-timeline-root.js +0 -11
- package/agent-spine-plugin/src/lib/session-timeline-search.js +0 -82
- package/agent-spine-plugin/src/lib/session-timeline-sid-acl.js +0 -213
- package/agent-spine-plugin/src/lib/session-timeline-source-open.js +0 -30
- package/agent-spine-plugin/src/lib/session-timeline-source.js +0 -80
- package/agent-spine-plugin/src/lib/session-timeline-state.js +0 -45
- package/agent-spine-plugin/src/lib/session-timeline-transport.js +0 -42
- package/agent-spine-plugin/src/lib/session-timeline-windows-acl.js +0 -145
- package/agent-spine-plugin/src/lib/session-timeline.js +0 -462
- package/agent-spine-plugin/src/lib/sharing.js +0 -969
- package/agent-spine-plugin/src/lib/source-roots.js +0 -475
- package/agent-spine-plugin/src/lib/source-tree-scan.js +0 -178
- package/agent-spine-plugin/src/lib/sqlite-transport.js +0 -501
- package/agent-spine-plugin/src/lib/task-knowledge-context.js +0 -99
- package/agent-spine-plugin/src/lib/telegram-adapter.js +0 -119
- package/agent-spine-plugin/src/lib/timeline-continuation-update.js +0 -100
- package/agent-spine-plugin/src/lib/timeline-tool-guard.js +0 -225
- package/agent-spine-plugin/src/lib/timeline-user-feedback.js +0 -216
- package/agent-spine-plugin/src/lib/timeline-world-capture.js +0 -233
- package/agent-spine-plugin/src/lib/voice-runtime.js +0 -39
- package/agent-spine-plugin/src/lib/world-knowledge.js +0 -306
- package/agent-spine-plugin/src/lib/world-model.js +0 -333
- package/agent-spine-plugin/src/mcp.js +0 -456
- package/agent-spine-plugin/src/version.js +0 -1
- package/agent-spine-plugin/src/worker.js +0 -257
- package/bin/agentspine-king-goal-inbox.mjs +0 -127
- package/bin/agentspine-king-goal-intake.mjs +0 -106
- package/bin/agentspine-king-host-runner.mjs +0 -109
- package/bin/agentspine-king-snapshot-policy.cjs +0 -80
- package/bin/agentspine-king-status-policy.mjs +0 -226
- package/bin/agentspine-king-worker-host.mjs +0 -160
- package/bin/managed-plugin-selection.cjs +0 -141
- package/bin/verify-agent-behavior.cjs +0 -122
- package/bin/verify-agent-components.cjs +0 -104
|
@@ -1,167 +0,0 @@
|
|
|
1
|
-
import { buildCatalog } from "./catalog.js";
|
|
2
|
-
import { loadGraph } from "./graph.js";
|
|
3
|
-
import { EVENT_KINDS, EVENT_STATUSES, SIGNAL_KINDS, TEAM_RELATIONS, normalizeDate, normalizeInteger, validConfig } from "./attention-schema.js";
|
|
4
|
-
import { loadAttention, withAttentionLock } from "./attention-storage.js";
|
|
5
|
-
import { entityVisible, groupEntityIds, isQuiet, looserPrivacy, recentlyPresented, stricterPrivacy, visible } from "./attention-privacy.js";
|
|
6
|
-
|
|
7
|
-
export async function attentionContext({
|
|
8
|
-
root = process.cwd(), includePrivate = false, focusActive = false,
|
|
9
|
-
markPresented = false, maxItems = null, entityId = null, groupId = null,
|
|
10
|
-
projectId = null, currentTaskId = null, now = new Date(), catalog: providedCatalog = null
|
|
11
|
-
} = {}) {
|
|
12
|
-
const timestamp = normalizeDate(now, "now");
|
|
13
|
-
const current = new Date(timestamp);
|
|
14
|
-
const catalog = providedCatalog || await buildCatalog(root);
|
|
15
|
-
const { attention, attentionPath } = await loadAttention(catalog.root, catalog);
|
|
16
|
-
if (!validConfig(attention.config)) throw new Error("attention configuration is invalid; inspect or reset the external attention state");
|
|
17
|
-
const { graph } = await loadGraph(catalog.root, catalog);
|
|
18
|
-
const entities = new Map(graph.entities.map((entity) => [entity.id, entity]));
|
|
19
|
-
if (groupId !== null) {
|
|
20
|
-
const group = entities.get(groupId);
|
|
21
|
-
if (!group || group.kind !== "group") throw new Error(`unknown group entity: ${groupId}`);
|
|
22
|
-
}
|
|
23
|
-
const groupEntities = groupEntityIds(graph, groupId, includePrivate);
|
|
24
|
-
let suppressed = null;
|
|
25
|
-
if (!attention.config.enabled) suppressed = "disabled";
|
|
26
|
-
else if (isQuiet(current, attention.config.quietHours)) suppressed = "quiet-hours";
|
|
27
|
-
else if (focusActive) suppressed = "focus-active";
|
|
28
|
-
|
|
29
|
-
const candidates = [];
|
|
30
|
-
if (!suppressed) {
|
|
31
|
-
for (const signal of attention.signals) {
|
|
32
|
-
if (signal.status !== "open" || !visible(signal, entities, includePrivate, groupId, groupEntities)) continue;
|
|
33
|
-
if (!SIGNAL_KINDS.has(signal.kind) || !Number.isFinite(signal.priority) || !Number.isFinite(signal.confidence)) continue;
|
|
34
|
-
if (signal.dueAt && new Date(signal.dueAt) > current) continue;
|
|
35
|
-
if (signal.dueAt && !Number.isFinite(new Date(signal.dueAt).getTime())) continue;
|
|
36
|
-
const key = `cue:${signal.id}`;
|
|
37
|
-
if (recentlyPresented(attention, key, current)) continue;
|
|
38
|
-
const weights = { "unanswered-question": 30, promise: 25, "meaningful-change": 15, "check-in": 5 };
|
|
39
|
-
candidates.push({
|
|
40
|
-
key,
|
|
41
|
-
source: "signal",
|
|
42
|
-
score: signal.priority + weights[signal.kind],
|
|
43
|
-
kind: signal.kind,
|
|
44
|
-
summary: signal.summary,
|
|
45
|
-
entityId: signal.entityId,
|
|
46
|
-
dueAt: signal.dueAt,
|
|
47
|
-
privacy: signal.privacy,
|
|
48
|
-
groupId: signal.groupId || null,
|
|
49
|
-
confidence: signal.confidence,
|
|
50
|
-
authority: "context-only"
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
const teamEdges = graph.entityEdges
|
|
55
|
-
.filter((edge) => TEAM_RELATIONS.has(edge.relation))
|
|
56
|
-
.filter((edge) => includePrivate || edge.privacy !== "private")
|
|
57
|
-
.filter((edge) => edge.privacy !== "group" || (
|
|
58
|
-
groupId && [edge.from, edge.to].every((id) => groupEntities.has(id))
|
|
59
|
-
))
|
|
60
|
-
.filter((edge) => [edge.from, edge.to].every((id) => {
|
|
61
|
-
return entityVisible(entities.get(id), includePrivate, groupEntities);
|
|
62
|
-
}));
|
|
63
|
-
const teamIds = new Set(teamEdges.flatMap((edge) => [edge.from, edge.to]));
|
|
64
|
-
for (const entity of graph.entities) {
|
|
65
|
-
if (!teamIds.has(entity.id) || !["person", "agent"].includes(entity.kind)) continue;
|
|
66
|
-
if (!visible({ entityId: entity.id, privacy: entity.privacy, groupId }, entities, includePrivate, groupId, groupEntities)) continue;
|
|
67
|
-
const latestActivity = attention.activities
|
|
68
|
-
.filter((activity) => activity.entityId === entity.id && visible(activity, entities, includePrivate, groupId, groupEntities))
|
|
69
|
-
.sort((a, b) => b.at.localeCompare(a.at))[0];
|
|
70
|
-
const baseline = new Date(latestActivity?.at || entity.updatedAt);
|
|
71
|
-
const silenceDays = (current.getTime() - baseline.getTime()) / 86400000;
|
|
72
|
-
if (silenceDays < attention.config.entitySilenceDays) continue;
|
|
73
|
-
const key = `neglected:${entity.id}`;
|
|
74
|
-
if (recentlyPresented(attention, key, current)) continue;
|
|
75
|
-
const edgePrivacy = teamEdges
|
|
76
|
-
.filter((edge) => edge.from === entity.id || edge.to === entity.id)
|
|
77
|
-
.map((edge) => [edge.from, edge.to].reduce(
|
|
78
|
-
(scope, id) => stricterPrivacy(scope, entities.get(id)?.privacy || "private"),
|
|
79
|
-
edge.privacy
|
|
80
|
-
))
|
|
81
|
-
.reduce((scope, privacy) => scope === null ? privacy : looserPrivacy(scope, privacy), null);
|
|
82
|
-
const privacy = stricterPrivacy(entity.privacy, edgePrivacy || "private");
|
|
83
|
-
candidates.push({
|
|
84
|
-
key,
|
|
85
|
-
source: "relationship",
|
|
86
|
-
score: 40 + Math.min(30, Math.floor(silenceDays - attention.config.entitySilenceDays)),
|
|
87
|
-
kind: "check-in",
|
|
88
|
-
summary: `No recorded interaction with ${entity.displayName || entity.id} for ${Math.floor(silenceDays)} days.`,
|
|
89
|
-
entityId: entity.id,
|
|
90
|
-
dueAt: null,
|
|
91
|
-
privacy,
|
|
92
|
-
groupId: privacy === "group" ? groupId : null,
|
|
93
|
-
confidence: entity.confidence,
|
|
94
|
-
authority: "context-only"
|
|
95
|
-
});
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
// Focus suppresses unrelated reminders but not a blocker or due promise for
|
|
100
|
-
// the exact task already in focus. Quiet hours and the global switch still
|
|
101
|
-
// suppress every presentation while retaining durable state.
|
|
102
|
-
if (attention.config.enabled && suppressed !== "quiet-hours") {
|
|
103
|
-
for (const event of attention.events) {
|
|
104
|
-
if (!EVENT_KINDS.has(event.kind) || !EVENT_STATUSES[event.kind]?.has(event.status)) continue;
|
|
105
|
-
if (!visible(event, entities, includePrivate, groupId, groupEntities)) continue;
|
|
106
|
-
if (event.entityId !== null && event.entityId !== entityId) continue;
|
|
107
|
-
if (event.projectId !== projectId || event.taskId !== currentTaskId) continue;
|
|
108
|
-
if (event.kind === "heartbeat" && event.status !== "active") continue;
|
|
109
|
-
if (event.kind === "promise" && event.status !== "open") continue;
|
|
110
|
-
if (event.kind === "blocker" && event.status !== "open") continue;
|
|
111
|
-
if (event.dueAt && new Date(event.dueAt) > current) continue;
|
|
112
|
-
if (event.dueAt && !Number.isFinite(new Date(event.dueAt).getTime())) continue;
|
|
113
|
-
if (event.kind === "heartbeat" && !event.dueAt) {
|
|
114
|
-
const staleAt = new Date(event.updatedAt).getTime() + attention.config.heartbeatStaleMinutes * 60000;
|
|
115
|
-
if (staleAt > current.getTime()) continue;
|
|
116
|
-
}
|
|
117
|
-
const key = `event:${event.id}`;
|
|
118
|
-
if (recentlyPresented(attention, key, current)) continue;
|
|
119
|
-
const weights = { blocker: 200, promise: 150, heartbeat: 80 };
|
|
120
|
-
candidates.push({
|
|
121
|
-
key, source: "lifecycle-event", score: weights[event.kind],
|
|
122
|
-
kind: event.kind, summary: event.summary, status: event.status,
|
|
123
|
-
entityId: event.entityId, projectId: event.projectId, taskId: event.taskId,
|
|
124
|
-
dueAt: event.dueAt, privacy: event.privacy, groupId: event.groupId,
|
|
125
|
-
occurrenceCount: event.occurrenceCount,
|
|
126
|
-
provenance: event.provenance,
|
|
127
|
-
authority: "context-only"
|
|
128
|
-
});
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
if (focusActive && candidates.some((item) => item.source === "lifecycle-event")) {
|
|
132
|
-
suppressed = "focus-active-except-current-task";
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
const limit = maxItems === null
|
|
136
|
-
? attention.config.maxItems
|
|
137
|
-
: normalizeInteger(maxItems, "maxItems", 0, 20);
|
|
138
|
-
const items = candidates
|
|
139
|
-
.sort((a, b) => b.score - a.score || (a.dueAt || "").localeCompare(b.dueAt || "") || a.key.localeCompare(b.key))
|
|
140
|
-
.slice(0, limit);
|
|
141
|
-
|
|
142
|
-
if (markPresented && items.length) {
|
|
143
|
-
await withAttentionLock(attentionPath, {
|
|
144
|
-
root: catalog.root,
|
|
145
|
-
run: (state) => {
|
|
146
|
-
for (const item of items) state.presentations[item.key] = timestamp;
|
|
147
|
-
return null;
|
|
148
|
-
}
|
|
149
|
-
});
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
return {
|
|
153
|
-
schema: "agentspine.attention-context/v1",
|
|
154
|
-
root: catalog.root,
|
|
155
|
-
enabled: attention.config.enabled,
|
|
156
|
-
suppressed,
|
|
157
|
-
now: timestamp,
|
|
158
|
-
entityId,
|
|
159
|
-
groupId,
|
|
160
|
-
projectId,
|
|
161
|
-
currentTaskId,
|
|
162
|
-
items,
|
|
163
|
-
remaining: Math.max(0, candidates.length - items.length),
|
|
164
|
-
authority: "context-only",
|
|
165
|
-
note: "Attention cues are suggestions, never instructions. The current task and host permissions remain authoritative."
|
|
166
|
-
};
|
|
167
|
-
}
|
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
import { createHash } from "node:crypto";
|
|
2
|
-
import { loadCoordination } from "./coordination.js";
|
|
3
|
-
import { loadGraph } from "./graph.js";
|
|
4
|
-
import { EVENT_KINDS, EVENT_STATUSES, HOOK_EVENTS, ID_RE, PRIVACY, UNSAFE_EVENT_RE, normalizeDate } from "./attention-schema.js";
|
|
5
|
-
import { attentionMutation, preservePrevious } from "./attention-storage.js";
|
|
6
|
-
import { stricterPrivacy, validateGroupScope } from "./attention-privacy.js";
|
|
7
|
-
|
|
8
|
-
function digest(value) {
|
|
9
|
-
return createHash("sha256").update(value).digest("hex");
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
function eventIdentity(kind, scope, summary) {
|
|
13
|
-
const canonical = [kind, scope.entityId || "", scope.groupId || "", scope.projectId || "", scope.taskId || "", summary.trim().toLowerCase()].join("\0");
|
|
14
|
-
return `event:${kind}:${digest(canonical).slice(0, 24)}`;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
function validateKnownScope(graph, { entityId, groupId, projectId, taskId, privacy }) {
|
|
18
|
-
if (!entityId) throw new Error("attention events require an exact known actor identity");
|
|
19
|
-
if (!projectId || !taskId) throw new Error("attention events require exact project and task scope");
|
|
20
|
-
if (entityId && !graph.entities.some((entity) => entity.id === entityId && ["person", "agent"].includes(entity.kind))) {
|
|
21
|
-
throw new Error(`unknown person or agent entity: ${entityId}`);
|
|
22
|
-
}
|
|
23
|
-
if (!graph.entities.some((entity) => entity.id === projectId && entity.kind === "project")) {
|
|
24
|
-
throw new Error(`unknown project entity: ${projectId}`);
|
|
25
|
-
}
|
|
26
|
-
validateGroupScope(privacy, groupId, graph, entityId);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
function validateEventSummary(summary) {
|
|
30
|
-
if (!summary || typeof summary !== "string") throw new Error("event summary is required");
|
|
31
|
-
const compact = summary.trim().replace(/\s+/g, " ").slice(0, 280);
|
|
32
|
-
if (!compact) throw new Error("event summary is required");
|
|
33
|
-
if (UNSAFE_EVENT_RE.test(compact)) throw new Error("secret, identity, authority, or operational-rights content was rejected");
|
|
34
|
-
return compact;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
/** Record or transition a minimal provider-neutral lifecycle event. */
|
|
38
|
-
export async function recordAttentionEvent({
|
|
39
|
-
root = process.cwd(), id = null, kind, summary, status = null,
|
|
40
|
-
entityId = null, groupId = null, projectId = null, taskId = null,
|
|
41
|
-
privacy = "private", dueAt = null, receiptId, host, hookEvent,
|
|
42
|
-
observedAt = new Date(), catalog: providedCatalog = null
|
|
43
|
-
}) {
|
|
44
|
-
if (!EVENT_KINDS.has(kind)) throw new Error(`unsupported attention event kind: ${kind}`);
|
|
45
|
-
if (!PRIVACY.has(privacy)) throw new Error(`unsupported privacy scope: ${privacy}`);
|
|
46
|
-
if (!ID_RE.test(receiptId || "")) throw new Error("receiptId is required for idempotent lifecycle recording");
|
|
47
|
-
if (!new Set(["claude", "codex", "generic"]).has(host)) throw new Error("event host is invalid");
|
|
48
|
-
if (!HOOK_EVENTS.has(hookEvent)) throw new Error("event provenance must name a supported lifecycle hook");
|
|
49
|
-
for (const [field, value] of Object.entries({ entityId, groupId, projectId, taskId })) {
|
|
50
|
-
if (value !== null && !ID_RE.test(value)) throw new Error(`${field} is invalid`);
|
|
51
|
-
}
|
|
52
|
-
const at = normalizeDate(observedAt, "observedAt");
|
|
53
|
-
const normalizedDueAt = normalizeDate(dueAt, "dueAt", true);
|
|
54
|
-
const normalizedSummary = validateEventSummary(summary);
|
|
55
|
-
const nextStatus = status || (kind === "heartbeat" ? "active" : "open");
|
|
56
|
-
if (!EVENT_STATUSES[kind].has(nextStatus)) throw new Error(`unsupported ${kind} status: ${nextStatus}`);
|
|
57
|
-
const scope = { entityId, groupId, projectId, taskId };
|
|
58
|
-
const eventId = id || eventIdentity(kind, scope, normalizedSummary);
|
|
59
|
-
if (!ID_RE.test(eventId)) throw new Error("event id must be stable and whitespace-free");
|
|
60
|
-
const provenanceDigest = digest(JSON.stringify({ kind, summary: normalizedSummary, status: nextStatus, ...scope }));
|
|
61
|
-
return attentionMutation(root, async (state, catalog, attentionPath) => {
|
|
62
|
-
const duplicate = state.receipts.find((receipt) => receipt.id === receiptId);
|
|
63
|
-
if (duplicate) {
|
|
64
|
-
if (duplicate.eventId !== eventId || duplicate.kind !== kind || duplicate.digest !== provenanceDigest) {
|
|
65
|
-
throw new Error("attention receipt collision detected");
|
|
66
|
-
}
|
|
67
|
-
const event = state.events.find((item) => item.id === duplicate.eventId) || null;
|
|
68
|
-
return { event, duplicate: true, receipt: duplicate, attentionPath };
|
|
69
|
-
}
|
|
70
|
-
const { graph } = await loadGraph(catalog.root, catalog);
|
|
71
|
-
validateKnownScope(graph, { ...scope, privacy });
|
|
72
|
-
const { coordination } = await loadCoordination(catalog.root, catalog);
|
|
73
|
-
const task = coordination.tasks.find((item) => item.id === taskId);
|
|
74
|
-
if (!task || task.projectId !== projectId) throw new Error("attention event task must exist in the exact project scope");
|
|
75
|
-
if (![task.createdBy, task.assigneeId].includes(entityId)) {
|
|
76
|
-
throw new Error("attention event actor must be the task creator or assignee");
|
|
77
|
-
}
|
|
78
|
-
if (task.groupId !== groupId && (task.groupId !== null || groupId !== null)) {
|
|
79
|
-
throw new Error("attention event group scope must match the task");
|
|
80
|
-
}
|
|
81
|
-
if (stricterPrivacy(privacy, task.privacy) !== privacy) {
|
|
82
|
-
throw new Error("attention event privacy cannot be broader than the task");
|
|
83
|
-
}
|
|
84
|
-
const previous = state.events.find((item) => item.id === eventId);
|
|
85
|
-
if (previous && (previous.kind !== kind || previous.entityId !== entityId || previous.groupId !== groupId
|
|
86
|
-
|| previous.projectId !== projectId || previous.taskId !== taskId || previous.privacy !== privacy)) {
|
|
87
|
-
throw new Error("stable attention event identity cannot change kind, scope, or privacy");
|
|
88
|
-
}
|
|
89
|
-
preservePrevious(state, "attention-event", previous, at);
|
|
90
|
-
const provenance = {
|
|
91
|
-
source: "native-lifecycle-hook", host, hookEvent, receiptId,
|
|
92
|
-
observedAt: at,
|
|
93
|
-
digest: provenanceDigest
|
|
94
|
-
};
|
|
95
|
-
const event = {
|
|
96
|
-
id: eventId, kind, summary: normalizedSummary, status: nextStatus,
|
|
97
|
-
entityId, groupId, projectId, taskId, privacy,
|
|
98
|
-
dueAt: normalizedDueAt,
|
|
99
|
-
createdAt: previous?.createdAt || at,
|
|
100
|
-
updatedAt: at,
|
|
101
|
-
occurrenceCount: (previous?.occurrenceCount || 0) + 1,
|
|
102
|
-
provenance,
|
|
103
|
-
authority: "context-only"
|
|
104
|
-
};
|
|
105
|
-
state.events = state.events.filter((item) => item.id !== eventId);
|
|
106
|
-
state.events.push(event);
|
|
107
|
-
state.events.sort((left, right) => left.id.localeCompare(right.id));
|
|
108
|
-
const receipt = { id: receiptId, eventId, kind, digest: provenanceDigest, at, authority: "context-only" };
|
|
109
|
-
state.receipts.push(receipt);
|
|
110
|
-
state.receipts.sort((left, right) => left.at.localeCompare(right.at) || left.id.localeCompare(right.id));
|
|
111
|
-
return { event, duplicate: false, receipt, attentionPath };
|
|
112
|
-
}, providedCatalog);
|
|
113
|
-
}
|
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
export function isGroupMember(graph, groupId, entityId) {
|
|
2
|
-
if (!entityId || entityId === groupId) return true;
|
|
3
|
-
return graph.entityEdges.some((edge) => edge.relation === "member-of" && edge.privacy !== "private" && (
|
|
4
|
-
(edge.from === entityId && edge.to === groupId) || (edge.to === entityId && edge.from === groupId)
|
|
5
|
-
));
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export function validateGroupScope(privacy, groupId, graph, entityId = null) {
|
|
9
|
-
if (privacy === "group") {
|
|
10
|
-
if (!groupId) throw new Error("group privacy requires groupId");
|
|
11
|
-
const group = graph.entities.find((entity) => entity.id === groupId);
|
|
12
|
-
if (!group || group.kind !== "group") throw new Error(`unknown group entity: ${groupId}`);
|
|
13
|
-
if (!isGroupMember(graph, groupId, entityId)) throw new Error(`entity is not a visible member of group: ${groupId}`);
|
|
14
|
-
} else if (groupId !== null && groupId !== undefined) {
|
|
15
|
-
throw new Error("groupId is only valid with group privacy");
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export function isQuiet(now, quietHours) {
|
|
20
|
-
if (!quietHours) return false;
|
|
21
|
-
const shifted = new Date(now.getTime() + quietHours.utcOffsetMinutes * 60000);
|
|
22
|
-
const hour = shifted.getUTCHours();
|
|
23
|
-
if (quietHours.start === quietHours.end) return true;
|
|
24
|
-
if (quietHours.start < quietHours.end) return hour >= quietHours.start && hour < quietHours.end;
|
|
25
|
-
return hour >= quietHours.start || hour < quietHours.end;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export function recentlyPresented(state, key, now) {
|
|
29
|
-
const value = state.presentations[key];
|
|
30
|
-
if (!value) return false;
|
|
31
|
-
return now.getTime() - new Date(value).getTime() < state.config.minIntervalHours * 3600000;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export function groupEntityIds(graph, groupId, includePrivate) {
|
|
35
|
-
const ids = new Set();
|
|
36
|
-
if (!groupId) return ids;
|
|
37
|
-
ids.add(groupId);
|
|
38
|
-
for (const edge of graph.entityEdges) {
|
|
39
|
-
if (edge.relation !== "member-of" || (!includePrivate && edge.privacy === "private")) continue;
|
|
40
|
-
if (edge.to === groupId) ids.add(edge.from);
|
|
41
|
-
if (edge.from === groupId) ids.add(edge.to);
|
|
42
|
-
}
|
|
43
|
-
return ids;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
export function entityVisible(entity, includePrivate, groupEntities) {
|
|
47
|
-
if (!entity) return true;
|
|
48
|
-
if (entity.privacy === "group") return groupEntities.has(entity.id);
|
|
49
|
-
if (entity.privacy === "private") return includePrivate;
|
|
50
|
-
return true;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
export function visible(record, entities, includePrivate, groupId, groupEntities) {
|
|
54
|
-
if (!includePrivate && record.privacy === "private") return false;
|
|
55
|
-
if (record.privacy === "group" && (!groupId || record.groupId !== groupId)) return false;
|
|
56
|
-
if (record.privacy === "group" && record.entityId && !groupEntities.has(record.entityId)) return false;
|
|
57
|
-
if (record.entityId) {
|
|
58
|
-
const entity = entities.get(record.entityId);
|
|
59
|
-
if (!entityVisible(entity, includePrivate, groupEntities)) return false;
|
|
60
|
-
}
|
|
61
|
-
return true;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
export function stricterPrivacy(left, right) {
|
|
65
|
-
const rank = { shared: 0, group: 1, private: 2 };
|
|
66
|
-
return rank[left] >= rank[right] ? left : right;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
export function looserPrivacy(left, right) {
|
|
70
|
-
const rank = { shared: 0, group: 1, private: 2 };
|
|
71
|
-
return rank[left] <= rank[right] ? left : right;
|
|
72
|
-
}
|
|
@@ -1,164 +0,0 @@
|
|
|
1
|
-
export const SIGNAL_KINDS = new Set(["unanswered-question", "promise", "check-in", "meaningful-change"]);
|
|
2
|
-
export const ACTIVITY_KINDS = new Set(["message", "interaction", "task", "check-in"]);
|
|
3
|
-
export const EVENT_KINDS = new Set(["heartbeat", "promise", "blocker"]);
|
|
4
|
-
export const PRIVACY = new Set(["private", "shared", "group"]);
|
|
5
|
-
export const STATUSES = new Set(["open", "completed", "dismissed"]);
|
|
6
|
-
export const EVENT_STATUSES = {
|
|
7
|
-
heartbeat: new Set(["active", "stopped"]),
|
|
8
|
-
promise: new Set(["open", "completed", "dismissed"]),
|
|
9
|
-
blocker: new Set(["open", "resolved", "dismissed"])
|
|
10
|
-
};
|
|
11
|
-
export const HOOK_EVENTS = new Set(["UserPromptSubmit", "PostToolUse", "Stop", "SubagentStop"]);
|
|
12
|
-
export const TEAM_RELATIONS = new Set(["works-with", "member-of", "reports-to", "responsible-for"]);
|
|
13
|
-
export const ID_RE = /^[A-Za-z0-9][A-Za-z0-9:_.@/-]{0,127}$/;
|
|
14
|
-
export const MAX_STATE_BYTES = 5 * 1024 * 1024;
|
|
15
|
-
export const UNSAFE_EVENT_RE = /-----BEGIN [A-Z ]*PRIVATE KEY-----|\b(?:sk|gh[opusu])_[A-Za-z0-9_-]{20,}\b|\bBearer\s+[A-Za-z0-9._~+/-]{20,}|\b(?:api[-_ ]?key|token|password|secret|passwort|geheimnis)\s*[:=]\s*\S{8,}|\b(?:permission|permissions|rights?|roles?|delegat|authorized|authorization|berechtigt|rechte|rolle|freigabe|approval|approve|admin|deploy|production|produktion|billing|payment|zahlung|spending|network access|netzwerkzugriff|database access|datenbankzugriff|tool access|dateizugriff|file access|same person|same identity|alias of|merge identit|identit(?:y|ät)|private group|private gruppe|private chat|privater chat|permisos?|derechos?|autorizad[oa]|delegación|aprobación|producción|pagos?|acceso (?:a la )?red|acceso (?:a la )?base de datos|misma persona|misma identidad|grupo privado|chat privado|rättigheter|behörighet|delegering|godkännande|produktion|betalning|nätverksåtkomst|databasåtkomst|samma person|samma identitet|privat grupp|privat chatt)\b/i;
|
|
16
|
-
|
|
17
|
-
export function defaultConfig() {
|
|
18
|
-
return {
|
|
19
|
-
enabled: true,
|
|
20
|
-
minIntervalHours: 24,
|
|
21
|
-
entitySilenceDays: 14,
|
|
22
|
-
heartbeatStaleMinutes: 30,
|
|
23
|
-
maxItems: 3,
|
|
24
|
-
quietHours: null
|
|
25
|
-
};
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export function emptyAttention(root) {
|
|
29
|
-
return {
|
|
30
|
-
schema: "agentspine.attention/v2",
|
|
31
|
-
root,
|
|
32
|
-
config: defaultConfig(),
|
|
33
|
-
signals: [],
|
|
34
|
-
activities: [],
|
|
35
|
-
events: [],
|
|
36
|
-
receipts: [],
|
|
37
|
-
history: [],
|
|
38
|
-
presentations: {}
|
|
39
|
-
};
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
export function normalizeAttention(value, root) {
|
|
43
|
-
const state = value && typeof value === "object" ? value : emptyAttention(root);
|
|
44
|
-
const originalSchema = state.schema;
|
|
45
|
-
if (!["agentspine.attention/v1", "agentspine.attention/v2"].includes(state.schema) || state.root !== root) {
|
|
46
|
-
throw new Error("attention state structure is invalid; automatic attention is disabled until repaired");
|
|
47
|
-
}
|
|
48
|
-
state.schema = "agentspine.attention/v2";
|
|
49
|
-
state.config = { ...defaultConfig(), ...(state.config && typeof state.config === "object" ? state.config : {}) };
|
|
50
|
-
for (const key of ["signals", "activities", "history"]) {
|
|
51
|
-
if (!Array.isArray(state[key])) throw new Error("attention state structure is invalid; automatic attention is disabled until repaired");
|
|
52
|
-
}
|
|
53
|
-
for (const key of ["events", "receipts"]) {
|
|
54
|
-
if (state[key] === undefined && originalSchema === "agentspine.attention/v1") state[key] = [];
|
|
55
|
-
if (!Array.isArray(state[key])) throw new Error("attention state structure is invalid; automatic attention is disabled until repaired");
|
|
56
|
-
}
|
|
57
|
-
if (!state.presentations || Array.isArray(state.presentations) || typeof state.presentations !== "object") {
|
|
58
|
-
throw new Error("attention state structure is invalid; automatic attention is disabled until repaired");
|
|
59
|
-
}
|
|
60
|
-
if (state.events.some((event) => !validEventRecord(event)) || state.receipts.some((receipt) => !validReceipt(receipt))) {
|
|
61
|
-
throw new Error("attention lifecycle state is invalid; automatic attention is disabled until repaired");
|
|
62
|
-
}
|
|
63
|
-
return state;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
export function validEventRecord(event) {
|
|
67
|
-
return event && ID_RE.test(event.id || "") && EVENT_KINDS.has(event.kind)
|
|
68
|
-
&& EVENT_STATUSES[event.kind]?.has(event.status) && PRIVACY.has(event.privacy)
|
|
69
|
-
&& (event.entityId === null || ID_RE.test(event.entityId))
|
|
70
|
-
&& (event.groupId === null || ID_RE.test(event.groupId))
|
|
71
|
-
&& ID_RE.test(event.projectId || "") && ID_RE.test(event.taskId || "")
|
|
72
|
-
&& typeof event.summary === "string" && event.summary.length > 0 && event.summary.length <= 280
|
|
73
|
-
&& Number.isInteger(event.occurrenceCount) && event.occurrenceCount >= 1
|
|
74
|
-
&& event.authority === "context-only"
|
|
75
|
-
&& Number.isFinite(new Date(event.createdAt).getTime())
|
|
76
|
-
&& Number.isFinite(new Date(event.updatedAt).getTime())
|
|
77
|
-
&& (event.dueAt === null || Number.isFinite(new Date(event.dueAt).getTime()))
|
|
78
|
-
&& !UNSAFE_EVENT_RE.test(event.summary)
|
|
79
|
-
&& event.provenance?.source === "native-lifecycle-hook"
|
|
80
|
-
&& ID_RE.test(event.provenance?.receiptId || "")
|
|
81
|
-
&& HOOK_EVENTS.has(event.provenance?.hookEvent)
|
|
82
|
-
&& new Set(["claude", "codex", "generic"]).has(event.provenance?.host)
|
|
83
|
-
&& /^[a-f0-9]{64}$/.test(event.provenance?.digest || "");
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
export function validReceipt(receipt) {
|
|
87
|
-
return receipt && ID_RE.test(receipt.id || "") && ID_RE.test(receipt.eventId || "")
|
|
88
|
-
&& EVENT_KINDS.has(receipt.kind) && receipt.authority === "context-only"
|
|
89
|
-
&& /^[a-f0-9]{64}$/.test(receipt.digest || "")
|
|
90
|
-
&& Number.isFinite(new Date(receipt.at).getTime());
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
export function normalizeDate(value, field, nullable = false) {
|
|
94
|
-
if ((value === null || value === undefined || value === "") && nullable) return null;
|
|
95
|
-
const date = value instanceof Date ? value : new Date(value);
|
|
96
|
-
if (!Number.isFinite(date.getTime())) throw new Error(`${field} must be a valid date`);
|
|
97
|
-
return date.toISOString();
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
export function normalizeNumber(value, field, minimum, maximum) {
|
|
101
|
-
const number = Number(value);
|
|
102
|
-
if (!Number.isFinite(number) || number < minimum || number > maximum) {
|
|
103
|
-
throw new Error(`${field} must be between ${minimum} and ${maximum}`);
|
|
104
|
-
}
|
|
105
|
-
return number;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
export function normalizeInteger(value, field, minimum, maximum) {
|
|
109
|
-
const number = normalizeNumber(value, field, minimum, maximum);
|
|
110
|
-
if (!Number.isInteger(number)) throw new Error(`${field} must be an integer`);
|
|
111
|
-
return number;
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
export function validConfig(config) {
|
|
115
|
-
const quiet = config.quietHours;
|
|
116
|
-
const quietValid = quiet === null || (
|
|
117
|
-
quiet && typeof quiet === "object"
|
|
118
|
-
&& Number.isInteger(quiet.start) && quiet.start >= 0 && quiet.start <= 23
|
|
119
|
-
&& Number.isInteger(quiet.end) && quiet.end >= 0 && quiet.end <= 23
|
|
120
|
-
&& Number.isFinite(quiet.utcOffsetMinutes) && quiet.utcOffsetMinutes >= -720 && quiet.utcOffsetMinutes <= 840
|
|
121
|
-
);
|
|
122
|
-
return typeof config.enabled === "boolean"
|
|
123
|
-
&& Number.isFinite(config.minIntervalHours) && config.minIntervalHours >= 1 && config.minIntervalHours <= 720
|
|
124
|
-
&& Number.isFinite(config.entitySilenceDays) && config.entitySilenceDays >= 1 && config.entitySilenceDays <= 3650
|
|
125
|
-
&& Number.isInteger(config.heartbeatStaleMinutes) && config.heartbeatStaleMinutes >= 1 && config.heartbeatStaleMinutes <= 10080
|
|
126
|
-
&& Number.isInteger(config.maxItems) && config.maxItems >= 1 && config.maxItems <= 20
|
|
127
|
-
&& quietValid;
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
export function normalizeRelativePath(value, field) {
|
|
131
|
-
if (value === null || value === undefined || value === "") return null;
|
|
132
|
-
if (typeof value !== "string") throw new Error(`${field} must be a project-relative path`);
|
|
133
|
-
const normalized = value.replaceAll("\\", "/").replace(/^\.\//, "");
|
|
134
|
-
if (normalized.startsWith("/") || normalized === ".." || normalized.startsWith("../") || normalized.includes("/../")) {
|
|
135
|
-
throw new Error(`${field} must be a project-relative path`);
|
|
136
|
-
}
|
|
137
|
-
return normalized;
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
export function attentionFindings(attention) {
|
|
141
|
-
const findings = [];
|
|
142
|
-
if (!attention || attention.schema !== "agentspine.attention/v2") findings.push("invalid-schema");
|
|
143
|
-
if (!validConfig(attention?.config || {})) findings.push("invalid-config");
|
|
144
|
-
const ids = new Set();
|
|
145
|
-
for (const event of attention?.events || []) {
|
|
146
|
-
if (!validEventRecord(event)) findings.push(`invalid-event:${event?.id || "unknown"}`);
|
|
147
|
-
if (ids.has(event.id)) findings.push(`duplicate-event:${event.id}`);
|
|
148
|
-
ids.add(event.id);
|
|
149
|
-
}
|
|
150
|
-
const receiptIds = new Set();
|
|
151
|
-
for (const receipt of attention?.receipts || []) {
|
|
152
|
-
if (!validReceipt(receipt)) findings.push(`invalid-receipt:${receipt?.id || "unknown"}`);
|
|
153
|
-
if (receiptIds.has(receipt.id)) findings.push(`duplicate-receipt:${receipt.id}`);
|
|
154
|
-
if (!ids.has(receipt.eventId)) findings.push(`orphan-receipt:${receipt.id}`);
|
|
155
|
-
receiptIds.add(receipt.id);
|
|
156
|
-
}
|
|
157
|
-
for (const event of attention?.events || []) {
|
|
158
|
-
const receipt = (attention.receipts || []).find((item) => item.id === event.provenance?.receiptId);
|
|
159
|
-
if (!receipt || receipt.eventId !== event.id || receipt.digest !== event.provenance.digest) {
|
|
160
|
-
findings.push(`event-provenance-receipt-mismatch:${event.id}`);
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
return findings;
|
|
164
|
-
}
|
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
import { randomUUID } from "node:crypto";
|
|
2
|
-
import { open, readFile, stat, unlink, writeFile } from "node:fs/promises";
|
|
3
|
-
import { join } from "node:path";
|
|
4
|
-
import { buildCatalog } from "./catalog.js";
|
|
5
|
-
import { isFileLockContention, replaceFileWithRetry } from "./filesystem-retry.js";
|
|
6
|
-
import { projectStateDir } from "./paths.js";
|
|
7
|
-
import { MAX_STATE_BYTES, emptyAttention, normalizeAttention } from "./attention-schema.js";
|
|
8
|
-
|
|
9
|
-
export async function readAttentionFile(path, root) {
|
|
10
|
-
try {
|
|
11
|
-
const metadata = await stat(path);
|
|
12
|
-
if (metadata.size > MAX_STATE_BYTES) throw new Error("attention state exceeds the 5 MiB read limit");
|
|
13
|
-
return normalizeAttention(JSON.parse(await readFile(path, "utf8")), root);
|
|
14
|
-
} catch (error) {
|
|
15
|
-
if (error.code !== "ENOENT") throw error;
|
|
16
|
-
return emptyAttention(root);
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export async function loadAttention(root = process.cwd(), providedCatalog = null) {
|
|
21
|
-
const catalog = providedCatalog || await buildCatalog(root);
|
|
22
|
-
const directory = await projectStateDir(catalog.root);
|
|
23
|
-
const attentionPath = join(directory, "attention.json");
|
|
24
|
-
return { attention: await readAttentionFile(attentionPath, catalog.root), attentionPath, catalog };
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export async function inspectAttention(root = process.cwd(), providedCatalog = null) {
|
|
28
|
-
const catalog = providedCatalog || await buildCatalog(root);
|
|
29
|
-
const directory = await projectStateDir(catalog.root);
|
|
30
|
-
const attentionPath = join(directory, "attention.json");
|
|
31
|
-
try {
|
|
32
|
-
return { attention: await readAttentionFile(attentionPath, catalog.root), attentionPath, catalog, error: null };
|
|
33
|
-
} catch (error) {
|
|
34
|
-
return { attention: emptyAttention(catalog.root), attentionPath, catalog, error: error.message };
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export async function saveAttention(state, path) {
|
|
39
|
-
const content = `${JSON.stringify(state, null, 2)}\n`;
|
|
40
|
-
if (Buffer.byteLength(content) > MAX_STATE_BYTES) throw new Error("attention state exceeds 5 MiB; resolve or delete old cues first");
|
|
41
|
-
const temporary = `${path}.${process.pid}.${randomUUID()}.tmp`;
|
|
42
|
-
await writeFile(temporary, content, { mode: 0o600 });
|
|
43
|
-
await replaceFileWithRetry(temporary, path);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
export async function withAttentionLock(path, task) {
|
|
47
|
-
const lockPath = `${path}.lock`;
|
|
48
|
-
let handle;
|
|
49
|
-
for (let attempt = 0; attempt < 80; attempt += 1) {
|
|
50
|
-
try {
|
|
51
|
-
handle = await open(lockPath, "wx", 0o600);
|
|
52
|
-
break;
|
|
53
|
-
} catch (error) {
|
|
54
|
-
if (!isFileLockContention(error)) throw error;
|
|
55
|
-
try {
|
|
56
|
-
const metadata = await stat(lockPath);
|
|
57
|
-
if (Date.now() - metadata.mtimeMs > 15000) await unlink(lockPath);
|
|
58
|
-
} catch (lockError) {
|
|
59
|
-
if (lockError.code !== "ENOENT") throw lockError;
|
|
60
|
-
}
|
|
61
|
-
await new Promise((resolve) => setTimeout(resolve, 25));
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
if (!handle) throw new Error("attention state is busy; retry shortly");
|
|
65
|
-
try {
|
|
66
|
-
const state = await readAttentionFile(path, task.root);
|
|
67
|
-
const result = await task.run(state);
|
|
68
|
-
await saveAttention(state, path);
|
|
69
|
-
return result;
|
|
70
|
-
} finally {
|
|
71
|
-
await handle.close();
|
|
72
|
-
await unlink(lockPath).catch((error) => { if (error.code !== "ENOENT") throw error; });
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
export function preservePrevious(state, kind, value, now) {
|
|
77
|
-
if (!value) return;
|
|
78
|
-
state.history.push({
|
|
79
|
-
kind,
|
|
80
|
-
recordId: value.id,
|
|
81
|
-
entityId: value.entityId || null,
|
|
82
|
-
supersededAt: now,
|
|
83
|
-
value: { ...value, authority: "context-only" },
|
|
84
|
-
privacy: value.privacy || "private",
|
|
85
|
-
authority: "context-only"
|
|
86
|
-
});
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
export async function attentionMutation(root, operation, providedCatalog = null) {
|
|
90
|
-
const catalog = providedCatalog || await buildCatalog(root);
|
|
91
|
-
const { attentionPath } = await loadAttention(catalog.root, catalog);
|
|
92
|
-
return withAttentionLock(attentionPath, { root: catalog.root, run: (state) => operation(state, catalog, attentionPath) });
|
|
93
|
-
}
|