@mjasnikovs/pi-task 0.9.0 → 0.10.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.
@@ -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 ────────────────────────────────────────────────────────────────────
@@ -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.0",
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",