@mjasnikovs/pi-task 0.9.0 → 0.10.1

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.
@@ -0,0 +1,7 @@
1
+ export interface PiTaskConfig {
2
+ remote: boolean;
3
+ compressReasoning: boolean;
4
+ autoCommit: boolean;
5
+ }
6
+ export declare function getConfig(): PiTaskConfig;
7
+ export declare function saveConfig(config: PiTaskConfig): Promise<void>;
@@ -0,0 +1,37 @@
1
+ import * as fs from 'node:fs';
2
+ import * as fsp from 'node:fs/promises';
3
+ import * as path from 'node:path';
4
+ import * as os from 'node:os';
5
+ const DEFAULTS = {
6
+ remote: true,
7
+ compressReasoning: true,
8
+ autoCommit: true
9
+ };
10
+ const CONFIG_PATH = path.join(os.homedir(), '.config', 'pi-task', 'config.json');
11
+ const _g = globalThis;
12
+ if (!_g.__piTaskConfig) {
13
+ _g.__piTaskConfig = { config: { ...DEFAULTS }, loaded: false };
14
+ }
15
+ const G = _g.__piTaskConfig;
16
+ // Load synchronously on module evaluation so getConfig() is always ready
17
+ // before any session_start handler fires.
18
+ if (!G.loaded) {
19
+ try {
20
+ const raw = fs.readFileSync(CONFIG_PATH, 'utf8');
21
+ const parsed = JSON.parse(raw);
22
+ G.config = { ...DEFAULTS, ...parsed };
23
+ }
24
+ catch {
25
+ G.config = { ...DEFAULTS };
26
+ }
27
+ G.loaded = true;
28
+ }
29
+ export function getConfig() {
30
+ return G.config;
31
+ }
32
+ export async function saveConfig(config) {
33
+ const dir = path.dirname(CONFIG_PATH);
34
+ await fsp.mkdir(dir, { recursive: true });
35
+ await fsp.writeFile(CONFIG_PATH, JSON.stringify(config, null, 2) + '\n', 'utf8');
36
+ G.config = { ...config };
37
+ }
@@ -0,0 +1,2 @@
1
+ import type { ExtensionAPI } from '@earendil-works/pi-coding-agent';
2
+ export declare function registerConfig(pi: ExtensionAPI): void;
@@ -0,0 +1,54 @@
1
+ import { SettingsList } from '@earendil-works/pi-tui';
2
+ import { registerBridgeCommand } from '../remote/bridge.js';
3
+ import { getConfig, saveConfig } from './config.js';
4
+ const ITEMS = [
5
+ { id: 'remote', label: 'remote', description: 'Remote UI server (QR code, phone access)' },
6
+ {
7
+ id: 'compressReasoning',
8
+ label: 'compress reasoning',
9
+ description: 'Compress <think> blocks after each message'
10
+ },
11
+ {
12
+ id: 'autoCommit',
13
+ label: 'auto-commit',
14
+ description: 'git commit after each /task-auto sub-task'
15
+ }
16
+ ];
17
+ function makeTheme(theme) {
18
+ return {
19
+ label: (text, selected) => (selected ? theme.fg('accent', text) : text),
20
+ value: text => (text === 'on' ? theme.fg('success', text) : theme.fg('muted', text)),
21
+ description: text => theme.fg('muted', text),
22
+ cursor: theme.fg('accent', '>'),
23
+ hint: text => theme.fg('dim', text)
24
+ };
25
+ }
26
+ async function handleTaskConfig(_args, ctx) {
27
+ const cfg = { ...getConfig() };
28
+ if (ctx.mode !== 'tui') {
29
+ const lines = ITEMS.map(({ id, label }) => `${label.padEnd(22)} ${cfg[id] ? 'on' : 'off'}`);
30
+ ctx.ui.notify(lines.join(' | '), 'info');
31
+ return;
32
+ }
33
+ await ctx.ui.custom((_tui, theme, _kb, done) => {
34
+ const listTheme = makeTheme(theme);
35
+ const items = ITEMS.map(({ id, label, description }) => ({
36
+ id,
37
+ label,
38
+ description,
39
+ currentValue: cfg[id] ? 'on' : 'off',
40
+ values: ['on', 'off']
41
+ }));
42
+ const list = new SettingsList(items, 10, listTheme, (id, newValue) => {
43
+ cfg[id] = newValue === 'on';
44
+ saveConfig(cfg).catch(() => { });
45
+ }, () => done(undefined));
46
+ return list;
47
+ }, { overlay: true, overlayOptions: { width: 54 } });
48
+ }
49
+ export function registerConfig(pi) {
50
+ registerBridgeCommand(pi, 'task-config', {
51
+ description: 'Configure pi-task settings (remote, compress reasoning, auto-commit).',
52
+ handler: handleTaskConfig
53
+ });
54
+ }
package/dist/index.js CHANGED
@@ -1,9 +1,11 @@
1
+ import { registerConfig } from './config/register.js';
1
2
  import { registerTask } from './task/orchestrator.js';
