dsh-kingdom 0.8.0 → 2.0.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/ASSETS_NOTICE.md +22 -0
- package/LICENSE +661 -29
- package/NOTICE +9 -0
- package/README.md +93 -94
- package/THIRD_PARTY_NOTICES.md +92 -0
- package/cordis.patch.yml +6 -6
- package/docs/V2.0-RELEASE-NOTES.md +30 -0
- package/docs/V2.0-USER-GUIDE.md +74 -0
- package/lib/adapter/dsh-backend.js +327 -24
- package/lib/adapter/dsh-backend.js.map +1 -1
- package/lib/adapter/dsh-cost.js +68 -0
- package/lib/adapter/dsh-cost.js.map +1 -0
- package/lib/adapter/dsh-session-events.js +86 -0
- package/lib/adapter/dsh-session-events.js.map +1 -0
- package/lib/adapter/dsh-usage.js +159 -0
- package/lib/adapter/dsh-usage.js.map +1 -0
- package/lib/capability/admin.js +72 -0
- package/lib/capability/admin.js.map +1 -0
- package/lib/capability/dsh-enforcement.js +143 -34
- package/lib/capability/dsh-enforcement.js.map +1 -1
- package/lib/capability/resolver.js +21 -8
- package/lib/capability/resolver.js.map +1 -1
- package/lib/capability/service.js +169 -26
- package/lib/capability/service.js.map +1 -1
- package/lib/capability/tool-disclosure.js +144 -0
- package/lib/capability/tool-disclosure.js.map +1 -0
- package/lib/core/binding.js +52 -34
- package/lib/core/binding.js.map +1 -1
- package/lib/core/budget.js +304 -0
- package/lib/core/budget.js.map +1 -0
- package/lib/core/collaboration.js +422 -0
- package/lib/core/collaboration.js.map +1 -0
- package/lib/core/cost.js +212 -0
- package/lib/core/cost.js.map +1 -0
- package/lib/core/db.js +197 -4
- package/lib/core/db.js.map +1 -1
- package/lib/core/execution.js +2 -2
- package/lib/core/execution.js.map +1 -1
- package/lib/core/governed-claim.js +46 -0
- package/lib/core/governed-claim.js.map +1 -0
- package/lib/core/governed.js +891 -98
- package/lib/core/governed.js.map +1 -1
- package/lib/core/kingdom.js +78 -70
- package/lib/core/kingdom.js.map +1 -1
- package/lib/core/owner-binding-intent.js +732 -0
- package/lib/core/owner-binding-intent.js.map +1 -0
- package/lib/core/owner-control.js +86 -0
- package/lib/core/owner-control.js.map +1 -0
- package/lib/core/owner-window.js +822 -0
- package/lib/core/owner-window.js.map +1 -0
- package/lib/core/task-service.js +296 -133
- package/lib/core/task-service.js.map +1 -1
- package/lib/core/territory.js +44 -14
- package/lib/core/territory.js.map +1 -1
- package/lib/core/usage.js +39 -0
- package/lib/core/usage.js.map +1 -0
- package/lib/core/workspace-admission.js +225 -0
- package/lib/core/workspace-admission.js.map +1 -0
- package/lib/dispatch/evidence.js +5 -2
- package/lib/dispatch/evidence.js.map +1 -1
- package/lib/dispatch/reconcile.js +3 -9
- package/lib/dispatch/reconcile.js.map +1 -1
- package/lib/dispatch/service.js +464 -64
- package/lib/dispatch/service.js.map +1 -1
- package/lib/gui/assets/characters/chancellor-idle.svg +67 -0
- package/lib/gui/assets/characters/chancellor-sleeping.svg +67 -0
- package/lib/gui/assets/characters/chancellor-thinking.svg +67 -0
- package/lib/gui/assets/characters/chancellor-working.svg +67 -0
- package/lib/gui/assets/characters/knight-redraw-r1-idle.svg +67 -0
- package/lib/gui/assets/characters/knight-redraw-r1-sleeping.svg +67 -0
- package/lib/gui/assets/characters/knight-redraw-r1-thinking.svg +67 -0
- package/lib/gui/assets/characters/knight-redraw-r1-working.svg +67 -0
- package/lib/gui/assets/characters/supervisor-idle.svg +67 -0
- package/lib/gui/assets/characters/supervisor-sleeping.svg +67 -0
- package/lib/gui/assets/characters/supervisor-thinking.svg +67 -0
- package/lib/gui/assets/characters/supervisor-working.svg +67 -0
- package/lib/gui/console-app.js +2330 -0
- package/lib/gui/console-app.js.map +1 -0
- package/lib/gui/contract.js +5 -5
- package/lib/gui/contract.js.map +1 -1
- package/lib/gui/control-contract.js +232 -0
- package/lib/gui/control-contract.js.map +1 -0
- package/lib/gui/local-control.js +423 -0
- package/lib/gui/local-control.js.map +1 -0
- package/lib/gui/owner-control.js +310 -0
- package/lib/gui/owner-control.js.map +1 -0
- package/lib/gui/owner-ui.js +191 -0
- package/lib/gui/owner-ui.js.map +1 -0
- package/lib/gui/server.js +445 -35
- package/lib/gui/server.js.map +1 -1
- package/lib/gui/snapshot.js +1346 -67
- package/lib/gui/snapshot.js.map +1 -1
- package/lib/gui/visual-assets.js +56 -0
- package/lib/gui/visual-assets.js.map +1 -0
- package/lib/gui/visual-system.js +272 -0
- package/lib/gui/visual-system.js.map +1 -0
- package/lib/gui/workbench-ui.js +358 -0
- package/lib/gui/workbench-ui.js.map +1 -0
- package/lib/gui/workbench.js +163 -0
- package/lib/gui/workbench.js.map +1 -0
- package/lib/index.js +1384 -361
- package/lib/index.js.map +1 -1
- package/lib/runner-context-broker.js +1134 -0
- package/lib/runner-context-broker.js.map +1 -0
- package/lib/runtime-cost-observer.js +145 -0
- package/lib/runtime-cost-observer.js.map +1 -0
- package/lib/types/adapter/contract.d.ts +61 -1
- package/lib/types/adapter/dsh-backend.d.ts +32 -13
- package/lib/types/adapter/dsh-cost.d.ts +13 -0
- package/lib/types/adapter/dsh-session-events.d.ts +16 -0
- package/lib/types/adapter/dsh-usage.d.ts +36 -0
- package/lib/types/capability/admin.d.ts +13 -0
- package/lib/types/capability/dsh-enforcement.d.ts +11 -7
- package/lib/types/capability/service.d.ts +10 -3
- package/lib/types/capability/tool-disclosure.d.ts +36 -0
- package/lib/types/core/binding.d.ts +19 -10
- package/lib/types/core/budget.d.ts +81 -0
- package/lib/types/core/collaboration.d.ts +110 -0
- package/lib/types/core/cost.d.ts +99 -0
- package/lib/types/core/db.d.ts +44 -4
- package/lib/types/core/execution.d.ts +1 -1
- package/lib/types/core/governed-claim.d.ts +7 -0
- package/lib/types/core/governed.d.ts +182 -1
- package/lib/types/core/kingdom.d.ts +3 -0
- package/lib/types/core/owner-binding-intent.d.ts +176 -0
- package/lib/types/core/owner-control.d.ts +53 -0
- package/lib/types/core/owner-window.d.ts +226 -0
- package/lib/types/core/task-service.d.ts +60 -13
- package/lib/types/core/territory.d.ts +9 -2
- package/lib/types/core/usage.d.ts +26 -0
- package/lib/types/core/workspace-admission.d.ts +43 -0
- package/lib/types/dispatch/evidence.d.ts +2 -5
- package/lib/types/dispatch/service.d.ts +62 -4
- package/lib/types/gui/console-app.d.ts +137 -0
- package/lib/types/gui/contract.d.ts +396 -16
- package/lib/types/gui/control-contract.d.ts +111 -0
- package/lib/types/gui/local-control.d.ts +120 -0
- package/lib/types/gui/owner-control.d.ts +45 -0
- package/lib/types/gui/owner-ui.d.ts +2 -0
- package/lib/types/gui/server.d.ts +17 -3
- package/lib/types/gui/snapshot.d.ts +33 -11
- package/lib/types/gui/visual-assets.d.ts +27 -0
- package/lib/types/gui/visual-system.d.ts +2 -0
- package/lib/types/gui/workbench-ui.d.ts +5 -0
- package/lib/types/gui/workbench.d.ts +33 -0
- package/lib/types/index.d.ts +157 -6
- package/lib/types/runner-context-broker.d.ts +119 -0
- package/lib/types/runtime-cost-observer.d.ts +22 -0
- package/lib/types/worker/collaboration.d.ts +35 -0
- package/lib/types/worker/dsh-subagent.d.ts +4 -4
- package/lib/types/worker/executor-factory.d.ts +2 -1
- package/lib/types/worker/executor.d.ts +8 -3
- package/lib/types/worker/governed-executor.d.ts +8 -1
- package/lib/worker/collaboration.js +172 -0
- package/lib/worker/collaboration.js.map +1 -0
- package/lib/worker/dsh-subagent.js +4 -4
- package/lib/worker/executor-factory.js.map +1 -1
- package/lib/worker/executor.js +7 -2
- package/lib/worker/executor.js.map +1 -1
- package/lib/worker/governed-executor.js +295 -84
- package/lib/worker/governed-executor.js.map +1 -1
- package/package.json +23 -8
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { KingdomStore, RoleBindingRow } from './db.js';
|
|
2
|
+
import { type OwnerControlCapability, type OwnerEventSource, type OwnerOperationMatch } from './owner-control.js';
|
|
2
3
|
export declare const ROLE_TYPES: readonly ["OWNER", "CHANCELLOR", "SUPERVISOR", "WORKER"];
|
|
3
4
|
export type RoleType = (typeof ROLE_TYPES)[number];
|
|
4
5
|
/**
|
|
@@ -25,7 +26,7 @@ export interface SessionIdentity {
|
|
|
25
26
|
* ExecutorFactory 解析执行时**禁止读取** binding.model_name。
|
|
26
27
|
*/
|
|
27
28
|
export interface ExecutionProfileV1 {
|
|
28
|
-
/**
|
|
29
|
+
/** Requested provider; governed runtime interprets this as an LLM provider. */
|
|
29
30
|
provider?: string;
|
|
30
31
|
/** requested model(传给子 agent 的 agentOptions.model)。缺省 → 继承父 Agent(parent-inherited 证据)。 */
|
|
31
32
|
model?: string;
|
|
@@ -44,8 +45,9 @@ export declare function parseExecutionProfile(json: string | null): ExecutionPro
|
|
|
44
45
|
/**
|
|
45
46
|
* v0.6.0(M1-C):设置/清空角色执行配置(组织资源配置,治理对象)。
|
|
46
47
|
*
|
|
47
|
-
* 必须走
|
|
48
|
-
*
|
|
48
|
+
* 必须走 Core Owner Control gate(requireAdmin → requireOwnerControl):
|
|
49
|
+
* 只有 direct `/kingdom` Slash 持有的 opaque capability 可执行;Agent
|
|
50
|
+
* Session、`OWNER.session_id` 与 declarative auth 均不是 Owner Authority。
|
|
49
51
|
* 独立工具面 `kingdom_set_execution_profile`,不塞进 bind_session
|
|
50
52
|
* (治理身份 Session 与执行能力 Profile 不混用)。
|
|
51
53
|
*/
|
|
@@ -73,23 +75,30 @@ export interface RebindSessionInput extends SessionIdentity {
|
|
|
73
75
|
/**
|
|
74
76
|
* v0.5.2:Trusted Governance Administration Plane 的授权输入。
|
|
75
77
|
*
|
|
76
|
-
*
|
|
77
|
-
*
|
|
78
|
-
*
|
|
79
|
-
*
|
|
78
|
+
* Owner-only 管理面(任命/罢免/改绑/换届/执行配置)的唯一授权输入是
|
|
79
|
+
* direct `/kingdom` handler 内部取得的 `OwnerControlCapability`。
|
|
80
|
+
* `mode` 与 `principalSessionId` 保留为兼容类型字段,不能产生写权限;
|
|
81
|
+
* `declarative`、`session-bound` 以及旧的 `OWNER.session_id` 均只表示历史
|
|
82
|
+
* 运行上下文,不能作为 Owner Authority。
|
|
80
83
|
*/
|
|
81
84
|
export interface AdminAuth {
|
|
82
85
|
mode: 'declarative' | 'session-bound';
|
|
83
86
|
/** 调用方会话(来自 DSH Runtime 证明,工具面注入)。 */
|
|
84
87
|
principalSessionId?: string | null;
|
|
88
|
+
/** Trusted-local direct Slash capability; never accepted from a Tool/HTTP payload. */
|
|
89
|
+
ownerControl?: OwnerControlCapability;
|
|
85
90
|
}
|
|
86
91
|
/**
|
|
87
|
-
*
|
|
88
|
-
*
|
|
92
|
+
* Core Owner gate(兼容旧符号名):所有产品 Owner-only 写统一只接受
|
|
93
|
+
* direct Slash mint 的 opaque capability。旧 auth 输入即使包含匹配的
|
|
94
|
+
* OWNER.session_id 或 declarative mode 也 fail-closed、zero-write。
|
|
89
95
|
*/
|
|
90
|
-
export declare function requireAdmin(store: KingdomStore, kingdomId: string, auth?: AdminAuth): {
|
|
96
|
+
export declare function requireAdmin(store: KingdomStore, kingdomId: string, auth?: AdminAuth, operation?: OwnerOperationMatch): {
|
|
91
97
|
ok: true;
|
|
92
98
|
owner: RoleBindingRow | null;
|
|
99
|
+
ownerPrincipalId: string | null;
|
|
100
|
+
ownerControl: boolean;
|
|
101
|
+
eventSource: OwnerEventSource;
|
|
93
102
|
} | {
|
|
94
103
|
ok: false;
|
|
95
104
|
message: string;
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import type { KingdomStore } from './db.js';
|
|
2
|
+
import { type AdminAuth } from './binding.js';
|
|
3
|
+
/** Exact Owner budget.policy parameters. Amounts are tokens, never a hard bill limit. */
|
|
4
|
+
export interface BudgetPolicyParameters {
|
|
5
|
+
enabled: boolean;
|
|
6
|
+
limit_tokens: number;
|
|
7
|
+
reserve_tokens: number;
|
|
8
|
+
unknown_policy: 'BLOCK' | 'WARN';
|
|
9
|
+
warning_percent?: number;
|
|
10
|
+
}
|
|
11
|
+
export interface BudgetPolicyView {
|
|
12
|
+
type: 'KingdomBudgetPolicy/v1';
|
|
13
|
+
budgetId: string;
|
|
14
|
+
kingdomId: string;
|
|
15
|
+
enabled: boolean;
|
|
16
|
+
limitTokens: number;
|
|
17
|
+
reserveTokens: number;
|
|
18
|
+
unknownPolicy: 'BLOCK' | 'WARN';
|
|
19
|
+
warningPercent: number;
|
|
20
|
+
sinceEventSeq: number;
|
|
21
|
+
revision: number;
|
|
22
|
+
updatedAt: string;
|
|
23
|
+
}
|
|
24
|
+
export interface BudgetView {
|
|
25
|
+
type: 'KingdomBudgetView/v1';
|
|
26
|
+
scope: 'KINGDOM';
|
|
27
|
+
coverage: 'OBSERVABLE_ONLY';
|
|
28
|
+
policy: BudgetPolicyView | null;
|
|
29
|
+
state: 'OFF' | 'ALLOW' | 'WARN' | 'BLOCK_LIMIT' | 'BLOCK_UNKNOWN';
|
|
30
|
+
verifiedTokens: number;
|
|
31
|
+
workerVerifiedTokens: number;
|
|
32
|
+
additionalVerifiedTokens: number;
|
|
33
|
+
reservedEstimateTokens: number;
|
|
34
|
+
exposureTokens: number;
|
|
35
|
+
remainingTokens: number | null;
|
|
36
|
+
pendingUnits: number;
|
|
37
|
+
unknownUnits: number;
|
|
38
|
+
attributionGapCount: number;
|
|
39
|
+
recoveryUnits: number;
|
|
40
|
+
amount: null;
|
|
41
|
+
amountStatus: 'UNKNOWN';
|
|
42
|
+
note: string;
|
|
43
|
+
}
|
|
44
|
+
declare const BUDGET_ADMISSION_HANDLE: unique symbol;
|
|
45
|
+
export interface BudgetAdmissionHandle {
|
|
46
|
+
readonly [BUDGET_ADMISSION_HANDLE]: true;
|
|
47
|
+
}
|
|
48
|
+
export interface BudgetAdmissionInput {
|
|
49
|
+
kingdomId: string;
|
|
50
|
+
taskId: string;
|
|
51
|
+
attemptNo: number;
|
|
52
|
+
workerBindingId: string;
|
|
53
|
+
}
|
|
54
|
+
export interface BudgetAdmissionBindingInput extends BudgetAdmissionInput {
|
|
55
|
+
dispatchId: string;
|
|
56
|
+
leaseId: string;
|
|
57
|
+
}
|
|
58
|
+
export declare class BudgetError extends Error {
|
|
59
|
+
readonly code: string;
|
|
60
|
+
constructor(code: string, message: string);
|
|
61
|
+
}
|
|
62
|
+
/** Process-local observation only; historical IDs do not grant admission authority. */
|
|
63
|
+
export declare function isBudgetAdmissionInvocationActive(store: KingdomStore, admissionId: string): boolean;
|
|
64
|
+
export declare function normalizeBudgetPolicyParameters(value: unknown): Required<BudgetPolicyParameters>;
|
|
65
|
+
export declare function readBudgetPolicy(store: KingdomStore, kingdomId: string): BudgetPolicyView | null;
|
|
66
|
+
/** Synchronous exact Owner helper, also callable inside the Owner receipt transaction. */
|
|
67
|
+
export declare function setBudgetPolicy(store: KingdomStore, input: {
|
|
68
|
+
kingdomId: string;
|
|
69
|
+
policy: BudgetPolicyParameters;
|
|
70
|
+
}, auth?: AdminAuth): string;
|
|
71
|
+
/** Deterministic read projection. Additional usage includes non-Worker sources only. */
|
|
72
|
+
export declare function readBudgetView(store: KingdomStore, kingdomId: string): BudgetView;
|
|
73
|
+
/** No Runtime callback occurs inside this transaction; concurrent admissions serialize on the ledger. */
|
|
74
|
+
export declare function reserveBudgetAdmission(store: KingdomStore, input: BudgetAdmissionInput): BudgetAdmissionHandle;
|
|
75
|
+
/** Called only from the existing TX-3 after the exact Execution, Intent and EXECUTING Lease are written. */
|
|
76
|
+
export declare function bindBudgetAdmissionInTransaction(store: KingdomStore, handle: BudgetAdmissionHandle | undefined, input: BudgetAdmissionBindingInput): void;
|
|
77
|
+
/** Only closes accounting; it never releases, stops or edits any Runtime/Lease/Task fact. */
|
|
78
|
+
export declare function cancelBudgetAdmissionIfSafe(store: KingdomStore, handle: BudgetAdmissionHandle): boolean;
|
|
79
|
+
/** End only the in-memory invocation; unresolved persisted reservations remain visible after restart. */
|
|
80
|
+
export declare function finishBudgetAdmissionInvocation(handle: BudgetAdmissionHandle): void;
|
|
81
|
+
export {};
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import type { KingdomStore } from './db.js';
|
|
2
|
+
import { type AdminAuth } from './binding.js';
|
|
3
|
+
import { type CommandContext } from './task-service.js';
|
|
4
|
+
export interface CollaborationPlanItemInput {
|
|
5
|
+
key: string;
|
|
6
|
+
title: string;
|
|
7
|
+
description: string;
|
|
8
|
+
acceptanceCriteria: string;
|
|
9
|
+
territoryId: string;
|
|
10
|
+
workerBindingId: string;
|
|
11
|
+
access: 'READ_ONLY' | 'WRITE';
|
|
12
|
+
dependsOn: string[];
|
|
13
|
+
expectedArtifact: string;
|
|
14
|
+
}
|
|
15
|
+
export interface ProposeCollaborationPlanInput {
|
|
16
|
+
parentTaskId: string;
|
|
17
|
+
expectedVersion?: number;
|
|
18
|
+
mode: 'EXPERT' | 'TEAM';
|
|
19
|
+
reason: string;
|
|
20
|
+
integratorBindingId: string;
|
|
21
|
+
budgetTokens: number;
|
|
22
|
+
reserveTokens: number;
|
|
23
|
+
items: CollaborationPlanItemInput[];
|
|
24
|
+
}
|
|
25
|
+
export interface PlanAdoptionParameters {
|
|
26
|
+
plan_id: string;
|
|
27
|
+
version: number;
|
|
28
|
+
digest: string;
|
|
29
|
+
}
|
|
30
|
+
export interface CollaborationPlanItem extends CollaborationPlanItemInput {
|
|
31
|
+
taskId: string;
|
|
32
|
+
}
|
|
33
|
+
export interface CollaborationPlanView {
|
|
34
|
+
type: 'KingdomCollaborationPlan/v1';
|
|
35
|
+
planId: string;
|
|
36
|
+
kingdomId: string;
|
|
37
|
+
parentTaskId: string;
|
|
38
|
+
version: number;
|
|
39
|
+
digest: string;
|
|
40
|
+
state: 'PROPOSED' | 'ADOPTED' | 'STALE';
|
|
41
|
+
mode: 'EXPERT' | 'TEAM';
|
|
42
|
+
reason: string;
|
|
43
|
+
integratorBindingId: string;
|
|
44
|
+
budgetTokens: number;
|
|
45
|
+
reserveTokens: number;
|
|
46
|
+
items: CollaborationPlanItem[];
|
|
47
|
+
childTaskIds: string[];
|
|
48
|
+
proposedBy: string;
|
|
49
|
+
proposedAt: string;
|
|
50
|
+
proposedSeq: number;
|
|
51
|
+
adoptedAt: string | null;
|
|
52
|
+
adoptedSeq: number | null;
|
|
53
|
+
}
|
|
54
|
+
export declare class CollaborationError extends Error {
|
|
55
|
+
readonly code: string;
|
|
56
|
+
constructor(code: string, message: string);
|
|
57
|
+
}
|
|
58
|
+
export declare function normalizePlanAdoptionParameters(value: unknown): PlanAdoptionParameters;
|
|
59
|
+
export declare function readCollaborationPlan(store: KingdomStore, kingdomId: string, planId: string): CollaborationPlanView | null;
|
|
60
|
+
export declare function listCollaborationPlans(store: KingdomStore, kingdomId: string): CollaborationPlanView[];
|
|
61
|
+
export declare function proposeCollaborationPlan(store: KingdomStore, ctx: CommandContext, input: ProposeCollaborationPlanInput): CollaborationPlanView;
|
|
62
|
+
export declare function adoptCollaborationPlan(store: KingdomStore, input: {
|
|
63
|
+
kingdomId: string;
|
|
64
|
+
} & PlanAdoptionParameters, auth?: AdminAuth): string;
|
|
65
|
+
export interface CollaborationHandoff {
|
|
66
|
+
taskId: string;
|
|
67
|
+
attemptNo: number;
|
|
68
|
+
resultId: string;
|
|
69
|
+
resultDigest: string;
|
|
70
|
+
acceptEventId: string;
|
|
71
|
+
acceptEventSeq: number;
|
|
72
|
+
summary: string;
|
|
73
|
+
artifacts: string[];
|
|
74
|
+
}
|
|
75
|
+
export interface CollaborationReadiness {
|
|
76
|
+
planId: string;
|
|
77
|
+
version: number;
|
|
78
|
+
digest: string;
|
|
79
|
+
parentTaskId: string;
|
|
80
|
+
taskId: string;
|
|
81
|
+
kind: 'ITEM' | 'INTEGRATION';
|
|
82
|
+
access: 'READ_ONLY' | 'WRITE';
|
|
83
|
+
workerBindingId: string;
|
|
84
|
+
ready: boolean;
|
|
85
|
+
reasonCode: string | null;
|
|
86
|
+
blockingTaskIds: string[];
|
|
87
|
+
handoffs: CollaborationHandoff[];
|
|
88
|
+
}
|
|
89
|
+
/** Read-only exact references. Handoff text remains an untrusted Worker Claim. */
|
|
90
|
+
export declare function readCollaborationReadiness(store: KingdomStore, kingdomId: string, taskId: string, preparingLeaseId?: string): CollaborationReadiness | null;
|
|
91
|
+
/** Recompute before dispatch; caller-supplied or stale references never become authority. */
|
|
92
|
+
export declare function validateCollaborationHandoffs(store: KingdomStore, kingdomId: string, taskId: string, expected: readonly CollaborationHandoff[], preparingLeaseId?: string): boolean;
|
|
93
|
+
export interface PlanBudgetView {
|
|
94
|
+
scope: 'PLAN_WITH_KINGDOM_COORDINATION_UPPER_BOUND';
|
|
95
|
+
planId: string;
|
|
96
|
+
limitTokens: number;
|
|
97
|
+
reserveTokens: number;
|
|
98
|
+
workerVerifiedTokens: number;
|
|
99
|
+
coordinationUpperBoundTokens: number;
|
|
100
|
+
reservedEstimateTokens: number;
|
|
101
|
+
exposureTokens: number;
|
|
102
|
+
remainingTokens: number;
|
|
103
|
+
pendingUnits: number;
|
|
104
|
+
unknownUnits: number;
|
|
105
|
+
attributionGapCount: number;
|
|
106
|
+
state: 'ALLOW' | 'WARN' | 'BLOCK_LIMIT' | 'BLOCK_UNKNOWN';
|
|
107
|
+
amount: null;
|
|
108
|
+
}
|
|
109
|
+
/** Members are exact; all observable concurrent kingdom coordination is a conservative upper bound. */
|
|
110
|
+
export declare function readPlanBudgetView(store: KingdomStore, kingdomId: string, planId: string): PlanBudgetView | null;
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import type { KingdomStore } from './db.js';
|
|
2
|
+
/** Provider buckets are disjoint; reasoning is already included in output. */
|
|
3
|
+
export interface ProviderTokenCounts {
|
|
4
|
+
uncachedInputTokens: number;
|
|
5
|
+
outputTokens: number;
|
|
6
|
+
totalTokens: number;
|
|
7
|
+
cacheReadTokens?: number;
|
|
8
|
+
cacheWriteTokens?: number;
|
|
9
|
+
reasoningTokens?: number;
|
|
10
|
+
routes?: readonly {
|
|
11
|
+
provider: string;
|
|
12
|
+
model: string;
|
|
13
|
+
}[];
|
|
14
|
+
}
|
|
15
|
+
/** Neutral source observation. It cannot change role, task, or execution authority. */
|
|
16
|
+
export interface RoleUsageObservation {
|
|
17
|
+
type: 'KingdomRoleUsage/v1';
|
|
18
|
+
source: 'provider-reported';
|
|
19
|
+
sourceUnitRef: string;
|
|
20
|
+
runtimeInstanceRef: string;
|
|
21
|
+
sessionRef: string;
|
|
22
|
+
bindingId: string;
|
|
23
|
+
roleType: 'CHANCELLOR' | 'SUPERVISOR';
|
|
24
|
+
taskIds: string[];
|
|
25
|
+
attribution: 'TASK' | 'SHARED' | 'UNATTRIBUTED';
|
|
26
|
+
startedAt: string;
|
|
27
|
+
startedLedgerSeq: number;
|
|
28
|
+
observationSequence: number;
|
|
29
|
+
status: 'IN_PROGRESS' | 'COMPLETE' | 'UNAVAILABLE';
|
|
30
|
+
reasonCode: string | null;
|
|
31
|
+
observedRequests: number;
|
|
32
|
+
reportedRequests: number;
|
|
33
|
+
usage: ProviderTokenCounts | null;
|
|
34
|
+
}
|
|
35
|
+
export interface PromptCostObservation {
|
|
36
|
+
type: 'KingdomPromptCost/v1';
|
|
37
|
+
source: 'assembly-byte-observation';
|
|
38
|
+
sourceUnitRef: string;
|
|
39
|
+
bindingId: string;
|
|
40
|
+
roleType: string;
|
|
41
|
+
toolsBefore: number;
|
|
42
|
+
toolsAfter: number;
|
|
43
|
+
toolsBytesBefore: number;
|
|
44
|
+
toolsBytesAfter: number;
|
|
45
|
+
sections: {
|
|
46
|
+
name: string;
|
|
47
|
+
bytes: number;
|
|
48
|
+
}[];
|
|
49
|
+
contexts: {
|
|
50
|
+
name: string;
|
|
51
|
+
bytes: number;
|
|
52
|
+
}[];
|
|
53
|
+
/** Assembly has no final history envelope; never substitute a zero. */
|
|
54
|
+
historyBytes: null;
|
|
55
|
+
tokenEstimate: null;
|
|
56
|
+
mode: 'off' | 'pilot';
|
|
57
|
+
reasonCode: string | null;
|
|
58
|
+
}
|
|
59
|
+
export declare function validProviderCounts(usage: ProviderTokenCounts): boolean;
|
|
60
|
+
export declare function recordUsageCoverageGap(store: KingdomStore, kingdomId: string, sourceUnitRef: string, reasonCode: 'ROLE_IDENTITY_AMBIGUOUS'): void;
|
|
61
|
+
/** Arbitrary plugin names are not trusted metadata. Only fixed public categories reach the ledger. */
|
|
62
|
+
export declare function safePromptPartName(value: string, index: number, type: 'section' | 'context'): string;
|
|
63
|
+
export declare function recordRoleUsage(store: KingdomStore, kingdomId: string, input: RoleUsageObservation): boolean;
|
|
64
|
+
export interface AdditionalRoleCostSummary {
|
|
65
|
+
scope: 'OBSERVED_GOVERNANCE_TURNS';
|
|
66
|
+
units: number;
|
|
67
|
+
completeUnits: number;
|
|
68
|
+
pendingUnits: number;
|
|
69
|
+
unknownUnits: number;
|
|
70
|
+
attributionGapCount: number;
|
|
71
|
+
observedRequests: number;
|
|
72
|
+
reportedRequests: number;
|
|
73
|
+
verifiedTokens: number | null;
|
|
74
|
+
byRole: {
|
|
75
|
+
roleType: string;
|
|
76
|
+
units: number;
|
|
77
|
+
completeUnits: number;
|
|
78
|
+
verifiedTokens: number | null;
|
|
79
|
+
}[];
|
|
80
|
+
sharedTokens: number | null;
|
|
81
|
+
unattributedTokens: number | null;
|
|
82
|
+
amount: null;
|
|
83
|
+
amountStatus: 'PRICE_NOT_CONFIGURED';
|
|
84
|
+
coverageNote: string;
|
|
85
|
+
}
|
|
86
|
+
/** Lost observer continuity is unknown usage, never proof a Runtime stopped. */
|
|
87
|
+
export declare function closeInterruptedRoleObservations(store: KingdomStore, kingdomId: string, runtimeInstanceRef: string): number;
|
|
88
|
+
export declare function readAdditionalRoleCost(store: KingdomStore, kingdomId: string, taskId?: string): AdditionalRoleCostSummary;
|
|
89
|
+
/** Add only non-Worker observations; Worker dispatch reports are already counted by budget.ts. */
|
|
90
|
+
export declare function readIncompleteRoleUsageSourceRefs(store: KingdomStore, kingdomId: string): string[];
|
|
91
|
+
/** Frozen carry-in sources preserve work already pending when the first policy was created. */
|
|
92
|
+
export declare function readAdditionalBudgetUsage(store: KingdomStore, kingdomId: string, sinceEventSeq: number, carriedSourceRefs?: readonly string[]): {
|
|
93
|
+
verifiedTokens: number;
|
|
94
|
+
unknownUnits: number;
|
|
95
|
+
pendingUnits: number;
|
|
96
|
+
attributionGapCount: number;
|
|
97
|
+
};
|
|
98
|
+
export declare function recordPromptCost(store: KingdomStore, kingdomId: string, input: PromptCostObservation): void;
|
|
99
|
+
export declare function readLatestPromptCosts(store: KingdomStore, kingdomId: string): PromptCostObservation[];
|
package/lib/types/core/db.d.ts
CHANGED
|
@@ -141,7 +141,10 @@ export interface ExecutionRow {
|
|
|
141
141
|
task_id: string;
|
|
142
142
|
attempt_no: number;
|
|
143
143
|
worker_binding_id: string | null;
|
|
144
|
-
/**
|
|
144
|
+
/**
|
|
145
|
+
* 该次执行的 runtime session id;LEGACY_COMPAT 每轮 REWORK 都是新的 one-shot,
|
|
146
|
+
* GOVERNED_PERSISTENT 则记录被复用的长期 Worker Session。
|
|
147
|
+
*/
|
|
145
148
|
session_id: string | null;
|
|
146
149
|
/** STARTING / RUNNING / PAUSED / COMPLETED / FAILED / ABORTED,见 ./execution.ts。 */
|
|
147
150
|
state: string;
|
|
@@ -151,7 +154,7 @@ export interface ExecutionRow {
|
|
|
151
154
|
/**
|
|
152
155
|
* 最近一次**状态转移**的时刻,不是心跳。
|
|
153
156
|
*
|
|
154
|
-
* 诚实说明:one-shot subagent
|
|
157
|
+
* 诚实说明:LEGACY_COMPAT one-shot subagent seam 不提供任何进度回调
|
|
155
158
|
* (`SubagentRun` 只有 `{id, localAgent, result, dispose}`),
|
|
156
159
|
* 所以执行进行中没有任何可以周期性上报的信号,本字段在整个执行体内不会前进。
|
|
157
160
|
*
|
|
@@ -164,7 +167,7 @@ export interface ExecutionRow {
|
|
|
164
167
|
/**
|
|
165
168
|
* 暂停请求时间。
|
|
166
169
|
*
|
|
167
|
-
* one-shot subagent 无法在一次 turn 中途真正挂起,因此"暂停"的诚实语义是:
|
|
170
|
+
* LEGACY_COMPAT one-shot subagent 无法在一次 turn 中途真正挂起,因此"暂停"的诚实语义是:
|
|
168
171
|
* 请求已登记,**在下一个 attempt 边界生效**。执行中的 Execution 会保持
|
|
169
172
|
* `RUNNING` 并带 `pause_requested_at`(GUI 应显示"准备休息"而不是"已睡着")。
|
|
170
173
|
*/
|
|
@@ -296,6 +299,8 @@ export interface TaskRow {
|
|
|
296
299
|
acceptance_criteria: string | null;
|
|
297
300
|
/** 最近一次 Worker Claim 的摘要。**是 Claim,不是完成事实**。 */
|
|
298
301
|
result_summary: string | null;
|
|
302
|
+
/** v0.8:Task 的非权威 Capability Requirement;旧 v3 库可能没有该列。 */
|
|
303
|
+
capability_requirement_json?: string | null;
|
|
299
304
|
created_at: string;
|
|
300
305
|
updated_at: string;
|
|
301
306
|
}
|
|
@@ -313,7 +318,7 @@ export interface WorkerResultRow {
|
|
|
313
318
|
/** 第几次尝试,从 1 起;REWORK 每轮 +1。UNIQUE(task_id, attempt_no)。 */
|
|
314
319
|
attempt_no: number;
|
|
315
320
|
worker_binding_id: string | null;
|
|
316
|
-
/** 该 attempt 的
|
|
321
|
+
/** 该 attempt 的 runtime session id;仅 LEGACY_COMPAT 每轮 REWORK 都是新 one-shot session。 */
|
|
317
322
|
session_id: string | null;
|
|
318
323
|
/** Worker 自称的结果:COMPLETED / FAILED / BLOCKED。是 Claim。 */
|
|
319
324
|
outcome: string;
|
|
@@ -438,6 +443,12 @@ export declare class KingdomStore {
|
|
|
438
443
|
tombstoneTerritoryRow(territoryId: string, reason: string | null): void;
|
|
439
444
|
/** v0.7.0(M2):设置 Territory 主理 Supervisor(scope relation;NULL=未指派=fail-closed)。 */
|
|
440
445
|
updateTerritorySupervisor(territoryId: string, supervisorBindingId: string | null): void;
|
|
446
|
+
updateTerritoryMetadata(territoryId: string, name: string, summary: string | null): void;
|
|
447
|
+
getEventById(eventId: string): EventRow | null;
|
|
448
|
+
/** Global append cursor; callers predicting a receipt sequence must hold the write transaction. */
|
|
449
|
+
eventSequence(): number;
|
|
450
|
+
/** Owner topology guards include RECOVERING and unknown future nonterminal states. */
|
|
451
|
+
listUnsettledOwnerExecutions(kingdomId: string): ExecutionRow[];
|
|
441
452
|
insertTaskAssignment(row: TaskAssignmentRow): TaskAssignmentRow;
|
|
442
453
|
/** 当前 active assignment(partial unique index 保证至多一条)。 */
|
|
443
454
|
getActiveAssignmentForTask(taskId: string): TaskAssignmentRow | null;
|
|
@@ -486,6 +497,19 @@ export declare class KingdomStore {
|
|
|
486
497
|
* 漏了就重新拉一次全量 snapshot,而不是拿残缺事件流去驱动动画。
|
|
487
498
|
*/
|
|
488
499
|
listEventsSince(kingdomId: string, afterSeq: number, limit?: number): EventRow[];
|
|
500
|
+
/**
|
|
501
|
+
* Exact Dispatch lookup for one Task attempt.
|
|
502
|
+
*
|
|
503
|
+
* Integrity decisions must not scan a bounded event projection: the
|
|
504
|
+
* dispatch/task/attempt relation is authoritative in dispatch_records.
|
|
505
|
+
*/
|
|
506
|
+
listDispatchesForTaskAttempt(taskId: string, attemptNo: number): DispatchRecordRow[];
|
|
507
|
+
/**
|
|
508
|
+
* Exact, replay-safe lookup for an open terminal integrity incident.
|
|
509
|
+
* The SQL predicate narrows by the exact Dispatch target; the bounded JSON
|
|
510
|
+
* payload is then checked against the exact Task/attempt correlation.
|
|
511
|
+
*/
|
|
512
|
+
getOpenDispatchTerminalIntegrityIncident(kingdomId: string, dispatchId: string, taskId: string, attemptNo: number): EventRow | null;
|
|
489
513
|
/**
|
|
490
514
|
* 王国当前 revision = 最大事件序号。
|
|
491
515
|
*
|
|
@@ -493,6 +517,12 @@ export declare class KingdomStore {
|
|
|
493
517
|
* GUI 比较 revision 就知道要不要重绘,不必 diff 整个 snapshot。
|
|
494
518
|
*/
|
|
495
519
|
revision(kingdomId: string): number;
|
|
520
|
+
/** Observations and future admission/window policy cannot change an in-flight Runner relation. */
|
|
521
|
+
runnerContextRevision(kingdomId: string, scope?: {
|
|
522
|
+
taskId: string;
|
|
523
|
+
workerBindingId: string;
|
|
524
|
+
sessionRef: string;
|
|
525
|
+
}): number;
|
|
496
526
|
/**
|
|
497
527
|
* v0.7.0(M2):外层事务包装——HANDOFF 等**原子治理操作**(多步写 + 事件)整体提交/回滚。
|
|
498
528
|
* appendEvent 的内层 BEGIN 在事务中会抛错,由 appendEvent 的嵌套容忍逻辑接管(见下)。
|
|
@@ -538,6 +568,15 @@ export declare class KingdomStore {
|
|
|
538
568
|
}): TaskRow;
|
|
539
569
|
listWorkerResults(taskId: string): WorkerResultRow[];
|
|
540
570
|
latestWorkerResult(taskId: string): WorkerResultRow | null;
|
|
571
|
+
/** Exact task/attempt lookup; unrelated kingdom activity cannot hide the reviewed attempt. */
|
|
572
|
+
latestTaskReworkEvent(kingdomId: string, taskId: string, reviewedAttemptNo: number): EventRow | null;
|
|
573
|
+
listDispatchUsageEvents(dispatchId: string): EventRow[];
|
|
574
|
+
/** Complete exact budget ledger; display event windows must never be used as accounting history. */
|
|
575
|
+
listBudgetEvents(kingdomId: string): EventRow[];
|
|
576
|
+
listWorkspaceAdmissionEvents(kingdomId: string): EventRow[];
|
|
577
|
+
listRuntimeCostEvents(kingdomId: string): EventRow[];
|
|
578
|
+
listActorEventsSince(kingdomId: string, actorId: string, afterSeq: number): EventRow[];
|
|
579
|
+
getLatestRuntimeRoleUsageEvent(kingdomId: string, sourceUnitRef: string): EventRow | null;
|
|
541
580
|
/** 已落库的最大 attempt_no;无结果时为 0。下一次尝试 = 本值 + 1。 */
|
|
542
581
|
maxAttemptNo(taskId: string): number;
|
|
543
582
|
/**
|
|
@@ -636,6 +675,7 @@ export declare class KingdomStore {
|
|
|
636
675
|
} | undefined, at: string): DispatchRecordRow;
|
|
637
676
|
getTaskCapabilityRequirement(taskId: string): string | null;
|
|
638
677
|
setTaskCapabilityRequirement(taskId: string, json: string | null): void;
|
|
678
|
+
private getTaskCapabilityRequirementColumn;
|
|
639
679
|
getKingdomCapabilityCeiling(kingdomId: string): string | null;
|
|
640
680
|
setKingdomCapabilityCeiling(kingdomId: string, json: string | null): void;
|
|
641
681
|
statusSummary(): string;
|
|
@@ -24,7 +24,7 @@ export type ExecutionState = (typeof EXECUTION_STATES)[number];
|
|
|
24
24
|
/**
|
|
25
25
|
* 合法转移。
|
|
26
26
|
*
|
|
27
|
-
* - `STARTING → RUNNING
|
|
27
|
+
* - `STARTING → RUNNING | PAUSED`:宿主确认执行已开始,或 Supervisor 在分派前暂停。
|
|
28
28
|
* - `RUNNING ↔ PAUSED`:暂停/恢复(见 `./execution.ts` 关于 one-shot 的诚实边界说明)。
|
|
29
29
|
* - `* → RECOVERING`:v0.8(M3-S2 v6)——Kingdom 无法确认 Execution 真实 Runtime 状态、
|
|
30
30
|
* 正在重建证据(Dispatch Intent 有 / Adapter 失联 / host 重启)。**不改 Task 治理状态**;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { KingdomStore } from './db.js';
|
|
2
|
+
/** One terminal dispatch produces one Claim. Runtime completion never accepts a task. */
|
|
3
|
+
export declare function submitGovernedClaim(store: KingdomStore, dispatchId: string, summary: string): {
|
|
4
|
+
created: boolean;
|
|
5
|
+
summary: string;
|
|
6
|
+
outcome: string;
|
|
7
|
+
};
|