@maolon/pi-watcher 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +18 -0
- package/LICENSE +21 -0
- package/README.md +255 -2
- package/dist/cli.d.ts +8 -0
- package/dist/cli.js +369 -0
- package/dist/contracts/interfaces.d.ts +262 -0
- package/dist/contracts/interfaces.js +1 -0
- package/dist/contracts/policy-defaults.json +61 -0
- package/dist/contracts/relay-next.interfaces.d.ts +160 -0
- package/dist/contracts/relay-next.interfaces.js +1 -0
- package/dist/engine/cards.d.ts +68 -0
- package/dist/engine/cards.js +76 -0
- package/dist/engine/engine.d.ts +178 -0
- package/dist/engine/engine.js +1162 -0
- package/dist/engine/hard-rules.d.ts +53 -0
- package/dist/engine/hard-rules.js +96 -0
- package/dist/engine/semantic.d.ts +49 -0
- package/dist/engine/semantic.js +125 -0
- package/dist/engine/service.d.ts +62 -0
- package/dist/engine/service.js +587 -0
- package/dist/engine/tool-actions.d.ts +35 -0
- package/dist/engine/tool-actions.js +348 -0
- package/dist/engine/widget.d.ts +29 -0
- package/dist/engine/widget.js +52 -0
- package/dist/ipc/client.d.ts +26 -0
- package/dist/ipc/client.js +106 -0
- package/dist/ipc/server.d.ts +78 -0
- package/dist/ipc/server.js +105 -0
- package/dist/jev/client.d.ts +38 -0
- package/dist/jev/client.js +239 -0
- package/dist/jev/consent.d.ts +12 -0
- package/dist/jev/consent.js +37 -0
- package/dist/jev/index.d.ts +9 -0
- package/dist/jev/index.js +9 -0
- package/dist/jev/mock.d.ts +30 -0
- package/dist/jev/mock.js +77 -0
- package/dist/jev/pi-registry.d.ts +66 -0
- package/dist/jev/pi-registry.js +127 -0
- package/dist/jev/questions.d.ts +15 -0
- package/dist/jev/questions.js +76 -0
- package/dist/jev/sanitizer.d.ts +10 -0
- package/dist/jev/sanitizer.js +59 -0
- package/dist/jev/types.d.ts +78 -0
- package/dist/jev/types.js +54 -0
- package/dist/pi-extension.d.ts +123 -0
- package/dist/pi-extension.js +687 -0
- package/dist/relay/managed.d.ts +120 -0
- package/dist/relay/managed.js +482 -0
- package/dist/relay/negotiate.d.ts +39 -0
- package/dist/relay/negotiate.js +112 -0
- package/dist/runtime.d.ts +74 -0
- package/dist/runtime.js +246 -0
- package/dist/source/agent-check/adapter.d.ts +57 -0
- package/dist/source/agent-check/adapter.js +224 -0
- package/dist/source/agent-file/adapter.d.ts +57 -0
- package/dist/source/agent-file/adapter.js +217 -0
- package/dist/source/task-status-v1/adapter.d.ts +36 -0
- package/dist/source/task-status-v1/adapter.js +263 -0
- package/dist/source/task-status-v1/producer.d.ts +81 -0
- package/dist/source/task-status-v1/producer.js +127 -0
- package/dist/storage/lock.d.ts +14 -0
- package/dist/storage/lock.js +66 -0
- package/dist/storage/schema.sql +166 -0
- package/dist/storage/store.d.ts +352 -0
- package/dist/storage/store.js +555 -0
- package/dist/util/clock.d.ts +23 -0
- package/dist/util/clock.js +34 -0
- package/dist/util/ids.d.ts +8 -0
- package/dist/util/ids.js +29 -0
- package/dist/util/result.d.ts +28 -0
- package/dist/util/result.js +54 -0
- package/package.json +101 -4
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Standard tool/service result envelope and error codes (design 11.4).
|
|
3
|
+
*/
|
|
4
|
+
export type WatcherErrorCode = 'INVALID_SPEC' | 'STALE_REVISION' | 'UNKNOWN_TARGET' | 'CAPABILITY_DENIED' | 'SOURCE_UNAVAILABLE' | 'BUDGET_EXHAUSTED' | 'STORE_UNAVAILABLE' | 'ADMISSION_UNKNOWN' | 'DEPENDENCY_UNQUALIFIED' | 'ROOT_LOCK_HELD' | 'NO_DELIVERY' | 'REQUEST_CONFLICT';
|
|
5
|
+
export declare class WatcherError extends Error {
|
|
6
|
+
readonly code: WatcherErrorCode;
|
|
7
|
+
readonly exitCode: number;
|
|
8
|
+
constructor(code: WatcherErrorCode, message: string);
|
|
9
|
+
}
|
|
10
|
+
export interface OkResult<T> {
|
|
11
|
+
ok: true;
|
|
12
|
+
requestId?: string;
|
|
13
|
+
value: T;
|
|
14
|
+
}
|
|
15
|
+
export interface ErrResult {
|
|
16
|
+
ok: false;
|
|
17
|
+
requestId?: string;
|
|
18
|
+
error: {
|
|
19
|
+
code: WatcherErrorCode;
|
|
20
|
+
message: string;
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
export type ServiceResult<T> = OkResult<T> | ErrResult;
|
|
24
|
+
export declare function ok<T>(value: T, requestId?: string): OkResult<T>;
|
|
25
|
+
export declare function err(code: WatcherErrorCode, message: string, requestId?: string): ErrResult;
|
|
26
|
+
export declare function toServiceResult<T>(requestId: string | undefined, fn: () => T): ServiceResult<T>;
|
|
27
|
+
/** Async version: fn may be async; a thrown error object may carry a code field (lightweight tool-layer error). */
|
|
28
|
+
export declare function toServiceResultAsync<T>(requestId: string | undefined, fn: () => Promise<T> | T): Promise<ServiceResult<T>>;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Standard tool/service result envelope and error codes (design 11.4).
|
|
3
|
+
*/
|
|
4
|
+
export class WatcherError extends Error {
|
|
5
|
+
code;
|
|
6
|
+
exitCode;
|
|
7
|
+
constructor(code, message) {
|
|
8
|
+
super(message);
|
|
9
|
+
this.name = 'WatcherError';
|
|
10
|
+
this.code = code;
|
|
11
|
+
// CLI exit code mapping (design 11.4): 2 invalid input; 3 permission/qualification; 4 delivery unknown; 5 local dependency/storage
|
|
12
|
+
this.exitCode =
|
|
13
|
+
code === 'INVALID_SPEC' || code === 'UNKNOWN_TARGET' ? 2
|
|
14
|
+
: code === 'ADMISSION_UNKNOWN' ? 4
|
|
15
|
+
: code === 'STORE_UNAVAILABLE' || code === 'ROOT_LOCK_HELD' ? 5
|
|
16
|
+
: 3;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
export function ok(value, requestId) {
|
|
20
|
+
return { ok: true, requestId, value };
|
|
21
|
+
}
|
|
22
|
+
export function err(code, message, requestId) {
|
|
23
|
+
return { ok: false, requestId, error: { code, message } };
|
|
24
|
+
}
|
|
25
|
+
export function toServiceResult(requestId, fn) {
|
|
26
|
+
try {
|
|
27
|
+
return ok(fn(), requestId);
|
|
28
|
+
}
|
|
29
|
+
catch (e) {
|
|
30
|
+
if (e instanceof WatcherError) {
|
|
31
|
+
return err(e.code, e.message, requestId);
|
|
32
|
+
}
|
|
33
|
+
const message = e instanceof Error ? e.message : String(e);
|
|
34
|
+
return err('STORE_UNAVAILABLE', `unexpected failure: ${message}`, requestId);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
/** Async version: fn may be async; a thrown error object may carry a code field (lightweight tool-layer error). */
|
|
38
|
+
export async function toServiceResultAsync(requestId, fn) {
|
|
39
|
+
try {
|
|
40
|
+
const value = await fn();
|
|
41
|
+
return ok(value, requestId);
|
|
42
|
+
}
|
|
43
|
+
catch (e) {
|
|
44
|
+
if (e instanceof WatcherError) {
|
|
45
|
+
return err(e.code, e.message, requestId);
|
|
46
|
+
}
|
|
47
|
+
const anyE = e;
|
|
48
|
+
if (typeof anyE?.code === 'string') {
|
|
49
|
+
return err(anyE.code, anyE.message ?? 'error', requestId);
|
|
50
|
+
}
|
|
51
|
+
const message = e instanceof Error ? e.message : String(e);
|
|
52
|
+
return err('STORE_UNAVAILABLE', `unexpected failure: ${message}`, requestId);
|
|
53
|
+
}
|
|
54
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,103 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@maolon/pi-watcher",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Watch long-running Pi tasks without babysitting: deterministic task monitoring, optional semantic review, and relay-delivered wakes only when something needs the host.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"pi-package",
|
|
7
|
+
"pi",
|
|
8
|
+
"pi-extension",
|
|
9
|
+
"pi-coding-agent",
|
|
10
|
+
"watcher",
|
|
11
|
+
"monitoring",
|
|
12
|
+
"long-running-tasks",
|
|
13
|
+
"agents"
|
|
14
|
+
],
|
|
15
|
+
"homepage": "https://github.com/Maolon/pi-watcher#readme",
|
|
16
|
+
"bugs": {
|
|
17
|
+
"url": "https://github.com/Maolon/pi-watcher/issues"
|
|
18
|
+
},
|
|
19
|
+
"repository": {
|
|
20
|
+
"type": "git",
|
|
21
|
+
"url": "git+https://github.com/Maolon/pi-watcher.git"
|
|
22
|
+
},
|
|
23
|
+
"license": "MIT",
|
|
24
|
+
"author": "Maolon",
|
|
25
|
+
"type": "module",
|
|
26
|
+
"main": "./dist/pi-extension.js",
|
|
27
|
+
"types": "./dist/pi-extension.d.ts",
|
|
28
|
+
"exports": {
|
|
29
|
+
".": {
|
|
30
|
+
"types": "./dist/pi-extension.d.ts",
|
|
31
|
+
"import": "./dist/pi-extension.js",
|
|
32
|
+
"default": "./dist/pi-extension.js"
|
|
33
|
+
},
|
|
34
|
+
"./package.json": "./package.json"
|
|
35
|
+
},
|
|
36
|
+
"bin": {
|
|
37
|
+
"pi-watcher": "dist/cli.js"
|
|
38
|
+
},
|
|
39
|
+
"files": [
|
|
40
|
+
"dist",
|
|
41
|
+
"README.md",
|
|
42
|
+
"LICENSE",
|
|
43
|
+
"CHANGELOG.md"
|
|
44
|
+
],
|
|
45
|
+
"pi": {
|
|
46
|
+
"extensions": [
|
|
47
|
+
"./dist/pi-extension.js"
|
|
48
|
+
]
|
|
49
|
+
},
|
|
50
|
+
"engines": {
|
|
51
|
+
"node": ">=22.16.0"
|
|
52
|
+
},
|
|
53
|
+
"os": [
|
|
54
|
+
"darwin",
|
|
55
|
+
"linux"
|
|
56
|
+
],
|
|
57
|
+
"publishConfig": {
|
|
58
|
+
"access": "public",
|
|
59
|
+
"provenance": true,
|
|
60
|
+
"registry": "https://registry.npmjs.org/"
|
|
61
|
+
},
|
|
62
|
+
"scripts": {
|
|
63
|
+
"build": "rm -rf dist && tsc -p tsconfig.build.json && node scripts/copy-assets.mjs",
|
|
64
|
+
"typecheck": "tsc --noEmit",
|
|
65
|
+
"test": "tsx --test tests/jev/*.test.ts tests/storage/*.test.ts tests/source/*.test.ts tests/relay/*.test.ts tests/engine/*.test.ts tests/*.test.ts",
|
|
66
|
+
"test:unit": "tsx --test tests/storage/*.test.ts tests/source/*.test.ts tests/relay/*.test.ts tests/engine/*.test.ts",
|
|
67
|
+
"test:jev": "tsx --test tests/jev/*.test.ts",
|
|
68
|
+
"test:jev:unit": "tsx --test tests/jev/sanitizer.test.ts tests/jev/mock-judge.test.ts tests/jev/client-unit.test.ts tests/jev/pi-registry.test.ts",
|
|
69
|
+
"test:jev:live": "tsx --test tests/jev/client-live.test.ts",
|
|
70
|
+
"test:package": "node scripts/package-smoke.mjs",
|
|
71
|
+
"qualify": "tsx src/cli.ts qualify",
|
|
72
|
+
"doctor": "tsx src/cli.ts doctor",
|
|
73
|
+
"demo": "tsx src/cli.ts demo",
|
|
74
|
+
"prepublishOnly": "npm run typecheck && npm run build && npm run test:package"
|
|
75
|
+
},
|
|
76
|
+
"dependencies": {
|
|
77
|
+
"@maolon/pi-relay": "^0.2.0",
|
|
78
|
+
"better-sqlite3": "13.0.3",
|
|
79
|
+
"fs-ext": "2.1.1"
|
|
80
|
+
},
|
|
81
|
+
"peerDependencies": {
|
|
82
|
+
"@earendil-works/pi-coding-agent": "*",
|
|
83
|
+
"typebox": "*"
|
|
84
|
+
},
|
|
85
|
+
"peerDependenciesMeta": {
|
|
86
|
+
"@earendil-works/pi-coding-agent": {
|
|
87
|
+
"optional": true
|
|
88
|
+
},
|
|
89
|
+
"typebox": {
|
|
90
|
+
"optional": true
|
|
91
|
+
}
|
|
92
|
+
},
|
|
93
|
+
"devDependencies": {
|
|
94
|
+
"@types/better-sqlite3": "^9.6.0",
|
|
95
|
+
"@types/node": "^22.20.4",
|
|
96
|
+
"tsx": "^4.23.13",
|
|
97
|
+
"typebox": "^1.3.34",
|
|
98
|
+
"typescript": "^5.7.3"
|
|
99
|
+
},
|
|
100
|
+
"allowScripts": {
|
|
101
|
+
"better-sqlite3@13.0.3": true
|
|
102
|
+
}
|
|
103
|
+
}
|