2
3
  import { registerTaskAuto } from './task/auto-orchestrator.js';
3
4
  import { registerWorkers } from './workers/index.js';
4
5
  import { registerRemote } from './remote/register.js';
5
6
  import { registerThinkingCompression } from './thinking/compress.js';
6
7
  export default function (pi) {
8
+ registerConfig(pi);
7
9
  registerTask(pi);
8
10
  registerTaskAuto(pi);
9
11
  registerWorkers(pi);
@@ -1,3 +1,4 @@
1
+ import { getConfig } from '../config/config.js';
1
2
  import { getBridge, dispatchRemoteLine, dispatchRemoteNewSession, makeShimmedCtx } from './bridge.js';
2
3
  import { setupEvents } from './events.js';
3
4
  import { reset, addUserTurn } from './session-state.js';
@@ -61,7 +62,9 @@ export function registerRemote(pi) {
61
62
  === true) {
62
63
  bridge.currentCtx = makeShimmedCtx(ctx);
63
64
  }
64
- void ensureServer().catch(err => ctx.ui.notify(`Failed to start remote: ${err.message}`, 'error'));
65
+ if (getConfig().remote) {
66
+ void ensureServer().catch(err => ctx.ui.notify(`Failed to start remote: ${err.message}`, 'error'));
67
+ }
65
68
  });
