pi-better-background-tasks 0.2.10 → 0.2.12

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-better-background-tasks",
3
- "version": "0.2.10",
3
+ "version": "0.2.12",
4
4
  "description": "Pi extension for durable background shell tasks, watchers, logs, and status inspection.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -97,7 +97,6 @@ type NavigatorState = {
97
97
  };
98
98
 
99
99
  const GLOBAL_KEY = Symbol.for("pi-better-harness.navigator.state");
100
- const PLAN_NAVIGATION_KEY = Symbol.for("pi-better-harness.plan-navigation.state");
101
100
  const FACTORY_MARK = "__piBetterHarnessNavigatorFactory";
102
101
  const FACTORY_REFRESH = "__piBetterHarnessNavigatorRefresh";
103
102
 
@@ -121,14 +120,6 @@ function state(): NavigatorState {
121
120
  return g[GLOBAL_KEY]!;
122
121
  }
123
122
 
124
- type PlanNavigationState = { visible: boolean; releaseWorkFocus?: () => void };
125
-
126
- function planNavigationState(): PlanNavigationState {
127
- const global = globalThis as typeof globalThis & { [PLAN_NAVIGATION_KEY]?: PlanNavigationState };
128
- if (!global[PLAN_NAVIGATION_KEY]) global[PLAN_NAVIGATION_KEY] = { visible: false };
129
- return global[PLAN_NAVIGATION_KEY]!;
130
- }
131
-
132
123
  export function registerBackgroundWorkProvider(provider: BackgroundWorkProvider): () => void {
133
124
  const s = state();
134
125
  const previousUnsub = s.unsubscribers.get(provider.id);
@@ -194,7 +185,6 @@ export function ensureBackgroundWorkNavigator(ctx: ExtensionContext, deps: HostD
194
185
  s.mainListRequestRender = undefined;
195
186
  s.mainListDeadlineScheduler?.dispose();
196
187
  s.mainListDeadlineScheduler = createRenderScheduler(() => refreshMainListWidget());
197
- planNavigationState().releaseWorkFocus = unfocusMainList;
198
188
  installNavigatorEditor(ctx.ui as any, deps);
199
189
  s.lastHint = undefined;
200
190
  refreshBackgroundWorkNavigator(ctx);
@@ -223,7 +213,6 @@ export function disposeBackgroundWorkNavigator(ctx?: ExtensionContext): void {
223
213
  s.mainListRequestRender = undefined;
224
214
  s.editorComponent = undefined;
225
215
  s.detailOverlayRows = undefined;
226
- planNavigationState().releaseWorkFocus = undefined;
227
216
  s.mainListSelectedId = undefined;
228
217
  s.mainListFocused = false;
229
218
  }
@@ -471,10 +460,9 @@ function buildMainListLines(
471
460
  }
472
461
 
473
462
  function shortcutsLine(focused: boolean, fg: (color: string, value: string) => string): string {
474
- const plan = planNavigationState().visible ? " · → plan" : "";
475
463
  const keys = focused
476
- ? `↑↓ switch · Enter detail · x stop${plan} · Esc unfocus`
477
- : `← work navigator${plan}`;
464
+ ? "↑↓ switch · Enter detail · x stop · Esc unfocus"
465
+ : "← work navigator";
478
466
  return dim(keys, fg);
479
467
  }
480
468
 
package/src/tools.ts CHANGED
@@ -103,6 +103,12 @@ const StatusActionParams = Type.Object({
103
103
  verbose: Type.Optional(Type.Boolean()),
104
104
  });
105
105
 
106
+ const BACKGROUND_ORCHESTRATION_GUIDELINES = [
107
+ "Use background tasks for genuinely long-running processes or repeated checks. Run short commands in the foreground.",
108
+ "When a structured plan is active, keep it as the coordinator ledger: launch relevant background work early, continue unblocked foreground work without polling, and update the plan after inspecting each terminal result or failure.",
109
+ "Do not treat launch as completion of the parent milestone; relevant background work must be terminal, inspected, and integrated before verification or completion.",
110
+ ];
111
+
106
112
  export function registerTools(pi: ExtensionAPI): void {
107
113
  let activeSession: BackgroundTaskCallbackOrigin | undefined;
108
114
  const getActiveSession = () => activeSession;
@@ -125,6 +131,7 @@ export function registerTools(pi: ExtensionAPI): void {
125
131
  name: "bg_task_spawn",
126
132
  label: "BG Spawn",
127
133
  description: "Start a long-running background process and return immediately with its task id. For remote work, prefer structured ssh: pass ssh:{host,user} and put the remote command in command; spawn defaults to a remote tmux session with durable local logs and real remote stop. For short synchronous remote commands that should return output now, use remote_bash from pi-better-ssh. If tmux is missing, the preset attempts to install tmux non-interactively and fails closed with operator guidance when setup cannot proceed. Explicit remote.session=direct skips tmux, but direct mode has weaker stop semantics and may leave the remote process running. Never wait or poll in the foreground.",
134
+ promptGuidelines: BACKGROUND_ORCHESTRATION_GUIDELINES,
128
135
  parameters: SpawnParams,
129
136
  async execute(_toolCallId, params, _signal, _onUpdate, ctx) {
130
137
  activeSession = getCallbackOrigin(ctx);
@@ -138,6 +145,7 @@ export function registerTools(pi: ExtensionAPI): void {
138
145
  name: "bg_task_watch",
139
146
  label: "BG Watch",
140
147
  description: "Poll a command in the background until success_when, failure_when, or timeout matches. For remote work, prefer structured ssh: pass ssh:{host,user} and provide the remote command in command; each interval opens a direct one-shot SSH poll without tmux installation. For short synchronous remote commands that should return output now, use remote_bash from pi-better-ssh. Returns immediately with its task id. Default timeout 900 seconds; pass timeout_seconds:0 to disable.",
148
+ promptGuidelines: BACKGROUND_ORCHESTRATION_GUIDELINES,
141
149
  parameters: WatchParams,
142
150
  async execute(_toolCallId, params, _signal, _onUpdate, ctx) {
143
151
  activeSession = getCallbackOrigin(ctx);
@@ -198,6 +206,7 @@ export function registerTools(pi: ExtensionAPI): void {
198
206
  name: "bg_task",
199
207
  label: "BG Task",
200
208
  description: "Action wrapper for background tasks: spawn, watch, list, status, log, stop, or clear. For remote work, prefer structured ssh: pass ssh:{host,user} and provide the remote command in command. For short synchronous remote commands that should return output now, use remote_bash from pi-better-ssh. SSH spawn defaults to durable tmux; SSH watches use direct one-shot polls without tmux installation; remote.session=direct is a weaker-stop spawn escape hatch. Spawn/watch return immediately; do not poll in foreground. For action:status, default compact output and use verbose:true only for full metadata. For action:log, default compact tail and use tail_lines:0 only for explicit full logs.",
209
+ promptGuidelines: BACKGROUND_ORCHESTRATION_GUIDELINES,
201
210
  parameters: ActionParams,
202
211
  renderResult(result: unknown, options: unknown, theme: unknown) {
203
212
  return renderBackgroundTaskLogDisplay(result, options, theme);