@narumitw/pi-plan-mode 0.51.0 → 0.52.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/README.md +37 -4
- package/dist/chunks/{chunk-VMD6XCI5.ts → chunk-H3RGWRY7.ts} +53 -608
- package/dist/chunks/{chunk-VMD6XCI5.ts.map → chunk-H3RGWRY7.ts.map} +3 -3
- package/dist/chunks/{interactive-ui-ROT43QBA.ts → interactive-ui-GFNX5OF4.ts} +2 -2
- package/dist/index.ts +277 -77
- package/dist/index.ts.map +3 -3
- package/package.json +2 -2
- package/src/plan-mode.ts +233 -70
- package/src/question-tool.ts +65 -738
- package/src/workflow-mutex.ts +87 -0
- /package/dist/chunks/{interactive-ui-ROT43QBA.ts.map → interactive-ui-GFNX5OF4.ts.map} +0 -0
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
|
|
3
|
+
export const WORKFLOW_MUTEX_CHANNEL = "workflow:mutex:v1";
|
|
4
|
+
export const AGENT_WORKFLOW_GROUP = "agent-workflow";
|
|
5
|
+
|
|
6
|
+
export type WorkflowMutexOwner = symbol;
|
|
7
|
+
|
|
8
|
+
interface WorkflowMutexAttemptV1 {
|
|
9
|
+
session: object;
|
|
10
|
+
group: string;
|
|
11
|
+
busy: boolean;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export class WorkflowMutex {
|
|
15
|
+
private session: object | undefined;
|
|
16
|
+
private readonly heldGroups = new Map<string, WorkflowMutexOwner>();
|
|
17
|
+
private generation = 0;
|
|
18
|
+
|
|
19
|
+
constructor(private readonly pi: Pick<ExtensionAPI, "events">) {
|
|
20
|
+
pi.events.on(WORKFLOW_MUTEX_CHANNEL, (payload) => {
|
|
21
|
+
this.answer(payload);
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
bindSession(session: object): void {
|
|
26
|
+
this.generation += 1;
|
|
27
|
+
this.heldGroups.clear();
|
|
28
|
+
this.session = session;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
unbindSession(session: object): void {
|
|
32
|
+
if (this.session !== session) return;
|
|
33
|
+
this.generation += 1;
|
|
34
|
+
this.heldGroups.clear();
|
|
35
|
+
this.session = undefined;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
acquire(group = AGENT_WORKFLOW_GROUP): WorkflowMutexOwner | undefined {
|
|
39
|
+
const session = this.session;
|
|
40
|
+
const generation = this.generation;
|
|
41
|
+
if (!session || this.heldGroups.has(group)) return undefined;
|
|
42
|
+
|
|
43
|
+
const attempt: WorkflowMutexAttemptV1 = { session, group, busy: false };
|
|
44
|
+
try {
|
|
45
|
+
this.pi.events.emit(WORKFLOW_MUTEX_CHANNEL, attempt);
|
|
46
|
+
} catch {
|
|
47
|
+
return undefined;
|
|
48
|
+
}
|
|
49
|
+
if (
|
|
50
|
+
this.session !== session ||
|
|
51
|
+
this.generation !== generation ||
|
|
52
|
+
attempt.session !== session ||
|
|
53
|
+
attempt.group !== group ||
|
|
54
|
+
attempt.busy !== false ||
|
|
55
|
+
this.heldGroups.has(group)
|
|
56
|
+
) {
|
|
57
|
+
return undefined;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const owner = Symbol(group);
|
|
61
|
+
this.heldGroups.set(group, owner);
|
|
62
|
+
return owner;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
isOwner(owner: WorkflowMutexOwner | undefined, group = AGENT_WORKFLOW_GROUP): boolean {
|
|
66
|
+
return owner !== undefined && this.heldGroups.get(group) === owner;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
release(owner: WorkflowMutexOwner | undefined, group = AGENT_WORKFLOW_GROUP): void {
|
|
70
|
+
if (!this.isOwner(owner, group)) return;
|
|
71
|
+
this.heldGroups.delete(group);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
private answer(payload: unknown): void {
|
|
75
|
+
try {
|
|
76
|
+
if (typeof payload !== "object" || payload === null || Array.isArray(payload)) return;
|
|
77
|
+
const attempt = payload as Partial<WorkflowMutexAttemptV1>;
|
|
78
|
+
if (attempt.session !== this.session) return;
|
|
79
|
+
if (attempt.group !== AGENT_WORKFLOW_GROUP) return;
|
|
80
|
+
if (typeof attempt.busy !== "boolean") return;
|
|
81
|
+
if (!this.heldGroups.has(attempt.group)) return;
|
|
82
|
+
attempt.busy = true;
|
|
83
|
+
} catch {
|
|
84
|
+
// Protocol listeners must ignore unusual objects without interrupting sibling listeners.
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
File without changes
|