66
69
  pi.on('session_shutdown', (event, _ctx) => {
67
70
  if (event.reason === 'quit') {
@@ -76,8 +79,12 @@ export function registerRemote(pi) {
76
79
  }
77
80
  });
78
81
  pi.registerCommand('remote', {
79
- description: 'Show the remote QR code & URLs (the server is always running)',
82
+ description: 'Show the remote QR code & URLs.',
80
83
  handler: async (args, ctx) => {
84
+ if (!getConfig().remote) {
85
+ ctx.ui.notify('Remote is disabled — enable it in /task-config.', 'info');
86
+ return;
87
+ }
81
88
  if (args.trim() === 'stop') {
82
89
  if (S.server) {
83
90
  const port = S.server.port;
@@ -16,6 +16,7 @@ import { writeTaskFile, readTaskFile, updateTaskFrontMatter } from './task-io.js
16
16
  import { gitCommitAll } from './auto-commit.js';
17
17
  import { runPhaseChild, USER_CANCELLED } from './child-runner.js';
18
18
  import { SessionUI, registerBridgeCommand } from '../remote/bridge.js';
19
+ import { getConfig } from '../config/config.js';
19
20
  import { startAutoLoader } from './widget.js';
20
21
  // Matches pi's @-file completion token (a path after @, until whitespace).
21
22
  const MENTION_RE = /(?:^|\s)@([^\s]+)/g;
@@ -181,7 +182,9 @@ function defaultDeps(ctx, cwd, signal, title) {
181
182
  resumeId: opts?.resumeId,
182
183
  onStart: opts?.onStart
183
184
  }),
184
- commit: (cwd2, message) => gitCommitAll(cwd2, message, signal)
185
+ commit: (cwd2, message) => getConfig().autoCommit ?
186
+ gitCommitAll(cwd2, message, signal)
187
+ : Promise.resolve({ committed: false, reason: 'auto-commit disabled' })
185
188
  };
186
189
  }
187
190
  // ─── Loop ────────────────────────────────────────────────────────────────────
@@ -22,7 +22,6 @@ export interface ClarifyQuestion {
22
22
  }
23
23
  export declare const GRILL_LINE_RE: RegExp;
24
24
  export declare const SUGGESTED_LINE_RE: RegExp;
25
- export declare const TITLE_MAX_CHARS = 120;
26
25
  export declare function parseVerifyBlock(spec: string): VerifyCommand[] | null;
27
26
  export declare function parseGrillQuestions(raw: string): string[];
28
27
  export declare function parseClarifyList(raw: string): ClarifyQuestion[];
@@ -7,7 +7,6 @@ import { MAX_GRILL_QUESTIONS } from './phases.js';
7
7
  // ─── Constants ───────────────────────────────────────────────────────────────
8
8
  export const GRILL_LINE_RE = /^\s*\d+[.)]\s+(.+)$/;
9
9
  export const SUGGESTED_LINE_RE = /^\s*SUGGESTED:\s*(.*)$/i;
10
- export const TITLE_MAX_CHARS = 120;
11
10
  // ─── Verify block parser ─────────────────────────────────────────────────────
12
11
  export function parseVerifyBlock(spec) {
13
12
  const lines = spec.split('\n');
@@ -222,9 +221,7 @@ export function deriveTitle(refined) {
222
221
  const headerCheck = line.replace(/^#+\s+/, '');
223
222
  if (/^(CONSTRAINTS|KNOWN-UNKNOWNS)\s*:?\s*$/i.test(headerCheck))
224
223
  break;
225
- return line.length > TITLE_MAX_CHARS ?
226
- line.slice(0, TITLE_MAX_CHARS - 1) + '…'
227
- : line;
224
+ return line;
228
225
  }
229
226
  break;
230
227
  }
@@ -236,7 +233,7 @@ export function deriveTitle(refined) {
236
233
  line = line.replace(/^#+\s+/, '').replace(/^GOAL\s*:?\s*/i, '');
237
234
  if (line.length === 0)
238
235
  continue;
239
- return line.length > TITLE_MAX_CHARS ? line.slice(0, TITLE_MAX_CHARS - 1) + '…' : line;
236
+ return line;
240
237
  }
241
238
  return '(untitled)';
242
239
  }
@@ -1,3 +1,4 @@
1
+ import { getConfig } from '../config/config.js';
1
2
  import { collectCompressible, MIN_THINKING_CHARS, rebuildWithCompressed } from './rewrite.js';
2
3
  /** Hard cap so a stuck model request can never wedge a turn. */
3
4
  const REQUEST_TIMEOUT_MS = 120_000;
@@ -72,6 +73,8 @@ async function resolveAuth(ctx, model) {
72
73
  const pct = (from, to) => Math.round((100 * (from - to)) / from);
73
74
  export function registerThinkingCompression(pi) {
74
75
  pi.on('message_end', async (event, ctx) => {
76
+ if (!getConfig().compressReasoning)
77
+ return;
75
78
  const message = event.message;
76
79
  const targets = collectCompressible(message, MIN_THINKING_CHARS);
77
80
  if (targets.length === 0)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mjasnikovs/pi-task",
3
- "version": "0.9.0",
3
+ "version": "0.10.1",
4
4
  "description": "Deterministic spec-orchestration for local models, with a bundled real-time remote web view and web/docs/fetch/worker subagent tools.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",