@ilya-lesikov/pi-pi 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/3p/pi-ask-user/index.ts +1835 -0
- package/3p/pi-ask-user/package.json +50 -0
- package/3p/pi-ask-user/single-select-layout.ts +203 -0
- package/3p/pi-lsp/extensions/lsp/client.ts +542 -0
- package/3p/pi-lsp/extensions/lsp/config.ts +135 -0
- package/3p/pi-lsp/extensions/lsp/effects/command.ts +42 -0
- package/3p/pi-lsp/extensions/lsp/effects/filesystem.ts +50 -0
- package/3p/pi-lsp/extensions/lsp/effects/runtime.ts +21 -0
- package/3p/pi-lsp/extensions/lsp/errors.ts +113 -0
- package/3p/pi-lsp/extensions/lsp/formatting.ts +315 -0
- package/3p/pi-lsp/extensions/lsp/index.ts +231 -0
- package/3p/pi-lsp/extensions/lsp/protocol.ts +209 -0
- package/3p/pi-lsp/extensions/lsp/retry.ts +39 -0
- package/3p/pi-lsp/extensions/lsp/tools/programs.ts +293 -0
- package/3p/pi-lsp/extensions/lsp/tools.ts +89 -0
- package/3p/pi-lsp/extensions/lsp/types.ts +243 -0
- package/3p/pi-lsp/package.json +54 -0
- package/3p/pi-plannotator/AGENTS.md +583 -0
- package/3p/pi-plannotator/apps/pi-extension/README.md +228 -0
- package/3p/pi-plannotator/apps/pi-extension/assistant-message.ts +128 -0
- package/3p/pi-plannotator/apps/pi-extension/config.test.ts +166 -0
- package/3p/pi-plannotator/apps/pi-extension/config.ts +318 -0
- package/3p/pi-plannotator/apps/pi-extension/current-pi-session.ts +147 -0
- package/3p/pi-plannotator/apps/pi-extension/index.ts +1279 -0
- package/3p/pi-plannotator/apps/pi-extension/package.json +56 -0
- package/3p/pi-plannotator/apps/pi-extension/plannotator-browser.test.ts +13 -0
- package/3p/pi-plannotator/apps/pi-extension/plannotator-browser.ts +616 -0
- package/3p/pi-plannotator/apps/pi-extension/plannotator-events.ts +342 -0
- package/3p/pi-plannotator/apps/pi-extension/plannotator.json +12 -0
- package/3p/pi-plannotator/apps/pi-extension/server/agent-jobs.ts +515 -0
- package/3p/pi-plannotator/apps/pi-extension/server/ai-runtime.ts +169 -0
- package/3p/pi-plannotator/apps/pi-extension/server/annotations.ts +85 -0
- package/3p/pi-plannotator/apps/pi-extension/server/external-annotations.ts +189 -0
- package/3p/pi-plannotator/apps/pi-extension/server/handlers.ts +210 -0
- package/3p/pi-plannotator/apps/pi-extension/server/helpers.ts +78 -0
- package/3p/pi-plannotator/apps/pi-extension/server/ide.ts +46 -0
- package/3p/pi-plannotator/apps/pi-extension/server/integrations.ts +195 -0
- package/3p/pi-plannotator/apps/pi-extension/server/network.test.ts +158 -0
- package/3p/pi-plannotator/apps/pi-extension/server/network.ts +268 -0
- package/3p/pi-plannotator/apps/pi-extension/server/pr.ts +126 -0
- package/3p/pi-plannotator/apps/pi-extension/server/project.ts +64 -0
- package/3p/pi-plannotator/apps/pi-extension/server/reference.ts +362 -0
- package/3p/pi-plannotator/apps/pi-extension/server/serverAnnotate.ts +199 -0
- package/3p/pi-plannotator/apps/pi-extension/server/serverPlan.ts +505 -0
- package/3p/pi-plannotator/apps/pi-extension/server/serverReview.ts +1229 -0
- package/3p/pi-plannotator/apps/pi-extension/server/vcs.ts +121 -0
- package/3p/pi-plannotator/apps/pi-extension/server.test.ts +966 -0
- package/3p/pi-plannotator/apps/pi-extension/server.ts +44 -0
- package/3p/pi-plannotator/apps/pi-extension/tool-scope.test.ts +88 -0
- package/3p/pi-plannotator/apps/pi-extension/tool-scope.ts +39 -0
- package/3p/pi-plannotator/apps/pi-extension/tsconfig.json +16 -0
- package/3p/pi-plannotator/apps/pi-extension/vendor.sh +48 -0
- package/3p/pi-plannotator/package.json +53 -0
- package/3p/pi-plannotator/packages/ai/ai.test.ts +1407 -0
- package/3p/pi-plannotator/packages/ai/base-session.ts +94 -0
- package/3p/pi-plannotator/packages/ai/context.ts +250 -0
- package/3p/pi-plannotator/packages/ai/endpoints.ts +326 -0
- package/3p/pi-plannotator/packages/ai/index.ts +105 -0
- package/3p/pi-plannotator/packages/ai/package.json +21 -0
- package/3p/pi-plannotator/packages/ai/provider.ts +103 -0
- package/3p/pi-plannotator/packages/ai/providers/claude-agent-sdk.ts +447 -0
- package/3p/pi-plannotator/packages/ai/providers/codex-sdk.ts +430 -0
- package/3p/pi-plannotator/packages/ai/providers/command-path.ts +115 -0
- package/3p/pi-plannotator/packages/ai/providers/opencode-sdk.ts +546 -0
- package/3p/pi-plannotator/packages/ai/providers/pi-events.ts +110 -0
- package/3p/pi-plannotator/packages/ai/providers/pi-sdk-node.ts +425 -0
- package/3p/pi-plannotator/packages/ai/providers/pi-sdk.ts +469 -0
- package/3p/pi-plannotator/packages/ai/session-manager.ts +195 -0
- package/3p/pi-plannotator/packages/ai/tsconfig.json +15 -0
- package/3p/pi-plannotator/packages/ai/types.ts +379 -0
- package/3p/pi-plannotator/packages/server/agent-jobs.ts +538 -0
- package/3p/pi-plannotator/packages/server/agent-review-message.test.ts +135 -0
- package/3p/pi-plannotator/packages/server/agent-review-message.ts +243 -0
- package/3p/pi-plannotator/packages/server/ai-runtime.ts +108 -0
- package/3p/pi-plannotator/packages/server/annotate.ts +401 -0
- package/3p/pi-plannotator/packages/server/browser.test.ts +87 -0
- package/3p/pi-plannotator/packages/server/browser.ts +245 -0
- package/3p/pi-plannotator/packages/server/claude-review.ts +352 -0
- package/3p/pi-plannotator/packages/server/code-nav.ts +73 -0
- package/3p/pi-plannotator/packages/server/codex-review-schema.json +41 -0
- package/3p/pi-plannotator/packages/server/codex-review.ts +330 -0
- package/3p/pi-plannotator/packages/server/config.ts +8 -0
- package/3p/pi-plannotator/packages/server/draft.ts +1 -0
- package/3p/pi-plannotator/packages/server/editor-annotations.ts +76 -0
- package/3p/pi-plannotator/packages/server/external-annotations.test.ts +18 -0
- package/3p/pi-plannotator/packages/server/external-annotations.ts +207 -0
- package/3p/pi-plannotator/packages/server/git.ts +141 -0
- package/3p/pi-plannotator/packages/server/goal-setup.test.ts +55 -0
- package/3p/pi-plannotator/packages/server/goal-setup.ts +248 -0
- package/3p/pi-plannotator/packages/server/ide.ts +43 -0
- package/3p/pi-plannotator/packages/server/image.test.ts +63 -0
- package/3p/pi-plannotator/packages/server/image.ts +66 -0
- package/3p/pi-plannotator/packages/server/index.ts +648 -0
- package/3p/pi-plannotator/packages/server/integrations.test.ts +172 -0
- package/3p/pi-plannotator/packages/server/integrations.ts +214 -0
- package/3p/pi-plannotator/packages/server/jj.test.ts +69 -0
- package/3p/pi-plannotator/packages/server/jj.ts +86 -0
- package/3p/pi-plannotator/packages/server/p4.ts +417 -0
- package/3p/pi-plannotator/packages/server/package.json +40 -0
- package/3p/pi-plannotator/packages/server/path-utils.ts +18 -0
- package/3p/pi-plannotator/packages/server/pr.ts +146 -0
- package/3p/pi-plannotator/packages/server/project.test.ts +115 -0
- package/3p/pi-plannotator/packages/server/project.ts +45 -0
- package/3p/pi-plannotator/packages/server/reference-handlers.ts +404 -0
- package/3p/pi-plannotator/packages/server/remote.test.ts +150 -0
- package/3p/pi-plannotator/packages/server/remote.ts +74 -0
- package/3p/pi-plannotator/packages/server/repo.ts +80 -0
- package/3p/pi-plannotator/packages/server/resolve-file.test.ts +310 -0
- package/3p/pi-plannotator/packages/server/review-workspace.test.ts +1032 -0
- package/3p/pi-plannotator/packages/server/review-workspace.ts +48 -0
- package/3p/pi-plannotator/packages/server/review.ts +1318 -0
- package/3p/pi-plannotator/packages/server/sessions.ts +111 -0
- package/3p/pi-plannotator/packages/server/share-url.ts +53 -0
- package/3p/pi-plannotator/packages/server/shared-handlers.test.ts +43 -0
- package/3p/pi-plannotator/packages/server/shared-handlers.ts +177 -0
- package/3p/pi-plannotator/packages/server/storage.test.ts +176 -0
- package/3p/pi-plannotator/packages/server/storage.ts +17 -0
- package/3p/pi-plannotator/packages/server/tour/tour-review.test.ts +146 -0
- package/3p/pi-plannotator/packages/server/tour/tour-review.ts +604 -0
- package/3p/pi-plannotator/packages/server/tsconfig.json +15 -0
- package/3p/pi-plannotator/packages/server/vcs.test.ts +48 -0
- package/3p/pi-plannotator/packages/server/vcs.ts +80 -0
- package/3p/pi-plannotator/packages/shared/agent-jobs.ts +132 -0
- package/3p/pi-plannotator/packages/shared/agents.ts +53 -0
- package/3p/pi-plannotator/packages/shared/annotate-args.test.ts +386 -0
- package/3p/pi-plannotator/packages/shared/annotate-args.ts +107 -0
- package/3p/pi-plannotator/packages/shared/at-reference.test.ts +99 -0
- package/3p/pi-plannotator/packages/shared/at-reference.ts +52 -0
- package/3p/pi-plannotator/packages/shared/checklist.ts +52 -0
- package/3p/pi-plannotator/packages/shared/code-file.test.ts +112 -0
- package/3p/pi-plannotator/packages/shared/code-file.ts +41 -0
- package/3p/pi-plannotator/packages/shared/code-nav.test.ts +515 -0
- package/3p/pi-plannotator/packages/shared/code-nav.ts +436 -0
- package/3p/pi-plannotator/packages/shared/compress.ts +51 -0
- package/3p/pi-plannotator/packages/shared/config.ts +262 -0
- package/3p/pi-plannotator/packages/shared/crypto.test.ts +172 -0
- package/3p/pi-plannotator/packages/shared/crypto.ts +97 -0
- package/3p/pi-plannotator/packages/shared/data-dir.ts +42 -0
- package/3p/pi-plannotator/packages/shared/diff-paths.test.ts +30 -0
- package/3p/pi-plannotator/packages/shared/diff-paths.ts +137 -0
- package/3p/pi-plannotator/packages/shared/draft.ts +64 -0
- package/3p/pi-plannotator/packages/shared/external-annotation.ts +397 -0
- package/3p/pi-plannotator/packages/shared/extract-code-paths.test.ts +59 -0
- package/3p/pi-plannotator/packages/shared/extract-code-paths.ts +66 -0
- package/3p/pi-plannotator/packages/shared/favicon.ts +5 -0
- package/3p/pi-plannotator/packages/shared/feedback-templates.test.ts +65 -0
- package/3p/pi-plannotator/packages/shared/feedback-templates.ts +29 -0
- package/3p/pi-plannotator/packages/shared/goal-setup.test.ts +231 -0
- package/3p/pi-plannotator/packages/shared/goal-setup.ts +336 -0
- package/3p/pi-plannotator/packages/shared/html-to-markdown.test.ts +62 -0
- package/3p/pi-plannotator/packages/shared/html-to-markdown.ts +32 -0
- package/3p/pi-plannotator/packages/shared/improvement-hooks.test.ts +135 -0
- package/3p/pi-plannotator/packages/shared/improvement-hooks.ts +115 -0
- package/3p/pi-plannotator/packages/shared/integrations-common.ts +243 -0
- package/3p/pi-plannotator/packages/shared/jj-core.test.ts +236 -0
- package/3p/pi-plannotator/packages/shared/jj-core.ts +433 -0
- package/3p/pi-plannotator/packages/shared/package.json +55 -0
- package/3p/pi-plannotator/packages/shared/pfm-reminder.test.ts +88 -0
- package/3p/pi-plannotator/packages/shared/pfm-reminder.ts +80 -0
- package/3p/pi-plannotator/packages/shared/pr-github.ts +661 -0
- package/3p/pi-plannotator/packages/shared/pr-gitlab.test.ts +202 -0
- package/3p/pi-plannotator/packages/shared/pr-gitlab.ts +620 -0
- package/3p/pi-plannotator/packages/shared/pr-provider.test.ts +266 -0
- package/3p/pi-plannotator/packages/shared/pr-provider.ts +123 -0
- package/3p/pi-plannotator/packages/shared/pr-stack.test.ts +104 -0
- package/3p/pi-plannotator/packages/shared/pr-stack.ts +194 -0
- package/3p/pi-plannotator/packages/shared/pr-types.ts +326 -0
- package/3p/pi-plannotator/packages/shared/project.ts +71 -0
- package/3p/pi-plannotator/packages/shared/prompts-integration.test.ts +421 -0
- package/3p/pi-plannotator/packages/shared/prompts.test.ts +504 -0
- package/3p/pi-plannotator/packages/shared/prompts.ts +247 -0
- package/3p/pi-plannotator/packages/shared/reference-common.ts +87 -0
- package/3p/pi-plannotator/packages/shared/repo.ts +71 -0
- package/3p/pi-plannotator/packages/shared/resolve-file.test.ts +113 -0
- package/3p/pi-plannotator/packages/shared/resolve-file.ts +509 -0
- package/3p/pi-plannotator/packages/shared/review-args.test.ts +64 -0
- package/3p/pi-plannotator/packages/shared/review-args.ts +85 -0
- package/3p/pi-plannotator/packages/shared/review-core.test.ts +286 -0
- package/3p/pi-plannotator/packages/shared/review-core.ts +895 -0
- package/3p/pi-plannotator/packages/shared/review-workspace-node.ts +230 -0
- package/3p/pi-plannotator/packages/shared/review-workspace.ts +436 -0
- package/3p/pi-plannotator/packages/shared/semantic-diff-types.ts +76 -0
- package/3p/pi-plannotator/packages/shared/semantic-diff.test.ts +322 -0
- package/3p/pi-plannotator/packages/shared/semantic-diff.ts +520 -0
- package/3p/pi-plannotator/packages/shared/storage.ts +378 -0
- package/3p/pi-plannotator/packages/shared/tour.ts +61 -0
- package/3p/pi-plannotator/packages/shared/tsconfig.json +15 -0
- package/3p/pi-plannotator/packages/shared/types.ts +29 -0
- package/3p/pi-plannotator/packages/shared/url-to-markdown.test.ts +177 -0
- package/3p/pi-plannotator/packages/shared/url-to-markdown.ts +351 -0
- package/3p/pi-plannotator/packages/shared/vcs-core.test.ts +332 -0
- package/3p/pi-plannotator/packages/shared/vcs-core.ts +482 -0
- package/3p/pi-plannotator/packages/shared/worktree-pool.test.ts +162 -0
- package/3p/pi-plannotator/packages/shared/worktree-pool.ts +103 -0
- package/3p/pi-plannotator/packages/shared/worktree.ts +119 -0
- package/3p/pi-subagents/package.json +50 -0
- package/3p/pi-subagents/src/agent-manager.ts +413 -0
- package/3p/pi-subagents/src/agent-runner.ts +502 -0
- package/3p/pi-subagents/src/agent-types.ts +248 -0
- package/3p/pi-subagents/src/context.ts +58 -0
- package/3p/pi-subagents/src/cross-extension-rpc.ts +135 -0
- package/3p/pi-subagents/src/custom-agents.ts +137 -0
- package/3p/pi-subagents/src/default-agents.ts +144 -0
- package/3p/pi-subagents/src/env.ts +33 -0
- package/3p/pi-subagents/src/group-join.ts +141 -0
- package/3p/pi-subagents/src/index.ts +1811 -0
- package/3p/pi-subagents/src/invocation-config.ts +40 -0
- package/3p/pi-subagents/src/memory.ts +165 -0
- package/3p/pi-subagents/src/model-resolver.ts +81 -0
- package/3p/pi-subagents/src/output-file.ts +77 -0
- package/3p/pi-subagents/src/prompts.ts +85 -0
- package/3p/pi-subagents/src/skill-loader.ts +79 -0
- package/3p/pi-subagents/src/types.ts +111 -0
- package/3p/pi-subagents/src/ui/agent-widget.ts +496 -0
- package/3p/pi-subagents/src/ui/conversation-viewer.ts +250 -0
- package/3p/pi-subagents/src/worktree.ts +162 -0
- package/3p/pi-tasks/package.json +52 -0
- package/3p/pi-tasks/src/auto-clear.ts +91 -0
- package/3p/pi-tasks/src/index.ts +1150 -0
- package/3p/pi-tasks/src/process-tracker.ts +140 -0
- package/3p/pi-tasks/src/reminder-cadence.ts +90 -0
- package/3p/pi-tasks/src/task-store.ts +324 -0
- package/3p/pi-tasks/src/tasks-config.ts +27 -0
- package/3p/pi-tasks/src/types.ts +40 -0
- package/3p/pi-tasks/src/ui/settings-menu.ts +152 -0
- package/3p/pi-tasks/src/ui/task-widget.ts +296 -0
- package/AGENTS.md +28 -0
- package/LICENSE +201 -0
- package/extensions/orchestrator/agents/brainstorm-reviewer.ts +77 -0
- package/extensions/orchestrator/agents/code-reviewer.ts +89 -0
- package/extensions/orchestrator/agents/explore.ts +33 -0
- package/extensions/orchestrator/agents/librarian.ts +43 -0
- package/extensions/orchestrator/agents/plan-reviewer.ts +75 -0
- package/extensions/orchestrator/agents/planner.ts +61 -0
- package/extensions/orchestrator/agents/registry.ts +156 -0
- package/extensions/orchestrator/agents/task.ts +50 -0
- package/extensions/orchestrator/agents/tool-routing.ts +84 -0
- package/extensions/orchestrator/ast-search.ts +85 -0
- package/extensions/orchestrator/cbm.ts +330 -0
- package/extensions/orchestrator/command-handlers.test.ts +163 -0
- package/extensions/orchestrator/command-handlers.ts +116 -0
- package/extensions/orchestrator/commands.test.ts +81 -0
- package/extensions/orchestrator/commands.ts +75 -0
- package/extensions/orchestrator/config.test.ts +221 -0
- package/extensions/orchestrator/config.ts +230 -0
- package/extensions/orchestrator/context.test.ts +293 -0
- package/extensions/orchestrator/context.ts +206 -0
- package/extensions/orchestrator/event-handlers.test.ts +190 -0
- package/extensions/orchestrator/event-handlers.ts +1416 -0
- package/extensions/orchestrator/exa.ts +104 -0
- package/extensions/orchestrator/flant-infra.ts +486 -0
- package/extensions/orchestrator/index.ts +80 -0
- package/extensions/orchestrator/integration.test.ts +1214 -0
- package/extensions/orchestrator/orchestrator.test.ts +252 -0
- package/extensions/orchestrator/orchestrator.ts +538 -0
- package/extensions/orchestrator/phases/brainstorm.test.ts +15 -0
- package/extensions/orchestrator/phases/brainstorm.ts +273 -0
- package/extensions/orchestrator/phases/implementation.ts +40 -0
- package/extensions/orchestrator/phases/machine.test.ts +293 -0
- package/extensions/orchestrator/phases/machine.ts +209 -0
- package/extensions/orchestrator/phases/planning.ts +255 -0
- package/extensions/orchestrator/phases/review.ts +193 -0
- package/extensions/orchestrator/plannotator.ts +56 -0
- package/extensions/orchestrator/pp-menu.ts +866 -0
- package/extensions/orchestrator/state.test.ts +343 -0
- package/extensions/orchestrator/state.ts +237 -0
- package/extensions/orchestrator/validate-artifacts.test.ts +88 -0
- package/extensions/orchestrator/validate-artifacts.ts +272 -0
- package/extensions/orchestrator/vendor.d.ts +26 -0
- package/package.json +73 -0
- package/scripts/postinstall.sh +18 -0
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* process-tracker.ts — Background process management for tasks.
|
|
3
|
+
*
|
|
4
|
+
* Tracks spawned child processes, buffers their output, and supports
|
|
5
|
+
* blocking wait and graceful stop (SIGTERM → 5s → SIGKILL).
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import type { ChildProcess } from "node:child_process";
|
|
9
|
+
import type { BackgroundProcess } from "./types.js";
|
|
10
|
+
|
|
11
|
+
export interface ProcessOutput {
|
|
12
|
+
output: string;
|
|
13
|
+
status: BackgroundProcess["status"];
|
|
14
|
+
exitCode?: number;
|
|
15
|
+
startedAt: number;
|
|
16
|
+
completedAt?: number;
|
|
17
|
+
command?: string;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export class ProcessTracker {
|
|
21
|
+
private processes = new Map<string, BackgroundProcess>();
|
|
22
|
+
|
|
23
|
+
/** Register a spawned process for a task. */
|
|
24
|
+
track(taskId: string, proc: ChildProcess, command?: string): void {
|
|
25
|
+
const bp: BackgroundProcess = {
|
|
26
|
+
taskId,
|
|
27
|
+
pid: proc.pid!,
|
|
28
|
+
command,
|
|
29
|
+
output: [],
|
|
30
|
+
status: "running",
|
|
31
|
+
startedAt: Date.now(),
|
|
32
|
+
proc,
|
|
33
|
+
abortController: new AbortController(),
|
|
34
|
+
waiters: [],
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
// Buffer stdout
|
|
38
|
+
proc.stdout?.on("data", (data: Buffer) => {
|
|
39
|
+
bp.output.push(data.toString());
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
// Buffer stderr
|
|
43
|
+
proc.stderr?.on("data", (data: Buffer) => {
|
|
44
|
+
bp.output.push(data.toString());
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
// Handle process exit
|
|
48
|
+
proc.on("close", (code, _signal) => {
|
|
49
|
+
if (bp.status === "running") {
|
|
50
|
+
bp.status = code === 0 ? "completed" : "error";
|
|
51
|
+
}
|
|
52
|
+
bp.exitCode = code ?? undefined;
|
|
53
|
+
bp.completedAt = Date.now();
|
|
54
|
+
// Notify all waiters
|
|
55
|
+
for (const resolve of bp.waiters) resolve();
|
|
56
|
+
bp.waiters = [];
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
proc.on("error", (err) => {
|
|
60
|
+
if (bp.status === "running") {
|
|
61
|
+
bp.status = "error";
|
|
62
|
+
bp.output.push(`Process error: ${err.message}`);
|
|
63
|
+
bp.completedAt = Date.now();
|
|
64
|
+
for (const resolve of bp.waiters) resolve();
|
|
65
|
+
bp.waiters = [];
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
this.processes.set(taskId, bp);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** Get current output and status for a task's process. */
|
|
73
|
+
getOutput(taskId: string): ProcessOutput | undefined {
|
|
74
|
+
const bp = this.processes.get(taskId);
|
|
75
|
+
if (!bp) return undefined;
|
|
76
|
+
return {
|
|
77
|
+
output: bp.output.join(""),
|
|
78
|
+
status: bp.status,
|
|
79
|
+
exitCode: bp.exitCode,
|
|
80
|
+
startedAt: bp.startedAt,
|
|
81
|
+
completedAt: bp.completedAt,
|
|
82
|
+
command: bp.command,
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/** Wait for a task's process to complete, with timeout. */
|
|
87
|
+
waitForCompletion(taskId: string, timeout: number, signal?: AbortSignal): Promise<ProcessOutput | undefined> {
|
|
88
|
+
const bp = this.processes.get(taskId);
|
|
89
|
+
if (!bp) return Promise.resolve(undefined);
|
|
90
|
+
if (bp.status !== "running") return Promise.resolve(this.getOutput(taskId));
|
|
91
|
+
|
|
92
|
+
return new Promise<ProcessOutput | undefined>((resolve) => {
|
|
93
|
+
let settled = false;
|
|
94
|
+
const timer = setTimeout(finish, timeout);
|
|
95
|
+
|
|
96
|
+
function finish() {
|
|
97
|
+
if (settled) return;
|
|
98
|
+
settled = true;
|
|
99
|
+
clearTimeout(timer);
|
|
100
|
+
resolve(self.getOutput(taskId));
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
const self = this;
|
|
104
|
+
bp.waiters.push(finish);
|
|
105
|
+
signal?.addEventListener("abort", finish, { once: true });
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/** Stop a task's background process. SIGTERM → 5s → SIGKILL. */
|
|
110
|
+
async stop(taskId: string): Promise<boolean> {
|
|
111
|
+
const bp = this.processes.get(taskId);
|
|
112
|
+
if (!bp || bp.status !== "running") return false;
|
|
113
|
+
|
|
114
|
+
bp.status = "stopped";
|
|
115
|
+
bp.proc.kill("SIGTERM");
|
|
116
|
+
|
|
117
|
+
// Wait up to 5s for graceful exit
|
|
118
|
+
await new Promise<void>((resolve) => {
|
|
119
|
+
const timer = setTimeout(() => {
|
|
120
|
+
try { bp.proc.kill("SIGKILL"); } catch { /* already dead */ }
|
|
121
|
+
resolve();
|
|
122
|
+
}, 5000);
|
|
123
|
+
|
|
124
|
+
bp.proc.on("close", () => {
|
|
125
|
+
clearTimeout(timer);
|
|
126
|
+
resolve();
|
|
127
|
+
});
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
bp.completedAt = Date.now();
|
|
131
|
+
for (const resolve of bp.waiters) resolve();
|
|
132
|
+
bp.waiters = [];
|
|
133
|
+
return true;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/** Get the process record for a task. */
|
|
137
|
+
getProcess(taskId: string): BackgroundProcess | undefined {
|
|
138
|
+
return this.processes.get(taskId);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure cadence logic for the system-reminder injection.
|
|
3
|
+
*
|
|
4
|
+
* Decisions are made here as plain functions so they're easy to unit-test
|
|
5
|
+
* without spinning up the whole extension. The default export of the
|
|
6
|
+
* extension wires these into the `tool_result` and `context` hooks.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
/** Internal cadence state. Plain object so it round-trips through tests. */
|
|
10
|
+
export interface CadenceState {
|
|
11
|
+
currentTurn: number;
|
|
12
|
+
lastTaskToolUseTurn: number;
|
|
13
|
+
reminderInjectedThisCycle: boolean;
|
|
14
|
+
reminderDue: boolean;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface CadenceConfig {
|
|
18
|
+
/** Turns without a task-tool call before a reminder is considered due. */
|
|
19
|
+
reminderInterval: number;
|
|
20
|
+
/** Set of tool names that count as "task tool usage" and reset cadence. */
|
|
21
|
+
taskToolNames: ReadonlySet<string>;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function createCadenceState(): CadenceState {
|
|
25
|
+
return {
|
|
26
|
+
currentTurn: 0,
|
|
27
|
+
lastTaskToolUseTurn: 0,
|
|
28
|
+
reminderInjectedThisCycle: false,
|
|
29
|
+
reminderDue: false,
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function resetCadenceState(state: CadenceState): void {
|
|
34
|
+
state.currentTurn = 0;
|
|
35
|
+
state.lastTaskToolUseTurn = 0;
|
|
36
|
+
state.reminderInjectedThisCycle = false;
|
|
37
|
+
state.reminderDue = false;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** Increment the turn counter at `turn_start`. */
|
|
41
|
+
export function onTurnStart(state: CadenceState): void {
|
|
42
|
+
state.currentTurn++;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export interface ToolResultDecision {
|
|
46
|
+
/** True when caller should mark `reminderDue` for the next `context` event. */
|
|
47
|
+
markDue: boolean;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Decide what cadence change a tool_result implies. Mutates `state` in place
|
|
52
|
+
* (resets the timer when a task tool was used) and returns whether the
|
|
53
|
+
* reminder should be queued for the next LLM call.
|
|
54
|
+
*/
|
|
55
|
+
export function evaluateToolResult(
|
|
56
|
+
state: CadenceState,
|
|
57
|
+
toolName: string,
|
|
58
|
+
hasTasks: boolean,
|
|
59
|
+
config: CadenceConfig,
|
|
60
|
+
): ToolResultDecision {
|
|
61
|
+
// Task tool usage resets cadence and clears any pending reminder.
|
|
62
|
+
if (config.taskToolNames.has(toolName)) {
|
|
63
|
+
state.lastTaskToolUseTurn = state.currentTurn;
|
|
64
|
+
state.reminderInjectedThisCycle = false;
|
|
65
|
+
state.reminderDue = false;
|
|
66
|
+
return { markDue: false };
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// Cheap guards first.
|
|
70
|
+
if (state.currentTurn - state.lastTaskToolUseTurn < config.reminderInterval) {
|
|
71
|
+
return { markDue: false };
|
|
72
|
+
}
|
|
73
|
+
if (state.reminderInjectedThisCycle) return { markDue: false };
|
|
74
|
+
if (!hasTasks) return { markDue: false };
|
|
75
|
+
|
|
76
|
+
state.reminderDue = true;
|
|
77
|
+
return { markDue: true };
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Drain the pending reminder when `context` fires. Returns true if the
|
|
82
|
+
* caller should inject the reminder into the upcoming LLM call's messages.
|
|
83
|
+
*/
|
|
84
|
+
export function drainReminderForContext(state: CadenceState): boolean {
|
|
85
|
+
if (!state.reminderDue) return false;
|
|
86
|
+
state.reminderDue = false;
|
|
87
|
+
state.reminderInjectedThisCycle = true;
|
|
88
|
+
state.lastTaskToolUseTurn = state.currentTurn;
|
|
89
|
+
return true;
|
|
90
|
+
}
|
|
@@ -0,0 +1,324 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* task-store.ts — File-backed task store with CRUD, dependency management, and file locking.
|
|
3
|
+
*
|
|
4
|
+
* Session-scoped (default): in-memory Map — no disk I/O.
|
|
5
|
+
* Shared (PI_TASK_LIST_ID set): ~/.pi/tasks/<listId>.json with file locking.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { existsSync, mkdirSync, readFileSync, renameSync, unlinkSync, writeFileSync } from "node:fs";
|
|
9
|
+
import { homedir } from "node:os";
|
|
10
|
+
import { dirname, isAbsolute, join } from "node:path";
|
|
11
|
+
import type { Task, TaskStatus, TaskStoreData } from "./types.js";
|
|
12
|
+
|
|
13
|
+
function sortById(a: Task, b: Task): number {
|
|
14
|
+
return Number(a.id) - Number(b.id);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function sortByStatus(a: Task, b: Task): number {
|
|
18
|
+
const rank = (s: string) => s === "completed" ? 0 : s === "in_progress" ? 1 : 2;
|
|
19
|
+
return rank(a.status) - rank(b.status) || Number(a.id) - Number(b.id);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function sortByRecent(a: Task, b: Task): number {
|
|
23
|
+
return b.updatedAt - a.updatedAt || Number(b.id) - Number(a.id);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function sortByOldest(a: Task, b: Task): number {
|
|
27
|
+
return a.updatedAt - b.updatedAt || Number(a.id) - Number(b.id);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const SORT_FNS = { id: sortById, status: sortByStatus, recent: sortByRecent, oldest: sortByOldest };
|
|
31
|
+
|
|
32
|
+
const TASKS_DIR = join(homedir(), ".pi", "tasks");
|
|
33
|
+
const LOCK_RETRY_MS = 50;
|
|
34
|
+
const LOCK_MAX_RETRIES = 100; // 5s max
|
|
35
|
+
|
|
36
|
+
/** Simple file-based locking. */
|
|
37
|
+
function acquireLock(lockPath: string): void {
|
|
38
|
+
for (let i = 0; i < LOCK_MAX_RETRIES; i++) {
|
|
39
|
+
try {
|
|
40
|
+
// O_EXCL: fail if file exists
|
|
41
|
+
writeFileSync(lockPath, `${process.pid}`, { flag: "wx" });
|
|
42
|
+
return;
|
|
43
|
+
} catch (e: any) {
|
|
44
|
+
if (e.code === "EEXIST") {
|
|
45
|
+
// Check for stale lock (process no longer running)
|
|
46
|
+
try {
|
|
47
|
+
const pid = parseInt(readFileSync(lockPath, "utf-8"), 10);
|
|
48
|
+
if (pid && !isProcessRunning(pid)) {
|
|
49
|
+
unlinkSync(lockPath);
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
} catch { /* ignore read errors */ }
|
|
53
|
+
// Wait and retry
|
|
54
|
+
const start = Date.now();
|
|
55
|
+
while (Date.now() - start < LOCK_RETRY_MS) { /* busy wait */ }
|
|
56
|
+
continue;
|
|
57
|
+
}
|
|
58
|
+
throw e;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
throw new Error(`Failed to acquire lock: ${lockPath}`);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function releaseLock(lockPath: string): void {
|
|
65
|
+
try { unlinkSync(lockPath); } catch { /* ignore */ }
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function isProcessRunning(pid: number): boolean {
|
|
69
|
+
try { process.kill(pid, 0); return true; } catch { return false; }
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export class TaskStore {
|
|
73
|
+
private filePath: string | undefined;
|
|
74
|
+
private lockPath: string | undefined;
|
|
75
|
+
|
|
76
|
+
// In-memory state (always kept in sync)
|
|
77
|
+
private nextId = 1;
|
|
78
|
+
private tasks = new Map<string, Task>();
|
|
79
|
+
|
|
80
|
+
constructor(listIdOrPath?: string) {
|
|
81
|
+
if (!listIdOrPath) return;
|
|
82
|
+
const isAbsPath = isAbsolute(listIdOrPath);
|
|
83
|
+
const filePath = isAbsPath ? listIdOrPath : join(TASKS_DIR, `${listIdOrPath}.json`);
|
|
84
|
+
mkdirSync(dirname(filePath), { recursive: true });
|
|
85
|
+
this.filePath = filePath;
|
|
86
|
+
this.lockPath = filePath + ".lock";
|
|
87
|
+
this.load();
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/** Read store from disk (file-backed mode only). */
|
|
91
|
+
private load(): void {
|
|
92
|
+
if (!this.filePath) return;
|
|
93
|
+
if (!existsSync(this.filePath)) return;
|
|
94
|
+
try {
|
|
95
|
+
const data: TaskStoreData = JSON.parse(readFileSync(this.filePath, "utf-8"));
|
|
96
|
+
this.nextId = data.nextId;
|
|
97
|
+
this.tasks.clear();
|
|
98
|
+
for (const t of data.tasks) {
|
|
99
|
+
this.tasks.set(t.id, t);
|
|
100
|
+
}
|
|
101
|
+
} catch { /* corrupt file — start fresh */ }
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/** Write store to disk atomically (file-backed mode only). */
|
|
105
|
+
private save(): void {
|
|
106
|
+
if (!this.filePath) return;
|
|
107
|
+
const data: TaskStoreData = {
|
|
108
|
+
nextId: this.nextId,
|
|
109
|
+
tasks: Array.from(this.tasks.values()),
|
|
110
|
+
};
|
|
111
|
+
const tmpPath = this.filePath + ".tmp";
|
|
112
|
+
writeFileSync(tmpPath, JSON.stringify(data, null, 2));
|
|
113
|
+
renameSync(tmpPath, this.filePath);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/** Execute a mutation with file locking (if file-backed). */
|
|
117
|
+
private withLock<T>(fn: () => T): T {
|
|
118
|
+
if (!this.lockPath) return fn();
|
|
119
|
+
acquireLock(this.lockPath);
|
|
120
|
+
try {
|
|
121
|
+
this.load(); // Re-read latest state
|
|
122
|
+
const result = fn();
|
|
123
|
+
this.save();
|
|
124
|
+
return result;
|
|
125
|
+
} finally {
|
|
126
|
+
releaseLock(this.lockPath);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
create(subject: string, description: string, activeForm?: string, metadata?: Record<string, any>): Task {
|
|
131
|
+
return this.withLock(() => {
|
|
132
|
+
const now = Date.now();
|
|
133
|
+
const task: Task = {
|
|
134
|
+
id: String(this.nextId++),
|
|
135
|
+
subject,
|
|
136
|
+
description,
|
|
137
|
+
status: "pending",
|
|
138
|
+
activeForm,
|
|
139
|
+
owner: undefined,
|
|
140
|
+
metadata: metadata ?? {},
|
|
141
|
+
blocks: [],
|
|
142
|
+
blockedBy: [],
|
|
143
|
+
createdAt: now,
|
|
144
|
+
updatedAt: now,
|
|
145
|
+
};
|
|
146
|
+
this.tasks.set(task.id, task);
|
|
147
|
+
return task;
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
get(id: string): Task | undefined {
|
|
152
|
+
if (this.filePath) this.load();
|
|
153
|
+
return this.tasks.get(id);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/** List all tasks, sorted by the given order (defaults to ID ascending). */
|
|
157
|
+
list(sortOrder: "id" | "status" | "recent" | "oldest" = "id"): Task[] {
|
|
158
|
+
if (this.filePath) this.load();
|
|
159
|
+
return Array.from(this.tasks.values()).sort(SORT_FNS[sortOrder]);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
update(id: string, fields: {
|
|
163
|
+
status?: TaskStatus | "deleted";
|
|
164
|
+
subject?: string;
|
|
165
|
+
description?: string;
|
|
166
|
+
activeForm?: string;
|
|
167
|
+
owner?: string;
|
|
168
|
+
metadata?: Record<string, any>;
|
|
169
|
+
addBlocks?: string[];
|
|
170
|
+
addBlockedBy?: string[];
|
|
171
|
+
}): { task: Task | undefined; changedFields: string[]; warnings: string[] } {
|
|
172
|
+
return this.withLock(() => {
|
|
173
|
+
const task = this.tasks.get(id);
|
|
174
|
+
if (!task) return { task: undefined, changedFields: [], warnings: [] };
|
|
175
|
+
|
|
176
|
+
const changedFields: string[] = [];
|
|
177
|
+
const warnings: string[] = [];
|
|
178
|
+
|
|
179
|
+
// Handle deletion
|
|
180
|
+
if (fields.status === "deleted") {
|
|
181
|
+
this.tasks.delete(id);
|
|
182
|
+
// Clean up dependency edges pointing to this task
|
|
183
|
+
for (const t of this.tasks.values()) {
|
|
184
|
+
t.blocks = t.blocks.filter(bid => bid !== id);
|
|
185
|
+
t.blockedBy = t.blockedBy.filter(bid => bid !== id);
|
|
186
|
+
}
|
|
187
|
+
return { task: undefined, changedFields: ["deleted"], warnings: [] };
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
if (fields.status !== undefined) {
|
|
191
|
+
task.status = fields.status;
|
|
192
|
+
changedFields.push("status");
|
|
193
|
+
}
|
|
194
|
+
if (fields.subject !== undefined) {
|
|
195
|
+
task.subject = fields.subject;
|
|
196
|
+
changedFields.push("subject");
|
|
197
|
+
}
|
|
198
|
+
if (fields.description !== undefined) {
|
|
199
|
+
task.description = fields.description;
|
|
200
|
+
changedFields.push("description");
|
|
201
|
+
}
|
|
202
|
+
if (fields.activeForm !== undefined) {
|
|
203
|
+
task.activeForm = fields.activeForm;
|
|
204
|
+
changedFields.push("activeForm");
|
|
205
|
+
}
|
|
206
|
+
if (fields.owner !== undefined) {
|
|
207
|
+
task.owner = fields.owner;
|
|
208
|
+
changedFields.push("owner");
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
// Metadata: shallow merge, null deletes keys
|
|
212
|
+
if (fields.metadata !== undefined) {
|
|
213
|
+
for (const [key, value] of Object.entries(fields.metadata)) {
|
|
214
|
+
if (value === null) {
|
|
215
|
+
delete task.metadata[key];
|
|
216
|
+
} else {
|
|
217
|
+
task.metadata[key] = value;
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
changedFields.push("metadata");
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
// Bidirectional dependency edges
|
|
224
|
+
if (fields.addBlocks && fields.addBlocks.length > 0) {
|
|
225
|
+
for (const targetId of fields.addBlocks) {
|
|
226
|
+
if (!task.blocks.includes(targetId)) {
|
|
227
|
+
task.blocks.push(targetId);
|
|
228
|
+
}
|
|
229
|
+
const target = this.tasks.get(targetId);
|
|
230
|
+
if (target && !target.blockedBy.includes(id)) {
|
|
231
|
+
target.blockedBy.push(id);
|
|
232
|
+
target.updatedAt = Date.now();
|
|
233
|
+
}
|
|
234
|
+
// Warnings for problematic edges
|
|
235
|
+
if (targetId === id) {
|
|
236
|
+
warnings.push(`#${id} blocks itself`);
|
|
237
|
+
} else if (!target) {
|
|
238
|
+
warnings.push(`#${targetId} does not exist`);
|
|
239
|
+
} else if (target.blocks.includes(id)) {
|
|
240
|
+
warnings.push(`cycle: #${id} and #${targetId} block each other`);
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
changedFields.push("blocks");
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
if (fields.addBlockedBy && fields.addBlockedBy.length > 0) {
|
|
247
|
+
for (const targetId of fields.addBlockedBy) {
|
|
248
|
+
if (!task.blockedBy.includes(targetId)) {
|
|
249
|
+
task.blockedBy.push(targetId);
|
|
250
|
+
}
|
|
251
|
+
const target = this.tasks.get(targetId);
|
|
252
|
+
if (target && !target.blocks.includes(id)) {
|
|
253
|
+
target.blocks.push(id);
|
|
254
|
+
target.updatedAt = Date.now();
|
|
255
|
+
}
|
|
256
|
+
// Warnings for problematic edges
|
|
257
|
+
if (targetId === id) {
|
|
258
|
+
warnings.push(`#${id} blocks itself`);
|
|
259
|
+
} else if (!target) {
|
|
260
|
+
warnings.push(`#${targetId} does not exist`);
|
|
261
|
+
} else if (task.blocks.includes(targetId)) {
|
|
262
|
+
warnings.push(`cycle: #${id} and #${targetId} block each other`);
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
changedFields.push("blockedBy");
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
task.updatedAt = Date.now();
|
|
269
|
+
return { task, changedFields, warnings };
|
|
270
|
+
});
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
/** Delete a task by ID. Returns true if deleted. */
|
|
274
|
+
delete(id: string): boolean {
|
|
275
|
+
return this.withLock(() => {
|
|
276
|
+
if (!this.tasks.has(id)) return false;
|
|
277
|
+
this.tasks.delete(id);
|
|
278
|
+
// Clean up dependency edges
|
|
279
|
+
for (const t of this.tasks.values()) {
|
|
280
|
+
t.blocks = t.blocks.filter(bid => bid !== id);
|
|
281
|
+
t.blockedBy = t.blockedBy.filter(bid => bid !== id);
|
|
282
|
+
}
|
|
283
|
+
return true;
|
|
284
|
+
});
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
/** Remove all tasks. */
|
|
288
|
+
clearAll(): number {
|
|
289
|
+
return this.withLock(() => {
|
|
290
|
+
const count = this.tasks.size;
|
|
291
|
+
this.tasks.clear();
|
|
292
|
+
return count;
|
|
293
|
+
});
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
/** Delete the backing file (if file-backed and empty). */
|
|
297
|
+
deleteFileIfEmpty(): boolean {
|
|
298
|
+
if (!this.filePath || this.tasks.size > 0) return false;
|
|
299
|
+
try { unlinkSync(this.filePath); } catch { /* ignore */ }
|
|
300
|
+
return true;
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
/** Remove all completed tasks. */
|
|
304
|
+
clearCompleted(): number {
|
|
305
|
+
return this.withLock(() => {
|
|
306
|
+
let count = 0;
|
|
307
|
+
for (const [id, task] of this.tasks) {
|
|
308
|
+
if (task.status === "completed") {
|
|
309
|
+
this.tasks.delete(id);
|
|
310
|
+
count++;
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
// Clean up dependency edges for deleted tasks
|
|
314
|
+
if (count > 0) {
|
|
315
|
+
const validIds = new Set(this.tasks.keys());
|
|
316
|
+
for (const t of this.tasks.values()) {
|
|
317
|
+
t.blocks = t.blocks.filter(bid => validIds.has(bid));
|
|
318
|
+
t.blockedBy = t.blockedBy.filter(bid => validIds.has(bid));
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
return count;
|
|
322
|
+
});
|
|
323
|
+
}
|
|
324
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// <cwd>/.pi/tasks-config.json — persists extension settings across sessions
|
|
2
|
+
|
|
3
|
+
import { mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
4
|
+
import { dirname, join } from "node:path";
|
|
5
|
+
|
|
6
|
+
export interface TasksConfig {
|
|
7
|
+
taskScope?: "memory" | "session" | "project"; // default: "session"
|
|
8
|
+
autoCascade?: boolean; // default: false
|
|
9
|
+
autoClearCompleted?: "never" | "on_list_complete" | "on_task_complete"; // default: "on_list_complete"
|
|
10
|
+
showAll?: boolean; // default: false
|
|
11
|
+
maxVisible?: number; // default: 10
|
|
12
|
+
sortOrder?: "id" | "status" | "recent" | "oldest"; // default: "id"
|
|
13
|
+
hiddenAt?: "top" | "bottom"; // default: "bottom"
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const CONFIG_PATH = join(process.cwd(), ".pi", "tasks-config.json");
|
|
17
|
+
|
|
18
|
+
export function loadTasksConfig(): TasksConfig {
|
|
19
|
+
try {
|
|
20
|
+
return JSON.parse(readFileSync(CONFIG_PATH, "utf-8"));
|
|
21
|
+
} catch { return {}; }
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function saveTasksConfig(config: TasksConfig): void {
|
|
25
|
+
mkdirSync(dirname(CONFIG_PATH), { recursive: true });
|
|
26
|
+
writeFileSync(CONFIG_PATH, JSON.stringify(config, null, 2));
|
|
27
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* types.ts — Type definitions for the task management system.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
export type TaskStatus = "pending" | "in_progress" | "completed";
|
|
6
|
+
|
|
7
|
+
export interface Task {
|
|
8
|
+
id: string;
|
|
9
|
+
subject: string;
|
|
10
|
+
description: string;
|
|
11
|
+
status: TaskStatus;
|
|
12
|
+
activeForm?: string;
|
|
13
|
+
owner?: string;
|
|
14
|
+
metadata: Record<string, any>;
|
|
15
|
+
blocks: string[];
|
|
16
|
+
blockedBy: string[];
|
|
17
|
+
createdAt: number;
|
|
18
|
+
updatedAt: number;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** Serialized store format on disk. */
|
|
22
|
+
export interface TaskStoreData {
|
|
23
|
+
nextId: number;
|
|
24
|
+
tasks: Task[];
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** Background process associated with a task. */
|
|
28
|
+
export interface BackgroundProcess {
|
|
29
|
+
taskId: string;
|
|
30
|
+
pid: number;
|
|
31
|
+
command?: string;
|
|
32
|
+
output: string[];
|
|
33
|
+
status: "running" | "completed" | "error" | "stopped";
|
|
34
|
+
exitCode?: number;
|
|
35
|
+
startedAt: number;
|
|
36
|
+
completedAt?: number;
|
|
37
|
+
proc: import("node:child_process").ChildProcess;
|
|
38
|
+
abortController: AbortController;
|
|
39
|
+
waiters: Array<() => void>;
|
|
40
|
+
}
|