@ngockhoale/ckit 0.0.0-stage → 0.1.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/.env.example +42 -0
- package/README.md +116 -2
- package/dist/src/adapters/agent/claude/errors.d.ts +13 -0
- package/dist/src/adapters/agent/claude/errors.js +16 -0
- package/dist/src/adapters/agent/claude/normalize.d.ts +11 -0
- package/dist/src/adapters/agent/claude/normalize.js +83 -0
- package/dist/src/adapters/agent/errors.d.ts +13 -0
- package/dist/src/adapters/agent/errors.js +19 -0
- package/dist/src/adapters/agent/fixtures/claude-transcript.d.ts +70 -0
- package/dist/src/adapters/agent/fixtures/claude-transcript.js +15 -0
- package/dist/src/adapters/agent/fixtures/omp-transcript.d.ts +60 -0
- package/dist/src/adapters/agent/fixtures/omp-transcript.js +14 -0
- package/dist/src/adapters/agent/normalize.d.ts +18 -0
- package/dist/src/adapters/agent/normalize.js +77 -0
- package/dist/src/adapters/agent/transport.d.ts +35 -0
- package/dist/src/adapters/agent/transport.js +39 -0
- package/dist/src/adapters/agent/worker-service.d.ts +49 -0
- package/dist/src/adapters/agent/worker-service.js +77 -0
- package/dist/src/adapters/fake/fake-advisor.d.ts +15 -0
- package/dist/src/adapters/fake/fake-advisor.js +29 -0
- package/dist/src/adapters/fake/fake-agent.d.ts +12 -0
- package/dist/src/adapters/fake/fake-agent.js +21 -0
- package/dist/src/adapters/fake/fake-store.d.ts +13 -0
- package/dist/src/adapters/fake/fake-store.js +23 -0
- package/dist/src/adapters/fake/fake-web.d.ts +12 -0
- package/dist/src/adapters/fake/fake-web.js +21 -0
- package/dist/src/adapters/fake/fault-injector.d.ts +18 -0
- package/dist/src/adapters/fake/fault-injector.js +64 -0
- package/dist/src/adapters/fake/virtual-clock.d.ts +12 -0
- package/dist/src/adapters/fake/virtual-clock.js +35 -0
- package/dist/src/adapters/launch/discover.d.ts +18 -0
- package/dist/src/adapters/launch/discover.js +55 -0
- package/dist/src/adapters/launch/executor.d.ts +117 -0
- package/dist/src/adapters/launch/executor.js +383 -0
- package/dist/src/adapters/launch/profile.d.ts +35 -0
- package/dist/src/adapters/launch/profile.js +73 -0
- package/dist/src/adapters/launch/spawn.d.ts +29 -0
- package/dist/src/adapters/launch/spawn.js +18 -0
- package/dist/src/adapters/openai/openai-advisor.d.ts +56 -0
- package/dist/src/adapters/openai/openai-advisor.js +146 -0
- package/dist/src/cli/ckit.d.ts +5 -0
- package/dist/src/cli/ckit.js +472 -0
- package/dist/src/cli/demo.d.ts +1 -0
- package/dist/src/cli/demo.js +30 -0
- package/dist/src/cli/sessions.d.ts +10 -0
- package/dist/src/cli/sessions.js +381 -0
- package/dist/src/cli/setup.d.ts +11 -0
- package/dist/src/cli/setup.js +115 -0
- package/dist/src/committee/decision.d.ts +84 -0
- package/dist/src/committee/decision.js +167 -0
- package/dist/src/committee/handover.d.ts +115 -0
- package/dist/src/committee/handover.js +191 -0
- package/dist/src/committee/no-progress.d.ts +44 -0
- package/dist/src/committee/no-progress.js +64 -0
- package/dist/src/committee/primary-registry.d.ts +15 -0
- package/dist/src/committee/primary-registry.js +60 -0
- package/dist/src/committee/reply-parser.d.ts +28 -0
- package/dist/src/committee/reply-parser.js +53 -0
- package/dist/src/committee/reviewer-scheduler.d.ts +101 -0
- package/dist/src/committee/reviewer-scheduler.js +163 -0
- package/dist/src/committee/role-epoch.d.ts +91 -0
- package/dist/src/committee/role-epoch.js +154 -0
- package/dist/src/core/control.d.ts +18 -0
- package/dist/src/core/control.js +29 -0
- package/dist/src/core/entities.d.ts +166 -0
- package/dist/src/core/entities.js +119 -0
- package/dist/src/core/errors.d.ts +9 -0
- package/dist/src/core/errors.js +17 -0
- package/dist/src/core/events.d.ts +72 -0
- package/dist/src/core/events.js +125 -0
- package/dist/src/core/ids.d.ts +47 -0
- package/dist/src/core/ids.js +32 -0
- package/dist/src/core/machine.d.ts +55 -0
- package/dist/src/core/machine.js +110 -0
- package/dist/src/core/policy.d.ts +34 -0
- package/dist/src/core/policy.js +59 -0
- package/dist/src/core/provenance.d.ts +20 -0
- package/dist/src/core/provenance.js +21 -0
- package/dist/src/core/record.d.ts +35 -0
- package/dist/src/core/record.js +67 -0
- package/dist/src/core/replay.d.ts +10 -0
- package/dist/src/core/replay.js +36 -0
- package/dist/src/core/run-task.d.ts +20 -0
- package/dist/src/core/run-task.js +48 -0
- package/dist/src/diagnostics/doctor.d.ts +78 -0
- package/dist/src/diagnostics/doctor.js +365 -0
- package/dist/src/diagnostics/journal-lock.d.ts +38 -0
- package/dist/src/diagnostics/journal-lock.js +181 -0
- package/dist/src/evidence/linker.d.ts +44 -0
- package/dist/src/evidence/linker.js +75 -0
- package/dist/src/evidence/report-parser.d.ts +27 -0
- package/dist/src/evidence/report-parser.js +17 -0
- package/dist/src/evidence/store.d.ts +36 -0
- package/dist/src/evidence/store.js +57 -0
- package/dist/src/gui/server.d.ts +27 -0
- package/dist/src/gui/server.js +497 -0
- package/dist/src/host/checkpoint.d.ts +22 -0
- package/dist/src/host/checkpoint.js +74 -0
- package/dist/src/host/export.d.ts +52 -0
- package/dist/src/host/export.js +45 -0
- package/dist/src/host/ipc.d.ts +57 -0
- package/dist/src/host/ipc.js +124 -0
- package/dist/src/host/leases.d.ts +27 -0
- package/dist/src/host/leases.js +40 -0
- package/dist/src/host/retention.d.ts +47 -0
- package/dist/src/host/retention.js +130 -0
- package/dist/src/host/supervisor.d.ts +59 -0
- package/dist/src/host/supervisor.js +64 -0
- package/dist/src/intake/owner-intake.d.ts +31 -0
- package/dist/src/intake/owner-intake.js +97 -0
- package/dist/src/intake/types.d.ts +46 -0
- package/dist/src/intake/types.js +2 -0
- package/dist/src/intent/context-packet.d.ts +68 -0
- package/dist/src/intent/context-packet.js +76 -0
- package/dist/src/intent/idea-ledger.d.ts +50 -0
- package/dist/src/intent/idea-ledger.js +136 -0
- package/dist/src/intent/ledger.d.ts +35 -0
- package/dist/src/intent/ledger.js +40 -0
- package/dist/src/intent/registry.d.ts +51 -0
- package/dist/src/intent/registry.js +44 -0
- package/dist/src/intent/revision.d.ts +37 -0
- package/dist/src/intent/revision.js +48 -0
- package/dist/src/orchestration/dispatcher.d.ts +32 -0
- package/dist/src/orchestration/dispatcher.js +136 -0
- package/dist/src/orchestration/milestone-loop.d.ts +149 -0
- package/dist/src/orchestration/milestone-loop.js +132 -0
- package/dist/src/orchestration/recovery-coordinator.d.ts +74 -0
- package/dist/src/orchestration/recovery-coordinator.js +180 -0
- package/dist/src/orchestration/work-order-contract.d.ts +44 -0
- package/dist/src/orchestration/work-order-contract.js +85 -0
- package/dist/src/orchestration/work-queue.d.ts +56 -0
- package/dist/src/orchestration/work-queue.js +95 -0
- package/dist/src/ports/advisor.d.ts +33 -0
- package/dist/src/ports/advisor.js +2 -0
- package/dist/src/ports/agent.d.ts +31 -0
- package/dist/src/ports/agent.js +2 -0
- package/dist/src/ports/capabilities.d.ts +3 -0
- package/dist/src/ports/capabilities.js +5 -0
- package/dist/src/ports/clock.d.ts +5 -0
- package/dist/src/ports/clock.js +5 -0
- package/dist/src/ports/store.d.ts +13 -0
- package/dist/src/ports/store.js +2 -0
- package/dist/src/ports/web.d.ts +29 -0
- package/dist/src/ports/web.js +2 -0
- package/dist/src/run/api-run.d.ts +49 -0
- package/dist/src/run/api-run.js +173 -0
- package/dist/src/run/plan-run.d.ts +22 -0
- package/dist/src/run/plan-run.js +233 -0
- package/dist/src/run/plan.d.ts +36 -0
- package/dist/src/run/plan.js +119 -0
- package/dist/src/run/verify.d.ts +25 -0
- package/dist/src/run/verify.js +81 -0
- package/dist/src/security/redact.d.ts +7 -0
- package/dist/src/security/redact.js +21 -0
- package/dist/src/settings/env-config.d.ts +64 -0
- package/dist/src/settings/env-config.js +232 -0
- package/dist/src/storage/artifacts.d.ts +30 -0
- package/dist/src/storage/artifacts.js +105 -0
- package/dist/src/storage/audit.d.ts +6 -0
- package/dist/src/storage/audit.js +6 -0
- package/dist/src/storage/db.d.ts +9 -0
- package/dist/src/storage/db.js +43 -0
- package/dist/src/storage/events.d.ts +20 -0
- package/dist/src/storage/events.js +69 -0
- package/dist/src/storage/migrations.d.ts +8 -0
- package/dist/src/storage/migrations.js +48 -0
- package/dist/src/storage/outbox.d.ts +25 -0
- package/dist/src/storage/outbox.js +40 -0
- package/dist/src/storage/projections.d.ts +18 -0
- package/dist/src/storage/projections.js +40 -0
- package/dist/src/storage/reconcile.d.ts +14 -0
- package/dist/src/storage/reconcile.js +93 -0
- package/dist/src/storage/reservations.d.ts +12 -0
- package/dist/src/storage/reservations.js +80 -0
- package/dist/src/storage/store.d.ts +34 -0
- package/dist/src/storage/store.js +105 -0
- package/dist/src/team/attachments.d.ts +22 -0
- package/dist/src/team/attachments.js +211 -0
- package/dist/src/team/cli-models.d.ts +24 -0
- package/dist/src/team/cli-models.js +72 -0
- package/dist/src/team/config.d.ts +20 -0
- package/dist/src/team/config.js +111 -0
- package/dist/src/team/engine.d.ts +28 -0
- package/dist/src/team/engine.js +443 -0
- package/dist/src/team/journal.d.ts +30 -0
- package/dist/src/team/journal.js +70 -0
- package/dist/src/team/runners.d.ts +79 -0
- package/dist/src/team/runners.js +436 -0
- package/dist/src/team/secrets.d.ts +10 -0
- package/dist/src/team/secrets.js +68 -0
- package/dist/src/team/types.d.ts +155 -0
- package/dist/src/team/types.js +5 -0
- package/dist/src/tui/app.d.ts +29 -0
- package/dist/src/tui/app.js +96 -0
- package/dist/src/tui/control-model.d.ts +101 -0
- package/dist/src/tui/control-model.js +109 -0
- package/dist/src/tui/control-screens.d.ts +27 -0
- package/dist/src/tui/control-screens.js +85 -0
- package/dist/src/tui/graph-model.d.ts +34 -0
- package/dist/src/tui/graph-model.js +29 -0
- package/dist/src/tui/graph-screens.d.ts +13 -0
- package/dist/src/tui/graph-screens.js +4 -0
- package/dist/src/tui/inspector-model.d.ts +150 -0
- package/dist/src/tui/inspector-model.js +15 -0
- package/dist/src/tui/inspector-screens.d.ts +14 -0
- package/dist/src/tui/inspector-screens.js +61 -0
- package/dist/src/tui/live.d.ts +16 -0
- package/dist/src/tui/live.js +39 -0
- package/dist/src/tui/mission-action-screens.d.ts +15 -0
- package/dist/src/tui/mission-action-screens.js +105 -0
- package/dist/src/tui/mission-actions.d.ts +46 -0
- package/dist/src/tui/mission-actions.js +53 -0
- package/dist/src/tui/mission-model.d.ts +120 -0
- package/dist/src/tui/mission-model.js +164 -0
- package/dist/src/tui/mission-nav.d.ts +82 -0
- package/dist/src/tui/mission-nav.js +131 -0
- package/dist/src/tui/mission-plan-screens.d.ts +11 -0
- package/dist/src/tui/mission-plan-screens.js +40 -0
- package/dist/src/tui/mission-plan.d.ts +45 -0
- package/dist/src/tui/mission-plan.js +166 -0
- package/dist/src/tui/mission-screens.d.ts +7 -0
- package/dist/src/tui/mission-screens.js +263 -0
- package/dist/src/tui/provenance-label.d.ts +11 -0
- package/dist/src/tui/provenance-label.js +16 -0
- package/dist/src/tui/screens.d.ts +10 -0
- package/dist/src/tui/screens.js +34 -0
- package/dist/src/tui/session-outcome.d.ts +14 -0
- package/dist/src/tui/session-outcome.js +57 -0
- package/dist/src/tui/setup-model.d.ts +159 -0
- package/dist/src/tui/setup-model.js +234 -0
- package/dist/src/tui/setup-screens.d.ts +66 -0
- package/dist/src/tui/setup-screens.js +72 -0
- package/dist/src/tui/team/app.d.ts +24 -0
- package/dist/src/tui/team/app.js +228 -0
- package/dist/src/tui/team/demo-handle.d.ts +22 -0
- package/dist/src/tui/team/demo-handle.js +42 -0
- package/dist/src/tui/team/model.d.ts +81 -0
- package/dist/src/tui/team/model.js +133 -0
- package/gui/app.css +177 -0
- package/gui/app.js +675 -0
- package/gui/index.html +51 -0
- package/gui/network.js +413 -0
- package/package.json +45 -4
- package/src/storage/schema.sql +42 -0
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { artifactRef, sourceId } from '../core/ids.js';
|
|
2
|
+
import { classifySourceMessage, isOutboundEcho, promoteRequirement } from '../core/provenance.js';
|
|
3
|
+
import { RequirementRegistry } from '../intent/registry.js';
|
|
4
|
+
import { DurableOutbox } from '../storage/outbox.js';
|
|
5
|
+
/** Local, offline intake composition only. This service never dispatches work. */
|
|
6
|
+
export class OwnerIntakeService {
|
|
7
|
+
dependencies;
|
|
8
|
+
constraints = [];
|
|
9
|
+
messages = new Map();
|
|
10
|
+
requirements;
|
|
11
|
+
now;
|
|
12
|
+
constructor(dependencies) {
|
|
13
|
+
this.dependencies = dependencies;
|
|
14
|
+
if (!dependencies?.outbox || !dependencies.intentLedger || !dependencies.ideaLedger || typeof dependencies.sessionId !== 'string' || !dependencies.sessionId.trim())
|
|
15
|
+
throw new TypeError('intake dependencies and sessionId required');
|
|
16
|
+
this.requirements = dependencies.requirementRegistry;
|
|
17
|
+
this.now = dependencies.now ?? (() => new Date());
|
|
18
|
+
}
|
|
19
|
+
submit(input) {
|
|
20
|
+
if (!input || typeof input.commandId !== 'string' || !input.commandId.trim() || typeof input.requestId !== 'string' || !input.requestId.trim())
|
|
21
|
+
throw new TypeError('commandId and requestId required');
|
|
22
|
+
if (!input.message || typeof input.text !== 'string' || !input.text.trim() || !['discussion', 'execution', 'needs_owner_decision'].includes(input.route))
|
|
23
|
+
throw new TypeError('message, text and route required');
|
|
24
|
+
const classified = classifySourceMessage({ ...input.message, text: input.text });
|
|
25
|
+
const messageId = input.message.id;
|
|
26
|
+
sourceId(messageId);
|
|
27
|
+
artifactRef(`raw-${messageId}`);
|
|
28
|
+
const requestedRoute = input.route;
|
|
29
|
+
const route = classified.role === 'advisor' && (input.outOfScope || requestedRoute === 'execution') ? 'needs_owner_decision' : requestedRoute;
|
|
30
|
+
const source = Object.freeze({ sourceId: sourceId(messageId), origin: input.message.origin, role: classified.role, messageIdentity: messageId, revision: 1, hash: `intake:${messageId}`, rawRef: artifactRef(`raw-${messageId}`), observedAt: this.now().toISOString() });
|
|
31
|
+
const priorByRequest = this.dependencies.outbox.get(input.requestId);
|
|
32
|
+
if (priorByRequest && priorByRequest.commandId !== input.commandId)
|
|
33
|
+
throw new TypeError('requestId reused with different commandId');
|
|
34
|
+
const existingIntent = this.dependencies.intentLedger.get(source.sourceId);
|
|
35
|
+
if (existingIntent && !priorByRequest) {
|
|
36
|
+
if (existingIntent.text !== input.text || existingIntent.source.messageIdentity !== messageId)
|
|
37
|
+
throw new TypeError('source messages are immutable and unique');
|
|
38
|
+
throw new TypeError('source message already submitted');
|
|
39
|
+
}
|
|
40
|
+
const queued = (priorByRequest || route !== 'needs_owner_decision') ? this.dependencies.outbox.accept({ commandId: input.commandId, requestId: input.requestId, payload: { messageId, text: input.text, route, provenance: classified }, ...(input.reason === undefined ? {} : { reason: input.reason }), ...(input.draft === undefined ? {} : { draft: input.draft }) }) : null;
|
|
41
|
+
if (queued?.duplicate && existingIntent) {
|
|
42
|
+
const ideaRecorded = classified.role !== 'advisor' || this.dependencies.ideaLedger.list().some((idea) => idea.sourceTraces.some((trace) => trace.source.sourceId === source.sourceId));
|
|
43
|
+
if (ideaRecorded)
|
|
44
|
+
return Object.freeze({ messageId, route, classified, rawText: input.text, intent: null, queued, workerMutations: 0, dispatches: 0 });
|
|
45
|
+
try {
|
|
46
|
+
this.dependencies.ideaLedger.ingest({ text: input.text, source });
|
|
47
|
+
}
|
|
48
|
+
catch (cause) {
|
|
49
|
+
throw new Error('owner intake ledger ingestion failed after outbox acceptance (accepted: true)', { cause });
|
|
50
|
+
}
|
|
51
|
+
this.messages.set(messageId, { source, text: input.text });
|
|
52
|
+
return Object.freeze({ messageId, route, classified, rawText: input.text, intent: existingIntent, queued, workerMutations: 0, dispatches: 0 });
|
|
53
|
+
}
|
|
54
|
+
let intent;
|
|
55
|
+
try {
|
|
56
|
+
intent = this.dependencies.intentLedger.ingest(source, input.text, input.message.transportActor);
|
|
57
|
+
if (classified.role === 'advisor')
|
|
58
|
+
this.dependencies.ideaLedger.ingest({ text: input.text, source });
|
|
59
|
+
}
|
|
60
|
+
catch (cause) {
|
|
61
|
+
throw new Error(`owner intake ledger ingestion failed after outbox acceptance (accepted: ${queued !== null})`, { cause });
|
|
62
|
+
}
|
|
63
|
+
this.messages.set(messageId, { source, text: input.text });
|
|
64
|
+
return Object.freeze({ messageId, route, classified, rawText: input.text, intent, queued, workerMutations: 0, dispatches: 0 });
|
|
65
|
+
}
|
|
66
|
+
confirmConstraint(messageId, input) {
|
|
67
|
+
const record = this.messages.get(messageId);
|
|
68
|
+
if (!record || !input || typeof input.id !== 'string' || !input.id.trim())
|
|
69
|
+
throw new TypeError('known owner source and requirement id required');
|
|
70
|
+
if (record.source.origin !== 'ckit' || record.source.role !== 'owner')
|
|
71
|
+
throw new TypeError('only owner-authenticated composer messages can confirm a constraint');
|
|
72
|
+
const previous = [...this.constraints].reverse().find((constraint) => constraint.supersededBy === null);
|
|
73
|
+
const message = { id: messageId, origin: record.source.origin, role: 'owner', text: record.text, transportActor: 'owner' };
|
|
74
|
+
const provenance = { message: promoteRequirement(message, 'owner'), observedAt: record.source.observedAt, sessionId: this.dependencies.sessionId };
|
|
75
|
+
this.requirements?.importOwnerRequirement({ id: input.id, text: record.text, scope: input.scope, provenance });
|
|
76
|
+
if (previous) {
|
|
77
|
+
const index = this.constraints.indexOf(previous);
|
|
78
|
+
this.constraints[index] = Object.freeze({ ...previous, supersededBy: input.id });
|
|
79
|
+
}
|
|
80
|
+
const confirmed = Object.freeze({ id: input.id, sourceId: messageId, rawText: record.text, scope: input.scope, supersededBy: null });
|
|
81
|
+
this.constraints.push(confirmed);
|
|
82
|
+
return confirmed;
|
|
83
|
+
}
|
|
84
|
+
confirmedConstraints() { return Object.freeze([...this.constraints]); }
|
|
85
|
+
local(control) {
|
|
86
|
+
const responses = { pause: 'Pause requested locally; no model call was made.', help: 'Local controls: pause, help, view.', view: `Local intake view: ${this.messages.size} message(s).` };
|
|
87
|
+
if (!Object.hasOwn(responses, control))
|
|
88
|
+
throw new TypeError('unsupported local control');
|
|
89
|
+
// Structural count: OwnerIntakeService has no model dependency or invocation path.
|
|
90
|
+
return Object.freeze({ control, response: responses[control], modelCalls: 0 });
|
|
91
|
+
}
|
|
92
|
+
markEcho(message, controllerRequestIds) {
|
|
93
|
+
const classified = classifySourceMessage(message);
|
|
94
|
+
return Object.freeze({ origin: isOutboundEcho(message, controllerRequestIds) ? 'outbound' : 'inbound', message: classified });
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
//# sourceMappingURL=owner-intake.js.map
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { ClassifiedSourceMessage, IncomingSourceMessage } from '../core/provenance.js';
|
|
2
|
+
import type { LedgerEntry } from '../intent/ledger.js';
|
|
3
|
+
import type { QueuedRequest } from '../storage/outbox.js';
|
|
4
|
+
export type IntakeRoute = 'discussion' | 'execution' | 'needs_owner_decision';
|
|
5
|
+
export type LocalControl = 'pause' | 'help' | 'view';
|
|
6
|
+
export interface OwnerIntakeInput {
|
|
7
|
+
readonly commandId: string;
|
|
8
|
+
readonly requestId: string;
|
|
9
|
+
readonly message: IncomingSourceMessage;
|
|
10
|
+
readonly text: string;
|
|
11
|
+
readonly route: IntakeRoute;
|
|
12
|
+
readonly outOfScope?: boolean;
|
|
13
|
+
readonly reason?: string;
|
|
14
|
+
readonly draft?: unknown;
|
|
15
|
+
}
|
|
16
|
+
export interface IntakeResult {
|
|
17
|
+
readonly messageId: string;
|
|
18
|
+
readonly route: IntakeRoute;
|
|
19
|
+
readonly classified: ClassifiedSourceMessage;
|
|
20
|
+
readonly rawText: string;
|
|
21
|
+
readonly intent: LedgerEntry | null;
|
|
22
|
+
readonly queued: QueuedRequest | null;
|
|
23
|
+
readonly workerMutations: 0;
|
|
24
|
+
readonly dispatches: 0;
|
|
25
|
+
}
|
|
26
|
+
export interface LocalControlResult {
|
|
27
|
+
readonly control: LocalControl;
|
|
28
|
+
readonly response: string;
|
|
29
|
+
readonly modelCalls: 0;
|
|
30
|
+
}
|
|
31
|
+
export interface EchoClassification {
|
|
32
|
+
readonly origin: 'outbound' | 'inbound';
|
|
33
|
+
readonly message: ClassifiedSourceMessage;
|
|
34
|
+
}
|
|
35
|
+
export interface ConfirmedConstraint {
|
|
36
|
+
readonly id: string;
|
|
37
|
+
readonly sourceId: string;
|
|
38
|
+
readonly rawText: string;
|
|
39
|
+
readonly scope: {
|
|
40
|
+
readonly kind: 'read' | 'write';
|
|
41
|
+
} | {
|
|
42
|
+
readonly kind: 'session';
|
|
43
|
+
readonly sessionId: string;
|
|
44
|
+
};
|
|
45
|
+
readonly supersededBy: string | null;
|
|
46
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
export type AcceptanceStatus = 'open' | 'satisfied' | 'incomplete';
|
|
2
|
+
export interface AcceptanceCriterionInput {
|
|
3
|
+
readonly id: string;
|
|
4
|
+
readonly text: string;
|
|
5
|
+
readonly status: AcceptanceStatus;
|
|
6
|
+
}
|
|
7
|
+
export interface PacketBudget {
|
|
8
|
+
readonly limit: number;
|
|
9
|
+
readonly measuredBytes: number;
|
|
10
|
+
readonly overflow: boolean;
|
|
11
|
+
readonly strategy: 'within-budget' | 'scope-split' | 'evidence-selection';
|
|
12
|
+
readonly message: string;
|
|
13
|
+
readonly omittedEvidence: readonly string[];
|
|
14
|
+
}
|
|
15
|
+
export interface PrimaryContextInput {
|
|
16
|
+
readonly intent: string;
|
|
17
|
+
readonly constraints: readonly string[];
|
|
18
|
+
readonly acceptanceCriteria: readonly AcceptanceCriterionInput[];
|
|
19
|
+
readonly delta: string;
|
|
20
|
+
readonly budget: number;
|
|
21
|
+
readonly evidence?: readonly string[];
|
|
22
|
+
/** Accepted for caller compatibility, intentionally never copied into a packet. */
|
|
23
|
+
readonly rawHistory?: readonly string[];
|
|
24
|
+
}
|
|
25
|
+
export interface PrimaryContextPacket {
|
|
26
|
+
readonly kind: 'primary';
|
|
27
|
+
readonly intent: string;
|
|
28
|
+
readonly constraints: readonly string[];
|
|
29
|
+
readonly openAcceptanceCriteria: readonly AcceptanceCriterionInput[];
|
|
30
|
+
readonly delta: string;
|
|
31
|
+
readonly evidence: readonly string[];
|
|
32
|
+
readonly content: Readonly<{
|
|
33
|
+
intent: string;
|
|
34
|
+
constraints: readonly string[];
|
|
35
|
+
openAcceptanceCriteria: readonly AcceptanceCriterionInput[];
|
|
36
|
+
delta: string;
|
|
37
|
+
evidence: readonly string[];
|
|
38
|
+
}>;
|
|
39
|
+
readonly budget: PacketBudget;
|
|
40
|
+
}
|
|
41
|
+
export interface ReviewerContextPacket {
|
|
42
|
+
readonly kind: 'reviewer';
|
|
43
|
+
readonly question: string;
|
|
44
|
+
readonly evidence: readonly string[];
|
|
45
|
+
readonly constraints: readonly string[];
|
|
46
|
+
readonly content: Readonly<{
|
|
47
|
+
question: string;
|
|
48
|
+
evidence: readonly string[];
|
|
49
|
+
constraints: readonly string[];
|
|
50
|
+
}>;
|
|
51
|
+
readonly budget: PacketBudget;
|
|
52
|
+
}
|
|
53
|
+
export declare function buildPrimaryContextPacket(input: PrimaryContextInput): PrimaryContextPacket;
|
|
54
|
+
export declare function buildReviewerContextPacket(input: {
|
|
55
|
+
readonly question: string;
|
|
56
|
+
readonly evidence: readonly string[];
|
|
57
|
+
readonly constraints: readonly string[];
|
|
58
|
+
readonly budget: number;
|
|
59
|
+
}): ReviewerContextPacket;
|
|
60
|
+
export declare function evaluateAcceptanceCompletion(input: {
|
|
61
|
+
readonly summary?: string;
|
|
62
|
+
readonly acceptanceCriteria: readonly AcceptanceCriterionInput[];
|
|
63
|
+
readonly sourceComplete?: boolean;
|
|
64
|
+
}): {
|
|
65
|
+
readonly complete: boolean;
|
|
66
|
+
readonly openCriteria: readonly AcceptanceCriterionInput[];
|
|
67
|
+
readonly basis: 'acceptance-source';
|
|
68
|
+
};
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { redactSecretText } from '../security/redact.js';
|
|
2
|
+
const sizeOf = (value) => Buffer.byteLength(JSON.stringify(value), 'utf8');
|
|
3
|
+
const validateStrings = (label, values) => {
|
|
4
|
+
if (!Array.isArray(values) || !values.every(value => typeof value === 'string' && value.trim().length > 0))
|
|
5
|
+
throw new TypeError(`${label} must contain non-empty strings`);
|
|
6
|
+
};
|
|
7
|
+
const validateBudget = (budget) => {
|
|
8
|
+
if (!Number.isSafeInteger(budget) || budget < 0)
|
|
9
|
+
throw new TypeError('budget must be a non-negative safe integer');
|
|
10
|
+
};
|
|
11
|
+
const freezeCriteria = (values) => {
|
|
12
|
+
if (!Array.isArray(values) || !values.every(value => value && typeof value.id === 'string' && value.id.length > 0 && typeof value.text === 'string' && value.text.length > 0 && ['open', 'satisfied', 'incomplete'].includes(value.status)))
|
|
13
|
+
throw new TypeError('acceptance criteria must have an id, text and valid status');
|
|
14
|
+
return Object.freeze(values.filter(value => value.status !== 'satisfied').map(value => Object.freeze({ ...value })));
|
|
15
|
+
};
|
|
16
|
+
function budgetReport(limit, measuredBytes, omittedEvidence, strategy) {
|
|
17
|
+
const overflow = measuredBytes > limit;
|
|
18
|
+
return Object.freeze({ limit, measuredBytes, overflow, strategy: overflow ? strategy : 'within-budget',
|
|
19
|
+
message: overflow ? `Context packet overflow (${measuredBytes} bytes > ${limit}); ${strategy} required. Hard requirements retained.` : 'Context packet fits budget.',
|
|
20
|
+
omittedEvidence: Object.freeze([...omittedEvidence]) });
|
|
21
|
+
}
|
|
22
|
+
export function buildPrimaryContextPacket(input) {
|
|
23
|
+
if (!input || typeof input.intent !== 'string' || !input.intent.trim() || typeof input.delta !== 'string')
|
|
24
|
+
throw new TypeError('intent and delta are required');
|
|
25
|
+
validateBudget(input.budget);
|
|
26
|
+
validateStrings('constraints', input.constraints);
|
|
27
|
+
const constraints = Object.freeze(input.constraints.map(item => redactSecretText(item)));
|
|
28
|
+
const openAcceptanceCriteria = Object.freeze(freezeCriteria(input.acceptanceCriteria).map(item => Object.freeze({ ...item, text: redactSecretText(item.text) })));
|
|
29
|
+
const rawCandidates = input.evidence ?? [];
|
|
30
|
+
validateStrings('evidence', rawCandidates);
|
|
31
|
+
const candidates = rawCandidates.map(item => redactSecretText(item));
|
|
32
|
+
const mandatory = { intent: redactSecretText(input.intent), constraints, openAcceptanceCriteria, delta: redactSecretText(input.delta) };
|
|
33
|
+
const selected = [];
|
|
34
|
+
const omitted = [];
|
|
35
|
+
for (const item of candidates) {
|
|
36
|
+
const tentative = { ...mandatory, evidence: [...selected, item] };
|
|
37
|
+
if (sizeOf(tentative) <= input.budget)
|
|
38
|
+
selected.push(item);
|
|
39
|
+
else
|
|
40
|
+
omitted.push(item);
|
|
41
|
+
}
|
|
42
|
+
const evidence = Object.freeze(selected);
|
|
43
|
+
const content = Object.freeze({ ...mandatory, evidence });
|
|
44
|
+
const measuredBytes = sizeOf(content);
|
|
45
|
+
const strategy = measuredBytes > input.budget ? 'scope-split' : omitted.length > 0 ? 'evidence-selection' : 'within-budget';
|
|
46
|
+
return Object.freeze({ kind: 'primary', ...mandatory, evidence, content, budget: budgetReport(input.budget, measuredBytes, omitted, strategy) });
|
|
47
|
+
}
|
|
48
|
+
export function buildReviewerContextPacket(input) {
|
|
49
|
+
if (!input || typeof input.question !== 'string' || !input.question.trim())
|
|
50
|
+
throw new TypeError('specific reviewer question is required');
|
|
51
|
+
validateBudget(input.budget);
|
|
52
|
+
validateStrings('constraints', input.constraints);
|
|
53
|
+
validateStrings('evidence', input.evidence);
|
|
54
|
+
const question = redactSecretText(input.question);
|
|
55
|
+
const constraints = Object.freeze(input.constraints.map(item => redactSecretText(item)));
|
|
56
|
+
const selected = [];
|
|
57
|
+
const omitted = [];
|
|
58
|
+
for (const item of input.evidence.map(entry => redactSecretText(entry))) {
|
|
59
|
+
if (sizeOf({ question, evidence: [...selected, item], constraints }) <= input.budget)
|
|
60
|
+
selected.push(item);
|
|
61
|
+
else
|
|
62
|
+
omitted.push(item);
|
|
63
|
+
}
|
|
64
|
+
const evidence = Object.freeze(selected);
|
|
65
|
+
const content = Object.freeze({ question, evidence, constraints });
|
|
66
|
+
const measuredBytes = sizeOf(content);
|
|
67
|
+
const strategy = measuredBytes > input.budget ? 'scope-split' : omitted.length > 0 ? 'evidence-selection' : 'within-budget';
|
|
68
|
+
return Object.freeze({ kind: 'reviewer', ...content, content, budget: budgetReport(input.budget, measuredBytes, omitted, strategy) });
|
|
69
|
+
}
|
|
70
|
+
export function evaluateAcceptanceCompletion(input) {
|
|
71
|
+
if (!input || typeof input.sourceComplete !== 'undefined' && typeof input.sourceComplete !== 'boolean')
|
|
72
|
+
throw new TypeError('valid acceptance source state required');
|
|
73
|
+
const unresolved = Object.freeze(input.acceptanceCriteria.filter(value => value.status !== 'satisfied').map(value => Object.freeze({ ...value })));
|
|
74
|
+
return Object.freeze({ complete: input.sourceComplete !== false && unresolved.length === 0, openCriteria: unresolved, basis: 'acceptance-source' });
|
|
75
|
+
}
|
|
76
|
+
//# sourceMappingURL=context-packet.js.map
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { Idea, SourceMessage } from '../core/entities.js';
|
|
2
|
+
import { type ArtifactRef, type IdeaId } from '../core/ids.js';
|
|
3
|
+
export type IdeaDisposition = 'accepted' | 'rejected' | 'deferred' | 'needs_evidence';
|
|
4
|
+
export interface IdeaSourceTrace {
|
|
5
|
+
readonly source: SourceMessage;
|
|
6
|
+
readonly disposition: IdeaDisposition | null;
|
|
7
|
+
readonly dispositionReason: string | null;
|
|
8
|
+
readonly evidenceRefs: readonly ArtifactRef[];
|
|
9
|
+
}
|
|
10
|
+
export interface IdeaRecord extends Omit<Idea, 'sources'> {
|
|
11
|
+
readonly id: IdeaId;
|
|
12
|
+
readonly text: string;
|
|
13
|
+
readonly sources: readonly IdeaSourceTrace[];
|
|
14
|
+
readonly sourceTraces: readonly IdeaSourceTrace[];
|
|
15
|
+
}
|
|
16
|
+
export interface IdeaInput {
|
|
17
|
+
readonly text: string;
|
|
18
|
+
readonly source: SourceMessage;
|
|
19
|
+
}
|
|
20
|
+
export interface ContextSelection {
|
|
21
|
+
readonly overflow: boolean;
|
|
22
|
+
readonly strategy: 'within-budget' | 'scope-split' | 'evidence-selection';
|
|
23
|
+
readonly budget: number;
|
|
24
|
+
readonly estimatedSize: number;
|
|
25
|
+
readonly hardRequirements: readonly string[];
|
|
26
|
+
readonly evidence: readonly string[];
|
|
27
|
+
readonly omittedEvidence: readonly string[];
|
|
28
|
+
readonly message: string;
|
|
29
|
+
}
|
|
30
|
+
/** In-memory idea grouping/disposition service. Inputs include source attribution; collection is local and model-free. */
|
|
31
|
+
export declare class IdeaLedger {
|
|
32
|
+
private readonly records;
|
|
33
|
+
private readonly sourceOwners;
|
|
34
|
+
private nextId;
|
|
35
|
+
ingest(input: IdeaInput): IdeaRecord;
|
|
36
|
+
get(id: string): IdeaRecord | undefined;
|
|
37
|
+
list(): readonly IdeaRecord[];
|
|
38
|
+
setDisposition(id: string, disposition: IdeaDisposition, reason: string): IdeaRecord;
|
|
39
|
+
setSourceDisposition(id: string, source: string, disposition: IdeaDisposition, reason: string): IdeaRecord;
|
|
40
|
+
addEvidence(id: string, source: string, contentDelta: string, evidence: string): IdeaRecord;
|
|
41
|
+
/** Rejected ideas remain suppressed until distinct provenance and evidence/content delta are recorded. */
|
|
42
|
+
contextIdeas(): readonly IdeaRecord[];
|
|
43
|
+
selectContext(input: {
|
|
44
|
+
readonly budget: number;
|
|
45
|
+
readonly hardRequirements: readonly string[];
|
|
46
|
+
readonly evidence: readonly string[];
|
|
47
|
+
}): ContextSelection;
|
|
48
|
+
private newTrace;
|
|
49
|
+
private requireRecord;
|
|
50
|
+
}
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import { artifactRef, ideaId, sourceId } from '../core/ids.js';
|
|
2
|
+
const dispositionStatuses = {
|
|
3
|
+
accepted: 'accepted', rejected: 'rejected', deferred: 'deferred', needs_evidence: 'needs_evidence',
|
|
4
|
+
};
|
|
5
|
+
const canonical = (text) => text.normalize('NFKC').toLocaleLowerCase().replace(/[^\p{L}\p{N}]+/gu, ' ').trim();
|
|
6
|
+
const similar = (left, right) => {
|
|
7
|
+
const a = new Set(canonical(left).split(/\s+/).filter(Boolean));
|
|
8
|
+
const b = new Set(canonical(right).split(/\s+/).filter(Boolean));
|
|
9
|
+
if (!a.size || !b.size)
|
|
10
|
+
return false;
|
|
11
|
+
let overlap = 0;
|
|
12
|
+
for (const word of a)
|
|
13
|
+
if (b.has(word))
|
|
14
|
+
overlap++;
|
|
15
|
+
return overlap / Math.min(a.size, b.size) >= 0.8;
|
|
16
|
+
};
|
|
17
|
+
const cloneSource = (source) => Object.freeze({ ...source });
|
|
18
|
+
/** In-memory idea grouping/disposition service. Inputs include source attribution; collection is local and model-free. */
|
|
19
|
+
export class IdeaLedger {
|
|
20
|
+
records = new Map();
|
|
21
|
+
sourceOwners = new Map();
|
|
22
|
+
nextId = 1;
|
|
23
|
+
ingest(input) {
|
|
24
|
+
if (!input || typeof input.text !== 'string' || !input.text.trim() || !input.source || typeof input.source.sourceId !== 'string') {
|
|
25
|
+
throw new TypeError('idea text and source provenance required');
|
|
26
|
+
}
|
|
27
|
+
const sourceKey = sourceId(input.source.sourceId);
|
|
28
|
+
const text = input.text.trim();
|
|
29
|
+
const priorId = this.sourceOwners.get(sourceKey);
|
|
30
|
+
if (priorId) {
|
|
31
|
+
const prior = this.records.get(priorId);
|
|
32
|
+
// Re-ingesting the same source is idempotent; it cannot count as new evidence.
|
|
33
|
+
return prior;
|
|
34
|
+
}
|
|
35
|
+
const normalized = canonical(text);
|
|
36
|
+
const previousRejected = [...this.records.values()].find((record) => record.status === 'rejected' && similar(record.text, text));
|
|
37
|
+
const changedEvidence = previousRejected && !previousRejected.sourceTraces.some((trace) => trace.source.sourceId === sourceKey)
|
|
38
|
+
&& normalized !== canonical(previousRejected.text);
|
|
39
|
+
if (previousRejected && !changedEvidence) {
|
|
40
|
+
const trace = this.newTrace(input.source);
|
|
41
|
+
const traces = Object.freeze([...previousRejected.sourceTraces, trace]);
|
|
42
|
+
const updated = Object.freeze({ ...previousRejected, sources: traces, sourceTraces: traces });
|
|
43
|
+
this.records.set(updated.ideaId, updated);
|
|
44
|
+
this.sourceOwners.set(sourceKey, updated.ideaId);
|
|
45
|
+
return updated;
|
|
46
|
+
}
|
|
47
|
+
const matching = !changedEvidence ? [...this.records.values()].find((record) => record.status !== 'rejected' && similar(record.text, text)) : undefined;
|
|
48
|
+
if (matching) {
|
|
49
|
+
const newTrace = this.newTrace(input.source);
|
|
50
|
+
const traces = Object.freeze([...matching.sourceTraces, newTrace]);
|
|
51
|
+
const updated = Object.freeze({ ...matching, sources: traces, sourceTraces: traces });
|
|
52
|
+
this.records.set(updated.ideaId, updated);
|
|
53
|
+
this.sourceOwners.set(sourceKey, updated.ideaId);
|
|
54
|
+
return updated;
|
|
55
|
+
}
|
|
56
|
+
const id = ideaId(`idea-${String(this.nextId++).padStart(8, '0')}`);
|
|
57
|
+
const trace = this.newTrace(input.source);
|
|
58
|
+
const traces = Object.freeze([trace]);
|
|
59
|
+
const created = Object.freeze({ ideaId: id, id, text, sources: traces, sourceTraces: traces, requirementIds: Object.freeze([]), status: 'open', dispositionReason: null, evidenceRefs: Object.freeze([]) });
|
|
60
|
+
this.records.set(id, created);
|
|
61
|
+
this.sourceOwners.set(sourceKey, id);
|
|
62
|
+
return created;
|
|
63
|
+
}
|
|
64
|
+
get(id) { return this.records.get(ideaId(id)); }
|
|
65
|
+
list() { return Object.freeze([...this.records.values()]); }
|
|
66
|
+
setDisposition(id, disposition, reason) {
|
|
67
|
+
const record = this.requireRecord(id);
|
|
68
|
+
if (!(disposition in dispositionStatuses) || typeof reason !== 'string' || !reason.trim())
|
|
69
|
+
throw new TypeError('valid disposition and reason required');
|
|
70
|
+
const traces = record.sourceTraces.map((trace) => Object.freeze({ ...trace, disposition, dispositionReason: reason.trim() }));
|
|
71
|
+
const updated = Object.freeze({ ...record, status: dispositionStatuses[disposition], dispositionReason: reason.trim(), sourceTraces: Object.freeze(traces), sources: Object.freeze(traces) });
|
|
72
|
+
this.records.set(updated.ideaId, updated);
|
|
73
|
+
return updated;
|
|
74
|
+
}
|
|
75
|
+
setSourceDisposition(id, source, disposition, reason) {
|
|
76
|
+
const record = this.requireRecord(id);
|
|
77
|
+
const key = sourceId(source);
|
|
78
|
+
if (!record.sourceTraces.some((trace) => trace.source.sourceId === key) || !(disposition in dispositionStatuses) || typeof reason !== 'string' || !reason.trim())
|
|
79
|
+
throw new TypeError('known source, valid disposition and reason required');
|
|
80
|
+
const traces = record.sourceTraces.map((trace) => trace.source.sourceId === key ? Object.freeze({ ...trace, disposition, dispositionReason: reason.trim() }) : trace);
|
|
81
|
+
const updated = Object.freeze({ ...record, sourceTraces: Object.freeze(traces), sources: Object.freeze(traces) });
|
|
82
|
+
this.records.set(updated.ideaId, updated);
|
|
83
|
+
return updated;
|
|
84
|
+
}
|
|
85
|
+
addEvidence(id, source, contentDelta, evidence) {
|
|
86
|
+
const record = this.requireRecord(id);
|
|
87
|
+
const key = sourceId(source);
|
|
88
|
+
if (!record.sourceTraces.some((trace) => trace.source.sourceId === key) || typeof contentDelta !== 'string' || !contentDelta.trim() || typeof evidence !== 'string' || !evidence.trim()) {
|
|
89
|
+
throw new TypeError('known source and distinct evidence with content delta required');
|
|
90
|
+
}
|
|
91
|
+
if (record.status === 'rejected' && canonical(contentDelta) === canonical(record.text)) {
|
|
92
|
+
throw new TypeError('reopening a rejected idea requires a content delta distinct from the rejected idea');
|
|
93
|
+
}
|
|
94
|
+
const reference = artifactRef(evidence);
|
|
95
|
+
const traces = record.sourceTraces.map((trace) => trace.source.sourceId === key
|
|
96
|
+
? Object.freeze({ ...trace, evidenceRefs: Object.freeze([...trace.evidenceRefs, reference]) }) : trace);
|
|
97
|
+
const updated = Object.freeze({ ...record, status: record.status === 'rejected' ? 'open' : record.status, dispositionReason: record.status === 'rejected' ? null : record.dispositionReason, evidenceRefs: Object.freeze([...record.evidenceRefs, reference]), sources: Object.freeze(traces), sourceTraces: Object.freeze(traces) });
|
|
98
|
+
this.records.set(updated.ideaId, updated);
|
|
99
|
+
return updated;
|
|
100
|
+
}
|
|
101
|
+
/** Rejected ideas remain suppressed until distinct provenance and evidence/content delta are recorded. */
|
|
102
|
+
contextIdeas() { return Object.freeze([...this.records.values()].filter((record) => record.status !== 'rejected')); }
|
|
103
|
+
selectContext(input) {
|
|
104
|
+
if (!input || !Number.isSafeInteger(input.budget) || input.budget < 0 || !Array.isArray(input.hardRequirements) || !input.hardRequirements.every((x) => typeof x === 'string' && x.length > 0) || !Array.isArray(input.evidence) || !input.evidence.every((x) => typeof x === 'string' && x.length > 0)) {
|
|
105
|
+
throw new TypeError('non-negative budget and valid requirement/evidence lists required');
|
|
106
|
+
}
|
|
107
|
+
const hardRequirements = Object.freeze([...input.hardRequirements]);
|
|
108
|
+
const evidence = Object.freeze([...input.evidence]);
|
|
109
|
+
const fixedSize = hardRequirements.reduce((sum, value) => sum + value.length, 0);
|
|
110
|
+
const remaining = Math.max(0, input.budget - fixedSize);
|
|
111
|
+
let used = 0;
|
|
112
|
+
const selected = [];
|
|
113
|
+
const omitted = [];
|
|
114
|
+
for (const item of evidence) {
|
|
115
|
+
if (used + item.length <= remaining) {
|
|
116
|
+
selected.push(item);
|
|
117
|
+
used += item.length;
|
|
118
|
+
}
|
|
119
|
+
else
|
|
120
|
+
omitted.push(item);
|
|
121
|
+
}
|
|
122
|
+
const overflow = fixedSize + evidence.reduce((sum, item) => sum + item.length, 0) > input.budget;
|
|
123
|
+
const strategy = !overflow ? 'within-budget' : omitted.length > 0 ? 'evidence-selection' : 'scope-split';
|
|
124
|
+
return Object.freeze({ overflow, strategy, budget: input.budget, estimatedSize: fixedSize + selected.reduce((sum, item) => sum + item.length, 0), hardRequirements, evidence: Object.freeze(selected), omittedEvidence: Object.freeze(omitted), message: overflow ? `Context budget ${input.budget} exceeded; ${strategy} required. All hard requirements retained.` : 'Context fits the requested budget.' });
|
|
125
|
+
}
|
|
126
|
+
newTrace(source) {
|
|
127
|
+
return Object.freeze({ source: cloneSource(source), disposition: null, dispositionReason: null, evidenceRefs: Object.freeze([]) });
|
|
128
|
+
}
|
|
129
|
+
requireRecord(id) {
|
|
130
|
+
const record = this.records.get(ideaId(id));
|
|
131
|
+
if (!record)
|
|
132
|
+
throw new TypeError('unknown idea');
|
|
133
|
+
return record;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
//# sourceMappingURL=idea-ledger.js.map
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { RequirementRegistry, type Requirement, type RequirementProvenance, type AuthorizationScope } from './registry.js';
|
|
2
|
+
import type { SourceMessage } from '../core/entities.js';
|
|
3
|
+
export type LedgerEntry = ProposalEntry | QuestionEntry;
|
|
4
|
+
export interface ProposalEntry {
|
|
5
|
+
readonly id: string;
|
|
6
|
+
readonly kind: 'proposal' | 'assumption';
|
|
7
|
+
readonly status: 'unconfirmed' | 'promoted';
|
|
8
|
+
readonly source: SourceMessage;
|
|
9
|
+
readonly text: string;
|
|
10
|
+
readonly executionAuthorized: false;
|
|
11
|
+
}
|
|
12
|
+
export interface QuestionEntry {
|
|
13
|
+
readonly id: string;
|
|
14
|
+
readonly kind: 'question';
|
|
15
|
+
readonly status: 'open';
|
|
16
|
+
readonly source: SourceMessage;
|
|
17
|
+
readonly text: string;
|
|
18
|
+
readonly executionAuthorized: false;
|
|
19
|
+
}
|
|
20
|
+
export declare class IntentLedger {
|
|
21
|
+
private readonly registry;
|
|
22
|
+
private readonly entries;
|
|
23
|
+
private readonly dispatched;
|
|
24
|
+
private currentStatus;
|
|
25
|
+
constructor(registry: RequirementRegistry);
|
|
26
|
+
get status(): string;
|
|
27
|
+
get dispatches(): readonly string[];
|
|
28
|
+
ingest(source: SourceMessage, text: string, actor: 'owner' | 'advisor' | 'worker' | 'system'): LedgerEntry;
|
|
29
|
+
get(id: string): LedgerEntry | undefined;
|
|
30
|
+
promote(id: string, actor: 'owner' | 'advisor' | 'worker' | 'system', input: {
|
|
31
|
+
readonly id: string;
|
|
32
|
+
readonly scope: AuthorizationScope;
|
|
33
|
+
readonly provenance: RequirementProvenance;
|
|
34
|
+
}): Requirement;
|
|
35
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { RequirementRegistry } from './registry.js';
|
|
2
|
+
import { sourceId } from '../core/ids.js';
|
|
3
|
+
export class IntentLedger {
|
|
4
|
+
registry;
|
|
5
|
+
entries = new Map();
|
|
6
|
+
dispatched = [];
|
|
7
|
+
currentStatus = 'idle';
|
|
8
|
+
constructor(registry) {
|
|
9
|
+
this.registry = registry;
|
|
10
|
+
}
|
|
11
|
+
get status() { return this.currentStatus; }
|
|
12
|
+
get dispatches() { return Object.freeze([...this.dispatched]); }
|
|
13
|
+
ingest(source, text, actor) {
|
|
14
|
+
if (!source || typeof source.sourceId !== 'string' || typeof text !== 'string' || !text.trim())
|
|
15
|
+
throw new TypeError('source and text required');
|
|
16
|
+
sourceId(source.sourceId);
|
|
17
|
+
const copy = Object.freeze({ ...source });
|
|
18
|
+
if (this.entries.has(source.sourceId))
|
|
19
|
+
throw new TypeError('source messages are immutable and unique');
|
|
20
|
+
const question = /^\s*(?:would|could|should|can|is|are|what|why|how|when|where|which|who)\b|\?\s*$/.test(text);
|
|
21
|
+
const entry = question
|
|
22
|
+
? Object.freeze({ id: source.sourceId, kind: 'question', status: 'open', source: copy, text, executionAuthorized: false })
|
|
23
|
+
: Object.freeze({ id: source.sourceId, kind: source.role === 'advisor' ? 'proposal' : 'assumption', status: 'unconfirmed', source: copy, text, executionAuthorized: false });
|
|
24
|
+
void actor; // retained for call-site context; source role is authoritative for classification.
|
|
25
|
+
this.entries.set(entry.id, entry);
|
|
26
|
+
return entry;
|
|
27
|
+
}
|
|
28
|
+
get(id) { return this.entries.get(id); }
|
|
29
|
+
promote(id, actor, input) {
|
|
30
|
+
if (actor !== 'owner')
|
|
31
|
+
throw new TypeError('only owner may promote a proposal');
|
|
32
|
+
const entry = this.entries.get(id);
|
|
33
|
+
if (!entry || entry.kind === 'question')
|
|
34
|
+
throw new TypeError('entry is not promotable');
|
|
35
|
+
const req = this.registry.importOwnerRequirement({ id: input.id, text: entry.text, scope: input.scope, provenance: input.provenance });
|
|
36
|
+
this.entries.set(id, Object.freeze({ ...entry, status: 'promoted' }));
|
|
37
|
+
return req;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=ledger.js.map
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { type ClassifiedSourceMessage } from '../core/provenance.js';
|
|
2
|
+
import { type RequirementId } from '../core/ids.js';
|
|
3
|
+
export type AuthorizationScope = {
|
|
4
|
+
readonly kind: 'read' | 'write';
|
|
5
|
+
} | {
|
|
6
|
+
readonly kind: 'session';
|
|
7
|
+
readonly sessionId: string;
|
|
8
|
+
};
|
|
9
|
+
export interface RequirementProvenance {
|
|
10
|
+
readonly message: ClassifiedSourceMessage;
|
|
11
|
+
readonly observedAt: string;
|
|
12
|
+
readonly sessionId: string;
|
|
13
|
+
}
|
|
14
|
+
export interface RequirementInput {
|
|
15
|
+
readonly id: string;
|
|
16
|
+
readonly text: string;
|
|
17
|
+
readonly scope: AuthorizationScope;
|
|
18
|
+
readonly provenance: RequirementProvenance;
|
|
19
|
+
}
|
|
20
|
+
export interface Requirement {
|
|
21
|
+
readonly id: RequirementId;
|
|
22
|
+
readonly text: string;
|
|
23
|
+
readonly scope: AuthorizationScope;
|
|
24
|
+
readonly provenance: {
|
|
25
|
+
readonly sourceMessageId: string;
|
|
26
|
+
readonly observedAt: string;
|
|
27
|
+
readonly author: 'owner';
|
|
28
|
+
readonly sessionId: string;
|
|
29
|
+
};
|
|
30
|
+
readonly sessionId: string;
|
|
31
|
+
}
|
|
32
|
+
export interface ChangePreview {
|
|
33
|
+
readonly affectedRequirementIds: readonly string[];
|
|
34
|
+
readonly proposedText: string;
|
|
35
|
+
readonly applied: false;
|
|
36
|
+
}
|
|
37
|
+
export interface AuthorizationResult {
|
|
38
|
+
readonly allowed: boolean;
|
|
39
|
+
readonly reason: string | null;
|
|
40
|
+
}
|
|
41
|
+
export declare class RequirementRegistry {
|
|
42
|
+
private readonly requirements;
|
|
43
|
+
importOwnerRequirement(input: RequirementInput): Requirement;
|
|
44
|
+
get(id: string): Requirement | undefined;
|
|
45
|
+
list(): readonly Requirement[];
|
|
46
|
+
authorizeUse(id: string, requested: AuthorizationScope): AuthorizationResult;
|
|
47
|
+
previewChange(change: {
|
|
48
|
+
readonly text: string;
|
|
49
|
+
readonly scope: AuthorizationScope;
|
|
50
|
+
}): ChangePreview;
|
|
51
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { promoteRequirement } from '../core/provenance.js';
|
|
2
|
+
import { requirementId, sessionId } from '../core/ids.js';
|
|
3
|
+
const validScope = (v) => { if (!v || typeof v !== 'object')
|
|
4
|
+
return false; const s = v; return s['kind'] === 'read' || s['kind'] === 'write' || s['kind'] === 'session' && typeof s['sessionId'] === 'string' && s['sessionId'].length > 0; };
|
|
5
|
+
const validTime = (v) => Number.isFinite(Date.parse(v)) && /^\d{4}-\d\d-\d\dT/.test(v);
|
|
6
|
+
export class RequirementRegistry {
|
|
7
|
+
requirements = new Map();
|
|
8
|
+
importOwnerRequirement(input) {
|
|
9
|
+
if (!input || typeof input.id !== 'string' || typeof input.text !== 'string' || !input.text.trim() || !validScope(input.scope))
|
|
10
|
+
throw new TypeError('invalid requirement or explicit authorization scope required');
|
|
11
|
+
const p = input.provenance;
|
|
12
|
+
if (!p || !p.message || !validTime(p.observedAt) || typeof p.sessionId !== 'string')
|
|
13
|
+
throw new TypeError('requirement provenance required');
|
|
14
|
+
const msg = p.message;
|
|
15
|
+
const authenticated = promoteRequirement({ id: msg.id, origin: msg.origin, role: msg.role, text: msg.text, transportActor: msg.transportActor }, 'owner');
|
|
16
|
+
if (authenticated.id !== msg.id || msg.role !== 'owner')
|
|
17
|
+
throw new TypeError('owner provenance rejected');
|
|
18
|
+
const id = requirementId(input.id);
|
|
19
|
+
if (this.requirements.has(id))
|
|
20
|
+
throw new TypeError('requirement IDs are immutable and unique');
|
|
21
|
+
const session = sessionId(p.sessionId);
|
|
22
|
+
const scope = input.scope.kind === 'session' ? Object.freeze({ kind: 'session', sessionId: sessionId(input.scope.sessionId) }) : Object.freeze({ kind: input.scope.kind });
|
|
23
|
+
const provenance = Object.freeze({ sourceMessageId: authenticated.id, observedAt: p.observedAt, author: 'owner', sessionId: session });
|
|
24
|
+
const req = Object.freeze({ id, text: input.text.trim(), scope, provenance, sessionId: session });
|
|
25
|
+
this.requirements.set(id, req);
|
|
26
|
+
return req;
|
|
27
|
+
}
|
|
28
|
+
get(id) { return this.requirements.get(requirementId(id)); }
|
|
29
|
+
list() { return Object.freeze([...this.requirements.values()]); }
|
|
30
|
+
authorizeUse(id, requested) {
|
|
31
|
+
const req = this.get(id);
|
|
32
|
+
if (!req || !validScope(requested))
|
|
33
|
+
return Object.freeze({ allowed: false, reason: 'unknown requirement or invalid scope' });
|
|
34
|
+
const allowed = req.scope.kind === 'write' || req.scope.kind === 'read' && requested.kind === 'read' || req.scope.kind === 'session' && requested.kind === 'session' && req.scope.sessionId === requested.sessionId;
|
|
35
|
+
return Object.freeze({ allowed, reason: allowed ? null : 'requested use is outside explicit authorization scope' });
|
|
36
|
+
}
|
|
37
|
+
previewChange(change) {
|
|
38
|
+
if (!change || typeof change.text !== 'string' || !validScope(change.scope))
|
|
39
|
+
throw new TypeError('valid proposed change and scope required');
|
|
40
|
+
const affected = [...this.requirements.values()].filter(r => r.text !== change.text || JSON.stringify(r.scope) !== JSON.stringify(change.scope)).map(r => r.id);
|
|
41
|
+
return Object.freeze({ affectedRequirementIds: Object.freeze(affected), proposedText: change.text, applied: false });
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=registry.js.map
|