@knpkv/herdr-work 0.4.0 → 0.5.1
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/README.md +95 -1
- package/dist/agent-binding.d.ts +4 -0
- package/dist/agent-binding.d.ts.map +1 -0
- package/dist/agent-binding.js +26 -0
- package/dist/agent-binding.js.map +1 -0
- package/dist/errors.d.ts +141 -0
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +97 -0
- package/dist/errors.js.map +1 -1
- package/dist/index.d.ts +4 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -1
- package/dist/index.js.map +1 -1
- package/dist/internal/agent-binding-admission.d.ts +15 -0
- package/dist/internal/agent-binding-admission.d.ts.map +1 -0
- package/dist/internal/agent-binding-admission.js +92 -0
- package/dist/internal/agent-binding-admission.js.map +1 -0
- package/dist/internal/agent-binding-readback.d.ts +55 -0
- package/dist/internal/agent-binding-readback.d.ts.map +1 -0
- package/dist/internal/agent-binding-readback.js +124 -0
- package/dist/internal/agent-binding-readback.js.map +1 -0
- package/dist/internal/coordinator-authority.d.ts +62 -0
- package/dist/internal/coordinator-authority.d.ts.map +1 -0
- package/dist/internal/coordinator-authority.js +214 -0
- package/dist/internal/coordinator-authority.js.map +1 -0
- package/dist/internal/decision-handoff-migration.d.ts +126 -0
- package/dist/internal/decision-handoff-migration.d.ts.map +1 -0
- package/dist/internal/decision-handoff-migration.js +51 -0
- package/dist/internal/decision-handoff-migration.js.map +1 -0
- package/dist/internal/history-validation.d.ts +5 -0
- package/dist/internal/history-validation.d.ts.map +1 -0
- package/dist/internal/history-validation.js +33 -0
- package/dist/internal/history-validation.js.map +1 -0
- package/dist/model.d.ts +3075 -51
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js +334 -12
- package/dist/model.js.map +1 -1
- package/dist/navigation.d.ts +17 -0
- package/dist/navigation.d.ts.map +1 -0
- package/dist/navigation.js +62 -0
- package/dist/navigation.js.map +1 -0
- package/dist/projection.d.ts +644 -0
- package/dist/projection.d.ts.map +1 -1
- package/dist/projection.js +65 -30
- package/dist/projection.js.map +1 -1
- package/dist/service.d.ts +1870 -3
- package/dist/service.d.ts.map +1 -1
- package/dist/service.js +138 -5
- package/dist/service.js.map +1 -1
- package/dist/sql.d.ts +30 -0
- package/dist/sql.d.ts.map +1 -0
- package/dist/sql.js +1454 -0
- package/dist/sql.js.map +1 -0
- package/dist/store.d.ts +1068 -4
- package/dist/store.d.ts.map +1 -1
- package/dist/store.js +3275 -51
- package/dist/store.js.map +1 -1
- package/dist/view.d.ts.map +1 -1
- package/dist/view.js +154 -8
- package/dist/view.js.map +1 -1
- package/package.json +25 -13
- package/src/styles.css +91 -17
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { Schema } from "effect";
|
|
2
|
+
import { WorkStoreError } from "../errors.js";
|
|
3
|
+
import { WorkGoalCheckpoint, WorkLaneClaimed } from "../model.js";
|
|
4
|
+
import type { WorkAgentBinding as WorkAgentBindingType } from "../model.js";
|
|
5
|
+
export declare const AgentBindingLaneOperationRow: Schema.Struct<{
|
|
6
|
+
readonly goalId: Schema.String;
|
|
7
|
+
readonly laneId: Schema.String;
|
|
8
|
+
readonly operationId: Schema.String;
|
|
9
|
+
readonly phase: Schema.String;
|
|
10
|
+
readonly record: Schema.String;
|
|
11
|
+
readonly revision: Schema.Number;
|
|
12
|
+
}>;
|
|
13
|
+
export declare const AgentBindingGoalEventRow: Schema.Struct<{
|
|
14
|
+
readonly eventId: Schema.String;
|
|
15
|
+
readonly goalId: Schema.String;
|
|
16
|
+
readonly occurredAt: Schema.Number;
|
|
17
|
+
readonly record: Schema.String;
|
|
18
|
+
}>;
|
|
19
|
+
export declare const AgentBindingRow: Schema.Struct<{
|
|
20
|
+
readonly dispatchRequestId: Schema.String;
|
|
21
|
+
readonly laneId: Schema.String;
|
|
22
|
+
readonly expectedRevision: Schema.Number;
|
|
23
|
+
readonly revision: Schema.Number;
|
|
24
|
+
readonly agentId: Schema.String;
|
|
25
|
+
readonly host: Schema.String;
|
|
26
|
+
readonly record: Schema.String;
|
|
27
|
+
}>;
|
|
28
|
+
export type AgentBindingRowDecision = {
|
|
29
|
+
readonly _tag: "valid";
|
|
30
|
+
readonly binding: WorkAgentBindingType;
|
|
31
|
+
} | {
|
|
32
|
+
readonly _tag: "invalid";
|
|
33
|
+
readonly error: WorkStoreError;
|
|
34
|
+
};
|
|
35
|
+
/** Decodes a binding only when its indexed identity and expected dispatch authority agree. */
|
|
36
|
+
export declare const decodeAgentBindingRow: (row: typeof AgentBindingRow.Type, expected: {
|
|
37
|
+
readonly dispatchRequestId: string;
|
|
38
|
+
readonly laneId: string;
|
|
39
|
+
}, operation: string) => AgentBindingRowDecision;
|
|
40
|
+
export type AgentBindingGoalEventDecision = {
|
|
41
|
+
readonly _tag: "valid";
|
|
42
|
+
readonly checkpoint: WorkGoalCheckpoint;
|
|
43
|
+
} | {
|
|
44
|
+
readonly _tag: "invalid";
|
|
45
|
+
readonly error: WorkStoreError;
|
|
46
|
+
};
|
|
47
|
+
/** Decodes a checkpoint only when its indexed identity matches its durable record. */
|
|
48
|
+
export declare const decodeAgentBindingGoalEvent: (row: typeof AgentBindingGoalEventRow.Type, operation: string) => AgentBindingGoalEventDecision;
|
|
49
|
+
/** Validates a lane claim against its immutable operation-ledger replica. */
|
|
50
|
+
export declare const laneOperationReadbackError: (lane: WorkLaneClaimed, row: typeof AgentBindingLaneOperationRow.Type | undefined, operation: string) => WorkStoreError | undefined;
|
|
51
|
+
/** Validates the two immutable ledger rows committed beside an agent binding. */
|
|
52
|
+
export declare const agentBindingReadbackError: (binding: WorkAgentBindingType, laneRow: typeof AgentBindingLaneOperationRow.Type | undefined, checkpointRow: typeof AgentBindingGoalEventRow.Type | undefined, operation: string) => WorkStoreError | undefined;
|
|
53
|
+
/** Ensures an untrusted binding record still conforms before companion comparison. */
|
|
54
|
+
export declare const decodeAgentBindingRecord: (record: string) => WorkAgentBindingType;
|
|
55
|
+
//# sour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B,QACjC,OAAO,wBAAwB,CAAC,IAAI,aAC9B,MAAM,KAChB,6BAcF,CAAA;AAED,6EAA6E;AAC7E,eAAO,MAAM,0BAA0B,SAC/B,eAAe,OAChB,OAAO,4BAA4B,CAAC,IAAI,GAAG,SAAS,aAC9C,MAAM,KAChB,cAAc,GAAG,SAiBnB,CAAA;AAED,iFAAiF;AACjF,eAAO,MAAM,yBAAyB,YAC3B,oBAAoB,WACpB,OAAO,4BAA4B,CAAC,IAAI,GAAG,SAAS,iBAC9C,OAAO,wBAAwB,CAAC,IAAI,GAAG,SAAS,aACpD,MAAM,KAChB,cAAc,GAAG,SAmCnB,CAAA;AAED,sFAAsF;AACtF,eAAO,MAAM,wBAAwB,WAAY,MAAM,KAAG,oBACM,CAAA"}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { Equal, Schema } from "effect";
|
|
2
|
+
import { WorkStoreError } from "../errors.js";
|
|
3
|
+
import { WorkAgentBinding, WorkGoalCheckpoint, WorkLaneClaimed } from "../model.js";
|
|
4
|
+
export const AgentBindingLaneOperationRow = Schema.Struct({
|
|
5
|
+
goalId: Schema.String,
|
|
6
|
+
laneId: Schema.String,
|
|
7
|
+
operationId: Schema.String,
|
|
8
|
+
phase: Schema.String,
|
|
9
|
+
record: Schema.String,
|
|
10
|
+
revision: Schema.Number
|
|
11
|
+
});
|
|
12
|
+
export const AgentBindingGoalEventRow = Schema.Struct({
|
|
13
|
+
eventId: Schema.String,
|
|
14
|
+
goalId: Schema.String,
|
|
15
|
+
occurredAt: Schema.Number,
|
|
16
|
+
record: Schema.String
|
|
17
|
+
});
|
|
18
|
+
export const AgentBindingRow = Schema.Struct({
|
|
19
|
+
dispatchRequestId: Schema.String,
|
|
20
|
+
laneId: Schema.String,
|
|
21
|
+
expectedRevision: Schema.Number,
|
|
22
|
+
revision: Schema.Number,
|
|
23
|
+
agentId: Schema.String,
|
|
24
|
+
host: Schema.String,
|
|
25
|
+
record: Schema.String
|
|
26
|
+
});
|
|
27
|
+
/** Decodes a binding only when its indexed identity and expected dispatch authority agree. */
|
|
28
|
+
export const decodeAgentBindingRow = (row, expected, operation) => {
|
|
29
|
+
try {
|
|
30
|
+
const binding = Schema.decodeUnknownSync(WorkAgentBinding)(JSON.parse(row.record));
|
|
31
|
+
return row.dispatchRequestId === expected.dispatchRequestId &&
|
|
32
|
+
row.laneId === expected.laneId &&
|
|
33
|
+
row.dispatchRequestId === binding.request.dispatchRequestId &&
|
|
34
|
+
row.laneId === binding.request.laneId &&
|
|
35
|
+
row.expectedRevision === binding.request.expectedRevision &&
|
|
36
|
+
row.revision === binding.lane.revision &&
|
|
37
|
+
row.agentId === binding.request.worker.agentId &&
|
|
38
|
+
row.host.toLowerCase() === binding.request.worker.host.toLowerCase()
|
|
39
|
+
? { _tag: "valid", binding }
|
|
40
|
+
: {
|
|
41
|
+
_tag: "invalid",
|
|
42
|
+
error: new WorkStoreError({ cause: { binding, expected, row }, operation: `${operation}.identity-mismatch` })
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
catch (cause) {
|
|
46
|
+
return { _tag: "invalid", error: new WorkStoreError({ cause, operation: `${operation}.decode` }) };
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
/** Decodes a checkpoint only when its indexed identity matches its durable record. */
|
|
50
|
+
export const decodeAgentBindingGoalEvent = (row, operation) => {
|
|
51
|
+
try {
|
|
52
|
+
const checkpoint = Schema.decodeUnknownSync(WorkGoalCheckpoint)(JSON.parse(row.record));
|
|
53
|
+
return row.eventId === checkpoint.eventId &&
|
|
54
|
+
row.goalId === checkpoint.goal.id &&
|
|
55
|
+
row.occurredAt === checkpoint.occurredAt
|
|
56
|
+
? { _tag: "valid", checkpoint }
|
|
57
|
+
: {
|
|
58
|
+
_tag: "invalid",
|
|
59
|
+
error: new WorkStoreError({ cause: { checkpoint, row }, operation: `${operation}.identity-mismatch` })
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
catch (cause) {
|
|
63
|
+
return { _tag: "invalid", error: new WorkStoreError({ cause, operation: `${operation}.decode` }) };
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
/** Validates a lane claim against its immutable operation-ledger replica. */
|
|
67
|
+
export const laneOperationReadbackError = (lane, row, operation) => {
|
|
68
|
+
if (row === undefined) {
|
|
69
|
+
return new WorkStoreError({ cause: { lane, laneOperation: "missing" }, operation });
|
|
70
|
+
}
|
|
71
|
+
try {
|
|
72
|
+
const replica = Schema.decodeUnknownSync(WorkLaneClaimed)(JSON.parse(row.record));
|
|
73
|
+
return row.operationId === replica.operationId &&
|
|
74
|
+
row.laneId === replica.laneId &&
|
|
75
|
+
row.goalId === replica.goalId &&
|
|
76
|
+
row.phase === replica.phase &&
|
|
77
|
+
row.revision === replica.revision &&
|
|
78
|
+
Equal.equals(replica, lane)
|
|
79
|
+
? undefined
|
|
80
|
+
: new WorkStoreError({ cause: { lane, replica, row }, operation });
|
|
81
|
+
}
|
|
82
|
+
catch (cause) {
|
|
83
|
+
return new WorkStoreError({ cause, operation });
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
/** Validates the two immutable ledger rows committed beside an agent binding. */
|
|
87
|
+
export const agentBindingReadbackError = (binding, laneRow, checkpointRow, operation) => {
|
|
88
|
+
if (laneRow === undefined || checkpointRow === undefined) {
|
|
89
|
+
return new WorkStoreError({
|
|
90
|
+
cause: {
|
|
91
|
+
binding: binding.request.dispatchRequestId,
|
|
92
|
+
checkpoint: checkpointRow === undefined ? "missing" : "present",
|
|
93
|
+
laneOperation: laneRow === undefined ? "missing" : "present"
|
|
94
|
+
},
|
|
95
|
+
operation: `${operation}.missing-companion`
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
try {
|
|
99
|
+
const lane = Schema.decodeUnknownSync(WorkLaneClaimed)(JSON.parse(laneRow.record));
|
|
100
|
+
const checkpoint = Schema.decodeUnknownSync(WorkGoalCheckpoint)(JSON.parse(checkpointRow.record));
|
|
101
|
+
if (laneRow.operationId !== lane.operationId ||
|
|
102
|
+
laneRow.laneId !== lane.laneId ||
|
|
103
|
+
laneRow.goalId !== lane.goalId ||
|
|
104
|
+
laneRow.phase !== lane.phase ||
|
|
105
|
+
laneRow.revision !== lane.revision ||
|
|
106
|
+
checkpointRow.eventId !== checkpoint.eventId ||
|
|
107
|
+
checkpointRow.goalId !== checkpoint.goal.id ||
|
|
108
|
+
checkpointRow.occurredAt !== checkpoint.occurredAt ||
|
|
109
|
+
!Equal.equals(lane, binding.lane) ||
|
|
110
|
+
!Equal.equals(checkpoint, binding.checkpoint)) {
|
|
111
|
+
return new WorkStoreError({
|
|
112
|
+
cause: { binding, checkpoint, checkpointRow, lane, laneRow },
|
|
113
|
+
operation: `${operation}.companion-identity-mismatch`
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
return undefined;
|
|
117
|
+
}
|
|
118
|
+
catch (cause) {
|
|
119
|
+
return new WorkStoreError({ cause, operation: `${operation}.decode-companion` });
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
/** Ensures an untrusted binding record still conforms before companion comparison. */
|
|
123
|
+
export const decodeAgentBindingRecord = (record) => Schema.decodeUnknownSync(WorkAgentBinding)(JSON.parse(record));
|
|
124
|
+
//# sourceMappingURL=agent-binding-readback.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent-binding-readback.js","sourceRoot":"","sources":["../../src/internal/agent-binding-readback.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AACtC,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAA;AAC7C,OAAO,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAGnF,MAAM,CAAC,MAAM,4BAA4B,GAAG,MAAM,CAAC,MAAM,CAAC;IACxD,MAAM,EAAE,MAAM,CAAC,MAAM;IACrB,MAAM,EAAE,MAAM,CAAC,MAAM;IACrB,WAA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,IAAI,CAAC,QAAQ;YAClC,aAAa,CAAC,OAAO,KAAK,UAAU,CAAC,OAAO;YAC5C,aAAa,CAAC,MAAM,KAAK,UAAU,CAAC,IAAI,CAAC,EAAE;YAC3C,aAAa,CAAC,UAAU,KAAK,UAAU,CAAC,UAAU;YAClD,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,IAAI,CAAC;YACjC,CAAC,KAAK,CAAC,MAAM,CAAC,UAAU,EAAE,OAAO,CAAC,UAAU,CAAC,EAC7C,CAAC;YACD,OAAO,IAAI,cAAc,CAAC;gBACxB,KAAK,EAAE,EAAE,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,IAAI,EAAE,OAAO,EAAE;gBAC5D,SAAS,EAAE,GAAG,SAAS,8BAA8B;aACtD,CAAC,CAAA;QACJ,CAAC;QACD,OAAO,SAAS,CAAA;IAClB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,IAAI,cAAc,CAAC,EAAE,KAAK,EAAE,SAAS,EAAE,GAAG,SAAS,mBAAmB,EAAE,CAAC,CAAA;IAClF,CAAC;AACH,CAAC,CAAA;AAED,sFAAsF;AACtF,MAAM,CAAC,MAAM,wBAAwB,GAAG,CAAC,MAAc,EAAwB,EAAE,CAC/E,MAAM,CAAC,iBAAiB,CAAC,gBAAgB,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAA"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { Schema } from "effect";
|
|
2
|
+
export declare const CoordinatorCommandRow: Schema.Struct<{
|
|
3
|
+
readonly activityIdempotencyKey: Schema.String;
|
|
4
|
+
readonly command: Schema.String;
|
|
5
|
+
}>;
|
|
6
|
+
export type CoordinatorCommandRow = typeof CoordinatorCommandRow.Type;
|
|
7
|
+
export declare const CoordinatorLifecycleDispatchRow: Schema.Struct<{
|
|
8
|
+
readonly activityIdempotencyKey: Schema.String;
|
|
9
|
+
readonly acceptedAt: Schema.Number;
|
|
10
|
+
readonly command: Schema.String;
|
|
11
|
+
readonly dispatchRequestId: Schema.String;
|
|
12
|
+
readonly status: Schema.Literals<readonly ["accepted", "queued", "running", "settled", "delivery_failed", "task_failed"]>;
|
|
13
|
+
}>;
|
|
14
|
+
export type CoordinatorLifecycleDispatchRow = typeof CoordinatorLifecycleDispatchRow.Type;
|
|
15
|
+
export declare const CoordinatorLifecycleEventRow: Schema.Struct<{
|
|
16
|
+
readonly activityIdempotencyKey: Schema.String;
|
|
17
|
+
readonly detail: Schema.NullOr<Schema.String>;
|
|
18
|
+
readonly dispatchRequestId: Schema.String;
|
|
19
|
+
readonly occurredAt: Schema.Number;
|
|
20
|
+
readonly result: Schema.NullOr<Schema.String>;
|
|
21
|
+
readonly sequence: Schema.Number;
|
|
22
|
+
readonly type: Schema.Literals<readonly ["accepted", "queued", "running", "settled", "delivery_failed", "task_failed"]>;
|
|
23
|
+
}>;
|
|
24
|
+
export type CoordinatorLifecycleEventRow = typeof CoordinatorLifecycleEventRow.Type;
|
|
25
|
+
declare const CoordinatorRoute: Schema.Union<readonly [Schema.Struct<{
|
|
26
|
+
readonly protocol: Schema.Literal<"hostd.coordinator.route.v1">;
|
|
27
|
+
readonly action: Schema.Literal<"dispatch">;
|
|
28
|
+
readonly model: Schema.Literal<"gpt-5.6-luna">;
|
|
29
|
+
readonly reasoningEffort: Schema.Literals<readonly ["low", "medium"]>;
|
|
30
|
+
readonly reason: Schema.String;
|
|
31
|
+
readonly linkedRequestId: Schema.Null;
|
|
32
|
+
}>, Schema.Struct<{
|
|
33
|
+
readonly protocol: Schema.Literal<"hostd.coordinator.route.v1">;
|
|
34
|
+
readonly action: Schema.Literal<"dispatch">;
|
|
35
|
+
readonly model: Schema.Literal<"gpt-5.6-sol">;
|
|
36
|
+
readonly reasoningEffort: Schema.Literal<"high">;
|
|
37
|
+
readonly reason: Schema.String;
|
|
38
|
+
readonly linkedRequestId: Schema.NullOr<Schema.String>;
|
|
39
|
+
}>]>;
|
|
40
|
+
type CoordinatorRoute = typeof CoordinatorRoute.Type;
|
|
41
|
+
export declare const CoordinatorRouteDiscriminatorRow: Schema.Struct<{
|
|
42
|
+
readonly isRouted: Schema.Literals<readonly [0, 1]>;
|
|
43
|
+
}>;
|
|
44
|
+
export type CoordinatorRouteDiscriminatorRow = typeof CoordinatorRouteDiscriminatorRow.Type;
|
|
45
|
+
export declare const CoordinatorRouteStorageAuthority: Schema.Union<readonly [Schema.TaggedStruct<"legacy_without_routed_discriminator", {}>, Schema.TaggedStruct<"routed_discriminator", {
|
|
46
|
+
readonly isRouted: Schema.Literals<readonly [0, 1]>;
|
|
47
|
+
}>]>;
|
|
48
|
+
export type CoordinatorRouteStorageAuthority = typeof CoordinatorRouteStorageAuthority.Type;
|
|
49
|
+
/** Validates the bounded coordinator history that authorizes restoring a persisted Work revision. */
|
|
50
|
+
export declare const requireCoordinatorLifecycleAuthority: (dispatchRows: ReadonlyArray<CoordinatorLifecycleDispatchRow>, eventRows: ReadonlyArray<CoordinatorLifecycleEventRow>, expectedRunningAt: number, operation: string) => void;
|
|
51
|
+
/** Returns the single persisted running timestamp, or null when no worker was activated. */
|
|
52
|
+
export declare const coordinatorLifecycleRunningAt: (dispatchRows: ReadonlyArray<CoordinatorLifecycleDispatchRow>, eventRows: ReadonlyArray<CoordinatorLifecycleEventRow>, operation: string) => number | null;
|
|
53
|
+
/** Reports whether a persisted routed dispatch must carry a Work link. */
|
|
54
|
+
export declare const coordinatorRouteRequiresWorkLink: (routeText: string, storageAuthority: CoordinatorRouteStorageAuthority, operation: string) => boolean;
|
|
55
|
+
/** Validates the persisted command, route, and Work-link form as one durable dispatch binding. */
|
|
56
|
+
export declare const requireCoordinatorRouteBinding: (commandText: string, expectedActivityIdempotencyKey: string, routeText: string, hasWorkLink: boolean, storageAuthority: CoordinatorRouteStorageAuthority, operation: string) => CoordinatorRoute;
|
|
57
|
+
/** Validates persisted route authority before a Work-link replica is upgraded. */
|
|
58
|
+
export declare const requireCoordinatorRouteAuthority: (commandText: string, expectedActivityIdempotencyKey: string, routeText: string, lineage: ReadonlyArray<string>, storageAuthority: CoordinatorRouteStorageAuthority, operation: string) => CoordinatorRoute;
|
|
59
|
+
/** Validates the exact failed Luna dispatch that authorizes a linked Sol route. */
|
|
60
|
+
export declare const requireCoordinatorFailedLunaAuthority: (dispatchRows: ReadonlyArray<CoordinatorLifecycleDispatchRow>, eventRows: ReadonlyArray<CoordinatorLifecycleEventRow>, routeText: string, storageAuthority: CoordinatorRouteStorageAuthority, operation: string) => void;
|
|
61
|
+
export {};
|
|
62
|
+
//# sourceMappingURL=coordinator-authority.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"coordinator-authority.d.ts","sourceRoot":"","sources":["../../src/internal/coordinator-authority.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AAyC/B,eAAO,MAAM,qBAAqB;;;EAGhC,CAAA;AACF,MAAM,MAAM,qBAAqB,GAAG,OAAO,qBAAqB,CAAC,IAAI,CAAA;AAErE,eAAO,MAAM,+BAA+B;;;;;;EAM1C,CAAA;AACF,MAAM,MAAM,+BAA+B,GAAG,OAAO,+BAA+B,CAAC,IAAI,CAAA;AAEzF,eAAO,MAAM,4BAA4B;;;;;;;;EAQvC,CAAA;AACF,MAAM,MAAM,4BAA4B,GAAG,OAAO,4BAA4B,CAAC,IAAI,CAAA;AAyBnF,QAAA,MAAM,gBAAgB;;;;;;;;;;;;;;IAiBpB,CAAA;AACF,KAAK,gBAAgB,GAAG,OAAO,gBAAgB,CAAC,IAAI,CAAA;AAEpD,eAAO,MAAM,gCAAgC;;EAE3C,CAAA;AACF,MAAM,MAAM,gCAAgC,GAAG,OAAO,gCAAgC,CAAC,IAAI,CAAA;AAE3F,eAAO,MAAM,gCAAgC;;IAK3C,CAAA;AACF,MAAM,MAAM,gCAAgC,GAAG,OAAO,gCAAgC,CAAC,IAAI,CAAA;AA0D3F,qGAAqG;AACrG,eAAO,MAAM,oCAAoC,iBACjC,aAAa,CAAC,+BAA+B,CAAC,aACjD,aAAa,CAAC,4BAA4B,CAAC,qBACnC,MAAM,aACd,MAAM,KAChB,IAOF,CAAA;AAED,4FAA4F;AAC5F,eAAO,MAAM,6BAA6B,iBAC1B,aAAa,CAAC,+BAA+B,CAAC,aACjD,aAAa,CAAC,4BAA4B,CAAC,aAC3C,MAAM,KAChB,MAAM,GAAG,IAOX,CAAA;AAoBD,0EAA0E;AAC1E,eAAO,MAAM,gCAAgC,cAChC,MAAM,oBACC,gCAAgC,aACvC,MAAM,KAChB,OAA0G,CAAA;AAE7G,kGAAkG;AAClG,eAAO,MAAM,8BAA8B,gBAC5B,MAAM,kCACa,MAAM,aAC3B,MAAM,eACJ,OAAO,oBACF,gCAAgC,aACvC,MAAM,KAChB,gBAqBF,CAAA;AAED,kFAAkF;AAClF,eAAO,MAAM,gCAAgC,gBAC9B,MAAM,kCACa,MAAM,aAC3B,MAAM,WACR,aAAa,CAAC,MAAM,CAAC,oBACZ,gCAAgC,aACvC,MAAM,KAChB,gBAaF,CAAA;AAED,mFAAmF;AACnF,eAAO,MAAM,qCAAqC,iBAClC,aAAa,CAAC,+BAA+B,CAAC,aACjD,aAAa,CAAC,4BAA4B,CAAC,aAC3C,MAAM,oBACC,gCAAgC,aACvC,MAAM,KAChB,IAYF,CAAA"}
|
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
import { JobActor, JobIdentifier, JobPayload } from "@knpkv/herdr-fleet/model";
|
|
2
|
+
import { fleetResponseBodyMaxBytes } from "@knpkv/herdr-fleet/response";
|
|
3
|
+
import { Schema } from "effect";
|
|
4
|
+
import { WorkStoreError } from "../errors.js";
|
|
5
|
+
const Identifier = Schema.String.check(Schema.isNonEmpty(), Schema.isMaxLength(256), Schema.isPattern(/^(?:[^\uD800-\uDFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF])*$/));
|
|
6
|
+
const UnicodeScalarText = Schema.String.check(Schema.isPattern(/^(?:[^\uD800-\uDFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF])*$/));
|
|
7
|
+
const utf8 = new TextEncoder();
|
|
8
|
+
const EventText = UnicodeScalarText.check(Schema.isMaxLength(fleetResponseBodyMaxBytes), Schema.makeFilter((value) => utf8.encode(value).byteLength <= fleetResponseBodyMaxBytes, { expected: `UTF-8 text no larger than ${fleetResponseBodyMaxBytes} bytes` }));
|
|
9
|
+
const Timestamp = Schema.Number.check(Schema.isInt(), Schema.isBetween({ minimum: 0, maximum: 8_640_000_000_000_000 }));
|
|
10
|
+
const Sequence = Schema.Number.check(Schema.isInt(), Schema.isBetween({ minimum: 0, maximum: 1_000_000 }));
|
|
11
|
+
const Status = Schema.Literals([
|
|
12
|
+
"accepted",
|
|
13
|
+
"queued",
|
|
14
|
+
"running",
|
|
15
|
+
"settled",
|
|
16
|
+
"delivery_failed",
|
|
17
|
+
"task_failed"
|
|
18
|
+
]);
|
|
19
|
+
const CoordinatorCommand = Schema.Struct({
|
|
20
|
+
kind: Schema.Literal("fleet.job"),
|
|
21
|
+
actor: JobActor,
|
|
22
|
+
activityIdempotencyKey: Identifier,
|
|
23
|
+
payload: JobPayload
|
|
24
|
+
});
|
|
25
|
+
export const CoordinatorCommandRow = Schema.Struct({
|
|
26
|
+
activityIdempotencyKey: Identifier,
|
|
27
|
+
command: Schema.String
|
|
28
|
+
});
|
|
29
|
+
export const CoordinatorLifecycleDispatchRow = Schema.Struct({
|
|
30
|
+
activityIdempotencyKey: Identifier,
|
|
31
|
+
acceptedAt: Timestamp,
|
|
32
|
+
command: Schema.String,
|
|
33
|
+
dispatchRequestId: JobIdentifier,
|
|
34
|
+
status: Status
|
|
35
|
+
});
|
|
36
|
+
export const CoordinatorLifecycleEventRow = Schema.Struct({
|
|
37
|
+
activityIdempotencyKey: Identifier,
|
|
38
|
+
detail: Schema.NullOr(Schema.String),
|
|
39
|
+
dispatchRequestId: JobIdentifier,
|
|
40
|
+
occurredAt: Timestamp,
|
|
41
|
+
result: Schema.NullOr(Schema.String),
|
|
42
|
+
sequence: Sequence,
|
|
43
|
+
type: Status
|
|
44
|
+
});
|
|
45
|
+
const eventFields = {
|
|
46
|
+
activityIdempotencyKey: Identifier,
|
|
47
|
+
dispatchRequestId: JobIdentifier,
|
|
48
|
+
occurredAt: Timestamp,
|
|
49
|
+
sequence: Sequence
|
|
50
|
+
};
|
|
51
|
+
const CoordinatorEvent = Schema.Union([
|
|
52
|
+
Schema.Struct({
|
|
53
|
+
...eventFields,
|
|
54
|
+
type: Schema.Literals(["accepted", "queued", "running"]),
|
|
55
|
+
detail: Schema.Null,
|
|
56
|
+
result: Schema.Null
|
|
57
|
+
}),
|
|
58
|
+
Schema.Struct({
|
|
59
|
+
...eventFields,
|
|
60
|
+
type: Schema.Literals(["delivery_failed", "task_failed"]),
|
|
61
|
+
detail: EventText,
|
|
62
|
+
result: Schema.Null
|
|
63
|
+
}),
|
|
64
|
+
Schema.Struct({ ...eventFields, type: Schema.Literal("settled"), detail: Schema.Null, result: EventText })
|
|
65
|
+
]);
|
|
66
|
+
const RouteReason = EventText.check(Schema.isNonEmpty());
|
|
67
|
+
const CoordinatorRoute = Schema.Union([
|
|
68
|
+
Schema.Struct({
|
|
69
|
+
protocol: Schema.Literal("hostd.coordinator.route.v1"),
|
|
70
|
+
action: Schema.Literal("dispatch"),
|
|
71
|
+
model: Schema.Literal("gpt-5.6-luna"),
|
|
72
|
+
reasoningEffort: Schema.Literals(["low", "medium"]),
|
|
73
|
+
reason: RouteReason,
|
|
74
|
+
linkedRequestId: Schema.Null
|
|
75
|
+
}),
|
|
76
|
+
Schema.Struct({
|
|
77
|
+
protocol: Schema.Literal("hostd.coordinator.route.v1"),
|
|
78
|
+
action: Schema.Literal("dispatch"),
|
|
79
|
+
model: Schema.Literal("gpt-5.6-sol"),
|
|
80
|
+
reasoningEffort: Schema.Literal("high"),
|
|
81
|
+
reason: RouteReason,
|
|
82
|
+
linkedRequestId: Schema.NullOr(JobIdentifier)
|
|
83
|
+
})
|
|
84
|
+
]);
|
|
85
|
+
export const CoordinatorRouteDiscriminatorRow = Schema.Struct({
|
|
86
|
+
isRouted: Schema.Literals([0, 1])
|
|
87
|
+
});
|
|
88
|
+
export const CoordinatorRouteStorageAuthority = Schema.Union([
|
|
89
|
+
Schema.TaggedStruct("legacy_without_routed_discriminator", {}),
|
|
90
|
+
Schema.TaggedStruct("routed_discriminator", {
|
|
91
|
+
isRouted: Schema.Literals([0, 1])
|
|
92
|
+
})
|
|
93
|
+
]);
|
|
94
|
+
const validTransition = (from, to) => (from === "accepted" && to === "queued") ||
|
|
95
|
+
(from === "queued" && (to === "running" || to === "delivery_failed")) ||
|
|
96
|
+
(from === "running" && (to === "settled" || to === "delivery_failed" || to === "task_failed"));
|
|
97
|
+
const decodeCoordinatorLifecycleAuthority = (dispatchRows, eventRows, operation) => {
|
|
98
|
+
try {
|
|
99
|
+
const dispatch = dispatchRows[0];
|
|
100
|
+
if (dispatchRows.length !== 1 || dispatch === undefined) {
|
|
101
|
+
throw new WorkStoreError({ cause: { dispatchRows }, operation });
|
|
102
|
+
}
|
|
103
|
+
const command = Schema.decodeUnknownSync(CoordinatorCommand)(JSON.parse(dispatch.command));
|
|
104
|
+
const events = eventRows.map((row) => Schema.decodeUnknownSync(CoordinatorEvent)(row));
|
|
105
|
+
const first = events[0];
|
|
106
|
+
if (first === undefined || first.sequence !== 0 || first.type !== "accepted" ||
|
|
107
|
+
first.occurredAt !== dispatch.acceptedAt) {
|
|
108
|
+
throw new WorkStoreError({ cause: { dispatch, first }, operation });
|
|
109
|
+
}
|
|
110
|
+
let previousType = first.type;
|
|
111
|
+
let previousOccurredAt = first.occurredAt;
|
|
112
|
+
for (const [index, event] of events.entries()) {
|
|
113
|
+
if (event.dispatchRequestId !== dispatch.dispatchRequestId ||
|
|
114
|
+
event.activityIdempotencyKey !== dispatch.activityIdempotencyKey ||
|
|
115
|
+
event.activityIdempotencyKey !== command.activityIdempotencyKey ||
|
|
116
|
+
event.sequence !== index || event.occurredAt < previousOccurredAt ||
|
|
117
|
+
(index > 0 && !validTransition(previousType, event.type))) {
|
|
118
|
+
throw new WorkStoreError({ cause: { dispatch, event, index, previousType }, operation });
|
|
119
|
+
}
|
|
120
|
+
previousType = event.type;
|
|
121
|
+
previousOccurredAt = event.occurredAt;
|
|
122
|
+
}
|
|
123
|
+
const last = events.at(-1);
|
|
124
|
+
if (last === undefined || last.type !== dispatch.status) {
|
|
125
|
+
throw new WorkStoreError({ cause: { dispatch, events }, operation });
|
|
126
|
+
}
|
|
127
|
+
return { command, dispatch, events };
|
|
128
|
+
}
|
|
129
|
+
catch (cause) {
|
|
130
|
+
if (Schema.is(WorkStoreError)(cause))
|
|
131
|
+
throw cause;
|
|
132
|
+
throw new WorkStoreError({ cause, operation });
|
|
133
|
+
}
|
|
134
|
+
};
|
|
135
|
+
/** Validates the bounded coordinator history that authorizes restoring a persisted Work revision. */
|
|
136
|
+
export const requireCoordinatorLifecycleAuthority = (dispatchRows, eventRows, expectedRunningAt, operation) => {
|
|
137
|
+
const authority = decodeCoordinatorLifecycleAuthority(dispatchRows, eventRows, operation);
|
|
138
|
+
const runningAtMatches = authority.events.filter((event) => event.type === "running" && event.occurredAt === expectedRunningAt).length;
|
|
139
|
+
if (runningAtMatches !== 1) {
|
|
140
|
+
throw new WorkStoreError({ cause: { ...authority, expectedRunningAt }, operation });
|
|
141
|
+
}
|
|
142
|
+
};
|
|
143
|
+
/** Returns the single persisted running timestamp, or null when no worker was activated. */
|
|
144
|
+
export const coordinatorLifecycleRunningAt = (dispatchRows, eventRows, operation) => {
|
|
145
|
+
const authority = decodeCoordinatorLifecycleAuthority(dispatchRows, eventRows, operation);
|
|
146
|
+
const running = authority.events.filter((event) => event.type === "running");
|
|
147
|
+
if (running.length > 1) {
|
|
148
|
+
throw new WorkStoreError({ cause: { ...authority, running }, operation });
|
|
149
|
+
}
|
|
150
|
+
return running[0]?.occurredAt ?? null;
|
|
151
|
+
};
|
|
152
|
+
const decodeCoordinatorRouteAuthority = (routeText, storageAuthority, operation) => {
|
|
153
|
+
try {
|
|
154
|
+
const authority = Schema.decodeUnknownSync(CoordinatorRouteStorageAuthority)(storageAuthority);
|
|
155
|
+
const route = Schema.decodeUnknownSync(CoordinatorRoute)(JSON.parse(routeText));
|
|
156
|
+
if (authority._tag === "routed_discriminator" && authority.isRouted !== 1) {
|
|
157
|
+
throw new WorkStoreError({ cause: { authority, route }, operation });
|
|
158
|
+
}
|
|
159
|
+
return route;
|
|
160
|
+
}
|
|
161
|
+
catch (cause) {
|
|
162
|
+
if (Schema.is(WorkStoreError)(cause))
|
|
163
|
+
throw cause;
|
|
164
|
+
throw new WorkStoreError({ cause, operation });
|
|
165
|
+
}
|
|
166
|
+
};
|
|
167
|
+
/** Reports whether a persisted routed dispatch must carry a Work link. */
|
|
168
|
+
export const coordinatorRouteRequiresWorkLink = (routeText, storageAuthority, operation) => decodeCoordinatorRouteAuthority(routeText, storageAuthority, operation).model === "gpt-5.6-sol";
|
|
169
|
+
/** Validates the persisted command, route, and Work-link form as one durable dispatch binding. */
|
|
170
|
+
export const requireCoordinatorRouteBinding = (commandText, expectedActivityIdempotencyKey, routeText, hasWorkLink, storageAuthority, operation) => {
|
|
171
|
+
const route = decodeCoordinatorRouteAuthority(routeText, storageAuthority, operation);
|
|
172
|
+
try {
|
|
173
|
+
const command = Schema.decodeUnknownSync(CoordinatorCommand)(JSON.parse(commandText));
|
|
174
|
+
const validBinding = command.activityIdempotencyKey === expectedActivityIdempotencyKey &&
|
|
175
|
+
command.payload.kind === "agent.delegate" &&
|
|
176
|
+
(route.model === "gpt-5.6-luna"
|
|
177
|
+
? !hasWorkLink &&
|
|
178
|
+
((command.payload.mode === "consult" && route.reasoningEffort === "medium") ||
|
|
179
|
+
(command.payload.mode === "transition_summary" && route.reasoningEffort === "low"))
|
|
180
|
+
: hasWorkLink &&
|
|
181
|
+
(command.payload.mode === "review" || command.payload.mode === "work") &&
|
|
182
|
+
command.payload.channel === undefined);
|
|
183
|
+
if (!validBinding) {
|
|
184
|
+
throw new WorkStoreError({ cause: { command, hasWorkLink, route }, operation });
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
catch (cause) {
|
|
188
|
+
if (Schema.is(WorkStoreError)(cause))
|
|
189
|
+
throw cause;
|
|
190
|
+
throw new WorkStoreError({ cause, operation });
|
|
191
|
+
}
|
|
192
|
+
return route;
|
|
193
|
+
};
|
|
194
|
+
/** Validates persisted route authority before a Work-link replica is upgraded. */
|
|
195
|
+
export const requireCoordinatorRouteAuthority = (commandText, expectedActivityIdempotencyKey, routeText, lineage, storageAuthority, operation) => {
|
|
196
|
+
const route = requireCoordinatorRouteBinding(commandText, expectedActivityIdempotencyKey, routeText, true, storageAuthority, operation);
|
|
197
|
+
if (route.linkedRequestId !== null && !lineage.includes(route.linkedRequestId)) {
|
|
198
|
+
throw new WorkStoreError({ cause: { lineage, route }, operation });
|
|
199
|
+
}
|
|
200
|
+
return route;
|
|
201
|
+
};
|
|
202
|
+
/** Validates the exact failed Luna dispatch that authorizes a linked Sol route. */
|
|
203
|
+
export const requireCoordinatorFailedLunaAuthority = (dispatchRows, eventRows, routeText, storageAuthority, operation) => {
|
|
204
|
+
const authority = decodeCoordinatorLifecycleAuthority(dispatchRows, eventRows, operation);
|
|
205
|
+
const route = decodeCoordinatorRouteAuthority(routeText, storageAuthority, operation);
|
|
206
|
+
if (route.model !== "gpt-5.6-luna" ||
|
|
207
|
+
authority.command.payload.kind !== "agent.delegate" ||
|
|
208
|
+
(route.reasoningEffort === "medium" && authority.command.payload.mode !== "consult") ||
|
|
209
|
+
(route.reasoningEffort === "low" && authority.command.payload.mode !== "transition_summary") ||
|
|
210
|
+
(authority.dispatch.status !== "delivery_failed" && authority.dispatch.status !== "task_failed")) {
|
|
211
|
+
throw new WorkStoreError({ cause: { ...authority, route }, operation });
|
|
212
|
+
}
|
|
213
|
+
};
|
|
214
|
+
//# sourceMappingURL=coordinator-authority.js.map
|
|
@@ -0,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O,EAAE,KAAK,EAAE,EAAE,SAAS,EAAE,CAAC,CAAA;IACpE,CAAC;IACD,OAAO,KAAK,CAAA;AACd,CAAC,CAAA;AAED,mFAAmF;AACnF,MAAM,CAAC,MAAM,qCAAqC,GAAG,CACnD,YAA4D,EAC5D,SAAsD,EACtD,SAAiB,EACjB,gBAAkD,EAClD,SAAiB,EACX,EAAE;IACR,MAAM,SAAS,GAAG,mCAAmC,CAAC,YAAY,EAAE,SAAS,EAAE,SAAS,CAAC,CAAA;IACzF,MAAM,KAAK,GAAG,+BAA+B,CAAC,SAAS,EAAE,gBAAgB,EAAE,SAAS,CAAC,CAAA;IACrF,IACE,KAAK,CAAC,KAAK,KAAK,cAAc;QAC9B,SAAS,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,KAAK,gBAAgB;QACnD,CAAC,KAAK,CAAC,eAAe,KAAK,QAAQ,IAAI,SAAS,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,KAAK,SAAS,CAAC;QACpF,CAAC,KAAK,CAAC,eAAe,KAAK,KAAK,IAAI,SAAS,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,KAAK,oBAAoB,CAAC;QAC5F,CAAC,SAAS,CAAC,QAAQ,CAAC,MAAM,KAAK,iBAAiB,IAAI,SAAS,CAAC,QAAQ,CAAC,MAAM,KAAK,aAAa,CAAC,EAChG,CAAC;QACD,MAAM,IAAI,cAAc,CAAC,EAAE,KAAK,EAAE,EAAE,GAAG,SAAS,EAAE,KAAK,EAAE,EAAE,SAAS,EAAE,CAAC,CAAA;IACzE,CAAC;AACH,CAAC,CAAA"}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import { Schema } from "effect";
|
|
2
|
+
import { type WorkDecisionHandoff as WorkDecisionHandoffType } from "../model.js";
|
|
3
|
+
export declare const PreviousWorkDecisionHandoff: Schema.Struct<{
|
|
4
|
+
readonly version: Schema.Literal<"herdr.work.decision.v1">;
|
|
5
|
+
readonly id: Schema.String;
|
|
6
|
+
readonly sessionId: Schema.String;
|
|
7
|
+
readonly laneId: Schema.String;
|
|
8
|
+
readonly goalId: Schema.String;
|
|
9
|
+
readonly decision: Schema.Literals<readonly ["continue", "blocked", "handoff", "complete"]>;
|
|
10
|
+
readonly summary: Schema.String;
|
|
11
|
+
readonly owner: Schema.Struct<{
|
|
12
|
+
readonly id: Schema.String;
|
|
13
|
+
readonly name: Schema.String;
|
|
14
|
+
}>;
|
|
15
|
+
readonly dispatchIds: Schema.$Array<Schema.String>;
|
|
16
|
+
readonly blockers: Schema.$Array<Schema.Struct<{
|
|
17
|
+
readonly id: Schema.String;
|
|
18
|
+
readonly detail: Schema.String;
|
|
19
|
+
}>>;
|
|
20
|
+
readonly evidenceRefs: Schema.$Array<Schema.Struct<{
|
|
21
|
+
readonly id: Schema.String;
|
|
22
|
+
readonly kind: Schema.Literals<readonly ["commit", "test", "review", "document"]>;
|
|
23
|
+
readonly reference: Schema.String;
|
|
24
|
+
}>>;
|
|
25
|
+
readonly occurredAt: Schema.Number;
|
|
26
|
+
}>;
|
|
27
|
+
type PreviousWorkDecisionHandoff = typeof PreviousWorkDecisionHandoff.Type;
|
|
28
|
+
type PersistedDecisionHandoffJson = typeof Schema.Json.Type;
|
|
29
|
+
type PreviousDecisionHandoffDecodeResult = {
|
|
30
|
+
readonly _tag: "current";
|
|
31
|
+
readonly value: WorkDecisionHandoffType;
|
|
32
|
+
} | {
|
|
33
|
+
readonly _tag: "invalid";
|
|
34
|
+
readonly cause: Schema.SchemaError;
|
|
35
|
+
} | {
|
|
36
|
+
readonly _tag: "previous";
|
|
37
|
+
readonly value: PreviousWorkDecisionHandoff;
|
|
38
|
+
};
|
|
39
|
+
export declare const previousDecisionHandoffEquivalent: import("effect/Equivalence").Equivalence<{
|
|
40
|
+
readonly version: "herdr.work.decision.v1";
|
|
41
|
+
readonly id: string;
|
|
42
|
+
readonly sessionId: string;
|
|
43
|
+
readonly laneId: string;
|
|
44
|
+
readonly goalId: string;
|
|
45
|
+
readonly decision: "blocked" | "complete" | "continue" | "handoff";
|
|
46
|
+
readonly summary: string;
|
|
47
|
+
readonly owner: {
|
|
48
|
+
readonly id: string;
|
|
49
|
+
readonly name: string;
|
|
50
|
+
};
|
|
51
|
+
readonly dispatchIds: readonly string[];
|
|
52
|
+
readonly blockers: readonly {
|
|
53
|
+
readonly id: string;
|
|
54
|
+
readonly detail: string;
|
|
55
|
+
}[];
|
|
56
|
+
readonly evidenceRefs: readonly {
|
|
57
|
+
readonly id: string;
|
|
58
|
+
readonly kind: "commit" | "document" | "review" | "test";
|
|
59
|
+
readonly reference: string;
|
|
60
|
+
}[];
|
|
61
|
+
readonly occurredAt: number;
|
|
62
|
+
}>;
|
|
63
|
+
export declare const currentDecisionHandoffEquivalent: import("effect/Equivalence").Equivalence<{
|
|
64
|
+
readonly version: "herdr.work.decision.v2";
|
|
65
|
+
readonly id: string;
|
|
66
|
+
readonly sessionId: string;
|
|
67
|
+
readonly laneId: string;
|
|
68
|
+
readonly goalId: string;
|
|
69
|
+
readonly expectedRevision: number;
|
|
70
|
+
readonly decision: "blocked" | "complete" | "continue" | "handoff";
|
|
71
|
+
readonly summary: string;
|
|
72
|
+
readonly contextDelta: string;
|
|
73
|
+
readonly owner: {
|
|
74
|
+
readonly id: string;
|
|
75
|
+
readonly name: string;
|
|
76
|
+
};
|
|
77
|
+
readonly dispatchIds: readonly string[];
|
|
78
|
+
readonly blockers: readonly {
|
|
79
|
+
readonly id: string;
|
|
80
|
+
readonly detail: string;
|
|
81
|
+
}[];
|
|
82
|
+
readonly evidenceRefs: readonly {
|
|
83
|
+
readonly id: string;
|
|
84
|
+
readonly kind: "commit" | "document" | "review" | "test";
|
|
85
|
+
readonly reference: string;
|
|
86
|
+
}[];
|
|
87
|
+
readonly occurredAt: number;
|
|
88
|
+
}>;
|
|
89
|
+
export declare const workDispatchLineageEquivalent: import("effect/Equivalence").Equivalence<readonly string[]>;
|
|
90
|
+
export declare const CurrentMetadataWorkLink: Schema.Struct<{
|
|
91
|
+
readonly handoff: Schema.Struct<{
|
|
92
|
+
readonly version: Schema.Literal<"herdr.work.decision.v2">;
|
|
93
|
+
readonly id: Schema.String;
|
|
94
|
+
readonly sessionId: Schema.String;
|
|
95
|
+
readonly laneId: Schema.String;
|
|
96
|
+
readonly goalId: Schema.String;
|
|
97
|
+
readonly expectedRevision: Schema.Number;
|
|
98
|
+
readonly decision: Schema.Literals<readonly ["continue", "blocked", "handoff", "complete"]>;
|
|
99
|
+
readonly summary: Schema.String;
|
|
100
|
+
readonly contextDelta: Schema.String;
|
|
101
|
+
readonly owner: Schema.Struct<{
|
|
102
|
+
readonly id: Schema.String;
|
|
103
|
+
readonly name: Schema.String;
|
|
104
|
+
}>;
|
|
105
|
+
readonly dispatchIds: Schema.$Array<Schema.String>;
|
|
106
|
+
readonly blockers: Schema.$Array<Schema.Struct<{
|
|
107
|
+
readonly id: Schema.String;
|
|
108
|
+
readonly detail: Schema.String;
|
|
109
|
+
}>>;
|
|
110
|
+
readonly evidenceRefs: Schema.$Array<Schema.Struct<{
|
|
111
|
+
readonly id: Schema.String;
|
|
112
|
+
readonly kind: Schema.Literals<readonly ["commit", "test", "review", "document"]>;
|
|
113
|
+
readonly reference: Schema.String;
|
|
114
|
+
}>>;
|
|
115
|
+
readonly occurredAt: Schema.Number;
|
|
116
|
+
}>;
|
|
117
|
+
readonly lineage: Schema.$Array<Schema.String>;
|
|
118
|
+
}>;
|
|
119
|
+
/** Keeps a dispatch's ordered lineage narrower than the decision's complete dispatch set. */
|
|
120
|
+
export declare const workDispatchLineageContainedBy: (lineage: ReadonlyArray<string>, dispatchIds: ReadonlyArray<string>) => boolean;
|
|
121
|
+
/** Accepts only the current or immediately previous persisted handoff contract. */
|
|
122
|
+
export declare const decodePreviousDecisionHandoff: (input: PersistedDecisionHandoffJson) => PreviousDecisionHandoffDecodeResult;
|
|
123
|
+
/** Upgrades the immediately previous persisted handoff shape without accepting unknown versions. */
|
|
124
|
+
export declare const upgradePreviousDecisionHandoff: (previous: PreviousWorkDecisionHandoff, expectedRevision: number) => WorkDecisionHandoffType;
|
|
125
|
+
export {};
|
|
126
|
+
//# sourceMappingURL=decision-handoff-migration.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"decision-handoff-migration.d.ts","sourceRoot":"","sources":["../../src/internal/decision-handoff-migration.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkB,MAAM,EAAE,MAAM,QAAQ,CAAA;AAC/C,OAAO,EAAuB,KAAK,mBAAmB,IAAI,uBAAuB,EAAE,MAAM,aAAa,CAAA;AAEtG,eAAO,MAAM,2BAA2B;;;;;;;;;;;;;;;;;;;;;;;EAatC,CAAA;AACF,KAAK,2BAA2B,GAAG,OAAO,2BAA2B,CAAC,IAAI,CAAA;AAC1E,KAAK,4BAA4B,GAAG,OAAO,MAAM,CAAC,IAAI,CAAC,IAAI,CAAA;AAM3D,KAAK,mCAAmC,GACpC;IAAE,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,uBAAuB,CAAA;CAAE,GACrE;IAAE,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC,WAAW,CAAA;CAAE,GAChE;IAAE,QAAQ,CAAC,IAAI,EAAE,UAAU,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,2BAA2B,CAAA;CAAE,CAAA;AAE9E,eAAO,MAAM,iCAAiC;;;;;;;;;;;;;;;;;;;;;;;EAAoD,CAAA;AAClG,eAAO,MAAM,gCAAgC;;;;;;;;;;;;;;;;;;;;;;;;;EAA4C,CAAA;AACzF,eAAO,MAAM,6BAA6B,6DAA+D,CAAA;AACzG,eAAO,MAAM,uBAAuB;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAGlC,CAAA;AAEF,6FAA6F;AAC7F,eAAO,MAAM,8BAA8B,YAChC,aAAa,CAAC,MAAM,CAAC,eACjB,aAAa,CAAC,MAA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