@piup/contracts 0.0.1-beta.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 piup contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,24 @@
1
+ # @piup/contracts
2
+
3
+ <p>
4
+ <a href="https://www.npmjs.com/package/@piup/contracts"><img alt="NPM version" src="https://img.shields.io/npm/v/@piup/contracts.svg?logo=npm"></a>
5
+ <a href="https://www.npmjs.com/package/@piup/contracts"><img alt="NPM downloads" src="https://img.shields.io/npm/dm/@piup/contracts.svg?logo=npm&color=blue"></a>
6
+ <a href="https://bundlephobia.com/package/@piup/contracts">
7
+ <img alt="bundle size" src="https://img.shields.io/bundlephobia/minzip/@piup/contracts.svg?style=flat-square&logo=typescript&label=size">
8
+ </a>
9
+ <a href="https://www.npmjs.com/package/@piup/contracts"><img alt="Node Versions" src="https://img.shields.io/node/v/@piup/contracts.svg"></a>
10
+ </p>
11
+
12
+ <p align="center">
13
+ <a href="https://docs-piup.keylenn.online">
14
+ <img src="https://docs-piup.keylenn.online/piup-logo.svg" alt="piup logo" width="128" height="128">
15
+ </a>
16
+ </p>
17
+
18
+ piup 的共享 TypeScript 协议与类型定义,覆盖请求路由、工作流、任务、检查门禁、Hook 和插件描述。
19
+
20
+ ## 快速开始
21
+
22
+ 本包是 piup 的基础依赖。使用 piup 时无需单独安装,统一通过 CLI 获取配套版本。
23
+
24
+ 完整使用指南与支持范围请查看 **[piup 文档](https://docs-piup.keylenn.online)**。
@@ -0,0 +1,232 @@
1
+ //#region src/index.d.ts
2
+ export declare const PIUP_API_VERSION: 1;
3
+ /** Tool schema generation: intent resolution, structured acceptance, recheck and read-only query. */
4
+ export declare const PIUP_TOOL_PROTOCOL_VERSION: 2;
5
+ export type RouteId = "debug" | "small" | "standard" | "foundation" | "infra";
6
+ export type RequestKind = "read-only" | "change" | "delivery" | "ambiguous";
7
+ export type DeliveryOperation = "commit" | "push";
8
+ export type RequestDisposition = "continue" | "reroute" | "follow-up" | "read-only" | "delivery" | "clarify";
9
+ export type Complexity = "low" | "medium" | "high";
10
+ export type RiskLevel = "low" | "medium" | "high";
11
+ export type DispatchMode = "inline";
12
+ export interface RouteScope {
13
+ /** Workspace-relative paths. A single "." means the whole workspace. */
14
+ readonly paths: readonly string[];
15
+ }
16
+ /** A read-only routing decision. Producing this value must not create a task or mutate a workspace. */
17
+ export interface RouteResult {
18
+ readonly requestKind: RequestKind;
19
+ /** Explicitly authorized Git delivery operations; never implies permission to edit source. */
20
+ readonly deliveryOperations?: readonly DeliveryOperation[];
21
+ readonly route: RouteId | null;
22
+ readonly complexity: Complexity | null;
23
+ readonly risk: RiskLevel | null;
24
+ readonly strategyId: string | null;
25
+ readonly dispatchMode: DispatchMode;
26
+ readonly scope: RouteScope;
27
+ readonly reason: string;
28
+ }
29
+ /** Semantic execution plan. Strategy IDs are derived by the host, never supplied by the agent. */
30
+ export interface RoutingDecision {
31
+ readonly route: RouteId;
32
+ readonly complexity: Complexity;
33
+ readonly risk: RiskLevel;
34
+ readonly reason: string;
35
+ }
36
+ /** Agent interpretation of a pending turn; evidence refers only to supplied conversation sources. */
37
+ export interface IntentDecision {
38
+ readonly turnId: string;
39
+ readonly kind: "read-only" | "change" | "clarify";
40
+ readonly relation: "none" | "new" | "continue" | "follow-up" | "recall";
41
+ readonly targetTaskId?: string;
42
+ /** Semantic task association, separate from current-turn authorization evidence. */
43
+ readonly matchReason?: string;
44
+ readonly basis: "standalone" | "contextual";
45
+ readonly goal: string;
46
+ /** Required for change decisions; optional for read-only/clarify and legacy persisted entries. */
47
+ readonly routing?: RoutingDecision;
48
+ readonly paths: readonly string[];
49
+ readonly evidence: readonly {
50
+ sourceId: string;
51
+ quote: string;
52
+ }[];
53
+ readonly constraints: readonly string[];
54
+ readonly clarification?: string;
55
+ }
56
+ export type StageStatus = "pending" | "running" | "validating" | "committed" | "waiting" | "blocked" | "failed" | "interrupted" | "cancelled";
57
+ export type TaskStatus = "queued" | "running" | "completed" | "failed" | "interrupted" | "cancelled";
58
+ export interface ExecutionIdentity {
59
+ readonly taskId: string;
60
+ readonly stageId: string;
61
+ readonly attempt: number;
62
+ readonly revision: number;
63
+ readonly leaseToken: string;
64
+ }
65
+ export type StageKind = "command" | "inline-agent";
66
+ export type StagePhase = "analysis" | "implementation" | "check" | "acceptance";
67
+ export interface CommandStageDefinition {
68
+ readonly id: string;
69
+ readonly type?: "command";
70
+ readonly phase?: StagePhase;
71
+ readonly command: readonly [string, ...string[]];
72
+ readonly cwd?: string;
73
+ readonly env?: Readonly<Record<string, string>>;
74
+ }
75
+ export interface InlineAgentStageDefinition {
76
+ readonly id: string;
77
+ readonly type: "inline-agent";
78
+ readonly phase?: StagePhase;
79
+ readonly instructions?: string;
80
+ }
81
+ export type StageDefinition = CommandStageDefinition | InlineAgentStageDefinition;
82
+ export type GateStatus = "pending" | "passed" | "failed" | "blocked" | "coverage_gap" | "not_applicable";
83
+ export type AcceptanceStatus = "passed" | "failed" | "blocked" | "coverage_gap";
84
+ /** References a persisted check execution, not a model-authored evidence string. */
85
+ export interface AcceptanceEvidence {
86
+ readonly stageId: string;
87
+ readonly attempt: number;
88
+ readonly assertion: string;
89
+ }
90
+ export interface AcceptanceReport {
91
+ /** The complete original request, including authorized follow-up requests. */
92
+ readonly request: string;
93
+ readonly status: AcceptanceStatus;
94
+ /** Every listed requirement is mandatory; no implicit waivers. */
95
+ readonly requirements: readonly {
96
+ readonly requirement: string;
97
+ readonly status: AcceptanceStatus;
98
+ /** Required for passing requirements; manual reports remain review-only. */
99
+ readonly verification?: {
100
+ readonly method: "command" | "manual";
101
+ readonly scope: "whitespace" | "behavior";
102
+ readonly steps: readonly string[];
103
+ };
104
+ readonly evidence: readonly AcceptanceEvidence[];
105
+ }[];
106
+ readonly unverified: readonly string[];
107
+ }
108
+ export interface GateDefinition {
109
+ readonly id: string;
110
+ readonly required: boolean;
111
+ readonly description: string;
112
+ }
113
+ export interface Strategy {
114
+ readonly version: 1;
115
+ readonly id: string;
116
+ readonly route: RouteId;
117
+ readonly stages: readonly StageDefinition[];
118
+ readonly gates: readonly GateDefinition[];
119
+ }
120
+ export interface WorkflowDefinition {
121
+ readonly version: 1;
122
+ readonly name: string;
123
+ readonly stages: readonly StageDefinition[];
124
+ readonly gates?: readonly GateDefinition[];
125
+ }
126
+ export interface WorkspaceFileSnapshot {
127
+ readonly path: string;
128
+ readonly sha256: string;
129
+ }
130
+ export interface WorkspaceSnapshot {
131
+ readonly digest: string;
132
+ readonly files: readonly WorkspaceFileSnapshot[];
133
+ }
134
+ export interface TaskStageRecord {
135
+ readonly index: number;
136
+ readonly id: string;
137
+ readonly kind: StageKind;
138
+ readonly phase: StagePhase;
139
+ readonly status: StageStatus;
140
+ readonly attempt: number;
141
+ readonly command: readonly string[];
142
+ readonly cwd: string | null;
143
+ readonly instructions: string | null;
144
+ readonly startedAt: string | null;
145
+ readonly finishedAt: string | null;
146
+ readonly exitCode: number | null;
147
+ readonly logPath: string | null;
148
+ readonly summary: string | null;
149
+ readonly evidence: readonly string[];
150
+ readonly error: string | null;
151
+ }
152
+ export interface GateRecord {
153
+ readonly taskId: string;
154
+ readonly stageIndex: number;
155
+ readonly gateId: string;
156
+ readonly required: boolean;
157
+ readonly status: GateStatus;
158
+ readonly description: string;
159
+ readonly paths: readonly string[];
160
+ readonly workspaceDigest: string | null;
161
+ readonly details: Readonly<Record<string, unknown>>;
162
+ readonly createdAt: string;
163
+ readonly updatedAt: string;
164
+ }
165
+ export interface TaskRecord {
166
+ readonly id: string;
167
+ /** Isolates active task ownership between Pi terminal sessions. */
168
+ readonly ownerId: string;
169
+ readonly title: string;
170
+ readonly request: string;
171
+ readonly workflowName: string;
172
+ readonly workspace: string;
173
+ readonly status: TaskStatus;
174
+ readonly route: RouteId | null;
175
+ readonly strategyId: string | null;
176
+ readonly complexity: Complexity | null;
177
+ readonly risk: RiskLevel | null;
178
+ readonly scope: RouteScope;
179
+ readonly currentStageIndex: number;
180
+ readonly revision: number;
181
+ readonly planVersion: number;
182
+ readonly baselineDigest: string | null;
183
+ readonly validatedDigest: string | null;
184
+ readonly createdAt: string;
185
+ readonly updatedAt: string;
186
+ readonly stages: readonly TaskStageRecord[];
187
+ readonly gates: readonly GateRecord[];
188
+ }
189
+ export interface TaskEvent {
190
+ readonly eventId: string;
191
+ readonly sequence: number;
192
+ readonly taskId: string;
193
+ readonly type: string;
194
+ readonly payload: Readonly<Record<string, unknown>>;
195
+ readonly dedupeKey: string | null;
196
+ readonly createdAt: string;
197
+ }
198
+ export type HookKind = "transform" | "guard" | "observer" | "cleanup";
199
+ export type HookInvocationStatus = "scheduled" | "started" | "succeeded" | "blocked" | "failed" | "timed_out" | "cancelled" | "interrupted";
200
+ export interface HookInvocation {
201
+ readonly invocationId: string;
202
+ readonly taskId: string;
203
+ readonly stageId: string;
204
+ readonly attempt: number;
205
+ readonly revision: number;
206
+ readonly pluginId: string;
207
+ readonly hookName: string;
208
+ readonly kind: HookKind;
209
+ readonly inputRef: string;
210
+ readonly status: HookInvocationStatus;
211
+ readonly result: Readonly<Record<string, unknown>> | null;
212
+ readonly error: string | null;
213
+ readonly scheduledAt: string;
214
+ readonly startedAt: string | null;
215
+ readonly finishedAt: string | null;
216
+ }
217
+ export type GuardResult = {
218
+ readonly action: "continue";
219
+ } | {
220
+ readonly action: "wait";
221
+ readonly request: string;
222
+ } | {
223
+ readonly action: "block";
224
+ readonly reason: string;
225
+ };
226
+ export interface PluginDescriptor {
227
+ readonly id: string;
228
+ readonly apiVersion: typeof PIUP_API_VERSION;
229
+ readonly capabilities: readonly string[];
230
+ }
231
+ //#endregion
232
+ //# sourceMappingURL=index.d.mts.map
package/dist/index.mjs ADDED
@@ -0,0 +1,8 @@
1
+ //#region src/index.ts
2
+ const PIUP_API_VERSION = 1;
3
+ /** Tool schema generation: intent resolution, structured acceptance, recheck and read-only query. */
4
+ const PIUP_TOOL_PROTOCOL_VERSION = 2;
5
+ //#endregion
6
+ export { PIUP_API_VERSION, PIUP_TOOL_PROTOCOL_VERSION };
7
+
8
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../src/index.ts"],"sourcesContent":["export const PIUP_API_VERSION = 1 as const;\n/** Tool schema generation: intent resolution, structured acceptance, recheck and read-only query. */\nexport const PIUP_TOOL_PROTOCOL_VERSION = 2 as const;\n\nexport type RouteId = \"debug\" | \"small\" | \"standard\" | \"foundation\" | \"infra\";\nexport type RequestKind = \"read-only\" | \"change\" | \"delivery\" | \"ambiguous\";\nexport type DeliveryOperation = \"commit\" | \"push\";\nexport type RequestDisposition =\n | \"continue\"\n | \"reroute\"\n | \"follow-up\"\n | \"read-only\"\n | \"delivery\"\n | \"clarify\";\nexport type Complexity = \"low\" | \"medium\" | \"high\";\nexport type RiskLevel = \"low\" | \"medium\" | \"high\";\nexport type DispatchMode = \"inline\";\n\nexport interface RouteScope {\n /** Workspace-relative paths. A single \".\" means the whole workspace. */\n readonly paths: readonly string[];\n}\n\n/** A read-only routing decision. Producing this value must not create a task or mutate a workspace. */\nexport interface RouteResult {\n readonly requestKind: RequestKind;\n /** Explicitly authorized Git delivery operations; never implies permission to edit source. */\n readonly deliveryOperations?: readonly DeliveryOperation[];\n readonly route: RouteId | null;\n readonly complexity: Complexity | null;\n readonly risk: RiskLevel | null;\n readonly strategyId: string | null;\n readonly dispatchMode: DispatchMode;\n readonly scope: RouteScope;\n readonly reason: string;\n}\n\n/** Semantic execution plan. Strategy IDs are derived by the host, never supplied by the agent. */\nexport interface RoutingDecision {\n readonly route: RouteId;\n readonly complexity: Complexity;\n readonly risk: RiskLevel;\n readonly reason: string;\n}\n\n/** Agent interpretation of a pending turn; evidence refers only to supplied conversation sources. */\nexport interface IntentDecision {\n readonly turnId: string;\n readonly kind: \"read-only\" | \"change\" | \"clarify\";\n readonly relation: \"none\" | \"new\" | \"continue\" | \"follow-up\" | \"recall\";\n readonly targetTaskId?: string;\n /** Semantic task association, separate from current-turn authorization evidence. */\n readonly matchReason?: string;\n readonly basis: \"standalone\" | \"contextual\";\n readonly goal: string;\n /** Required for change decisions; optional for read-only/clarify and legacy persisted entries. */\n readonly routing?: RoutingDecision;\n readonly paths: readonly string[];\n readonly evidence: readonly { sourceId: string; quote: string }[];\n readonly constraints: readonly string[];\n readonly clarification?: string;\n}\n\nexport type StageStatus =\n | \"pending\"\n | \"running\"\n | \"validating\"\n | \"committed\"\n | \"waiting\"\n | \"blocked\"\n | \"failed\"\n | \"interrupted\"\n | \"cancelled\";\n\nexport type TaskStatus =\n | \"queued\"\n | \"running\"\n | \"completed\"\n | \"failed\"\n | \"interrupted\"\n | \"cancelled\";\n\nexport interface ExecutionIdentity {\n readonly taskId: string;\n readonly stageId: string;\n readonly attempt: number;\n readonly revision: number;\n readonly leaseToken: string;\n}\n\nexport type StageKind = \"command\" | \"inline-agent\";\nexport type StagePhase = \"analysis\" | \"implementation\" | \"check\" | \"acceptance\";\n\nexport interface CommandStageDefinition {\n readonly id: string;\n readonly type?: \"command\";\n readonly phase?: StagePhase;\n readonly command: readonly [string, ...string[]];\n readonly cwd?: string;\n readonly env?: Readonly<Record<string, string>>;\n}\n\nexport interface InlineAgentStageDefinition {\n readonly id: string;\n readonly type: \"inline-agent\";\n readonly phase?: StagePhase;\n readonly instructions?: string;\n}\n\nexport type StageDefinition =\n | CommandStageDefinition\n | InlineAgentStageDefinition;\n\nexport type GateStatus =\n | \"pending\"\n | \"passed\"\n | \"failed\"\n | \"blocked\"\n | \"coverage_gap\"\n | \"not_applicable\";\n\nexport type AcceptanceStatus = \"passed\" | \"failed\" | \"blocked\" | \"coverage_gap\";\n\n/** References a persisted check execution, not a model-authored evidence string. */\nexport interface AcceptanceEvidence {\n readonly stageId: string;\n readonly attempt: number;\n readonly assertion: string;\n}\n\nexport interface AcceptanceReport {\n /** The complete original request, including authorized follow-up requests. */\n readonly request: string;\n readonly status: AcceptanceStatus;\n /** Every listed requirement is mandatory; no implicit waivers. */\n readonly requirements: readonly {\n readonly requirement: string;\n readonly status: AcceptanceStatus;\n /** Required for passing requirements; manual reports remain review-only. */\n readonly verification?: {\n readonly method: \"command\" | \"manual\";\n readonly scope: \"whitespace\" | \"behavior\";\n readonly steps: readonly string[];\n };\n readonly evidence: readonly AcceptanceEvidence[];\n }[];\n readonly unverified: readonly string[];\n}\n\nexport interface GateDefinition {\n readonly id: string;\n readonly required: boolean;\n readonly description: string;\n}\n\nexport interface Strategy {\n readonly version: 1;\n readonly id: string;\n readonly route: RouteId;\n readonly stages: readonly StageDefinition[];\n readonly gates: readonly GateDefinition[];\n}\n\nexport interface WorkflowDefinition {\n readonly version: 1;\n readonly name: string;\n readonly stages: readonly StageDefinition[];\n readonly gates?: readonly GateDefinition[];\n}\n\nexport interface WorkspaceFileSnapshot {\n readonly path: string;\n readonly sha256: string;\n}\n\nexport interface WorkspaceSnapshot {\n readonly digest: string;\n readonly files: readonly WorkspaceFileSnapshot[];\n}\n\nexport interface TaskStageRecord {\n readonly index: number;\n readonly id: string;\n readonly kind: StageKind;\n readonly phase: StagePhase;\n readonly status: StageStatus;\n readonly attempt: number;\n readonly command: readonly string[];\n readonly cwd: string | null;\n readonly instructions: string | null;\n readonly startedAt: string | null;\n readonly finishedAt: string | null;\n readonly exitCode: number | null;\n readonly logPath: string | null;\n readonly summary: string | null;\n readonly evidence: readonly string[];\n readonly error: string | null;\n}\n\nexport interface GateRecord {\n readonly taskId: string;\n readonly stageIndex: number;\n readonly gateId: string;\n readonly required: boolean;\n readonly status: GateStatus;\n readonly description: string;\n readonly paths: readonly string[];\n readonly workspaceDigest: string | null;\n readonly details: Readonly<Record<string, unknown>>;\n readonly createdAt: string;\n readonly updatedAt: string;\n}\n\nexport interface TaskRecord {\n readonly id: string;\n /** Isolates active task ownership between Pi terminal sessions. */\n readonly ownerId: string;\n readonly title: string;\n readonly request: string;\n readonly workflowName: string;\n readonly workspace: string;\n readonly status: TaskStatus;\n readonly route: RouteId | null;\n readonly strategyId: string | null;\n readonly complexity: Complexity | null;\n readonly risk: RiskLevel | null;\n readonly scope: RouteScope;\n readonly currentStageIndex: number;\n readonly revision: number;\n readonly planVersion: number;\n readonly baselineDigest: string | null;\n readonly validatedDigest: string | null;\n readonly createdAt: string;\n readonly updatedAt: string;\n readonly stages: readonly TaskStageRecord[];\n readonly gates: readonly GateRecord[];\n}\n\nexport interface TaskEvent {\n readonly eventId: string;\n readonly sequence: number;\n readonly taskId: string;\n readonly type: string;\n readonly payload: Readonly<Record<string, unknown>>;\n readonly dedupeKey: string | null;\n readonly createdAt: string;\n}\n\nexport type HookKind = \"transform\" | \"guard\" | \"observer\" | \"cleanup\";\nexport type HookInvocationStatus =\n | \"scheduled\"\n | \"started\"\n | \"succeeded\"\n | \"blocked\"\n | \"failed\"\n | \"timed_out\"\n | \"cancelled\"\n | \"interrupted\";\n\nexport interface HookInvocation {\n readonly invocationId: string;\n readonly taskId: string;\n readonly stageId: string;\n readonly attempt: number;\n readonly revision: number;\n readonly pluginId: string;\n readonly hookName: string;\n readonly kind: HookKind;\n readonly inputRef: string;\n readonly status: HookInvocationStatus;\n readonly result: Readonly<Record<string, unknown>> | null;\n readonly error: string | null;\n readonly scheduledAt: string;\n readonly startedAt: string | null;\n readonly finishedAt: string | null;\n}\n\nexport type GuardResult =\n | { readonly action: \"continue\" }\n | { readonly action: \"wait\"; readonly request: string }\n | { readonly action: \"block\"; readonly reason: string };\n\nexport interface PluginDescriptor {\n readonly id: string;\n readonly apiVersion: typeof PIUP_API_VERSION;\n readonly capabilities: readonly string[];\n}\n"],"mappings":";AAAA,MAAa,mBAAmB;;AAEhC,MAAa,6BAA6B"}
package/package.json ADDED
@@ -0,0 +1,34 @@
1
+ {
2
+ "name": "@piup/contracts",
3
+ "version": "0.0.1-beta.0",
4
+ "description": "Shared TypeScript contracts for piup workflows, tasks, Gates, and plugins.",
5
+ "type": "module",
6
+ "exports": {
7
+ ".": {
8
+ "types": "./dist/index.d.mts",
9
+ "import": "./dist/index.mjs"
10
+ }
11
+ },
12
+ "files": [
13
+ "dist",
14
+ "README.md",
15
+ "LICENSE"
16
+ ],
17
+ "sideEffects": false,
18
+ "engines": {
19
+ "node": ">=22.19.0"
20
+ },
21
+ "license": "MIT",
22
+ "repository": {
23
+ "type": "git",
24
+ "url": "git+https://github.com/Keylenn/piup.git",
25
+ "directory": "packages/contracts"
26
+ },
27
+ "homepage": "https://github.com/Keylenn/piup#readme",
28
+ "bugs": {
29
+ "url": "https://github.com/Keylenn/piup/issues"
30
+ },
31
+ "publishConfig": {
32
+ "access": "public"
33
+ }
34
+ }