pal-code 0.0.5

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.
Files changed (73) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +169 -0
  3. package/SYSTEM.md +146 -0
  4. package/bin/pal-code.js +131 -0
  5. package/package.json +68 -0
  6. package/packages/cli/README.md +77 -0
  7. package/packages/cli/src/agent-panel.ts +94 -0
  8. package/packages/cli/src/commands/ext.ts +79 -0
  9. package/packages/cli/src/commands/mcp-registry.ts +136 -0
  10. package/packages/cli/src/commands/mcp.ts +186 -0
  11. package/packages/cli/src/commands.ts +153 -0
  12. package/packages/cli/src/components/message-box.ts +35 -0
  13. package/packages/cli/src/components/permission-prompt.ts +185 -0
  14. package/packages/cli/src/components/render-history.ts +143 -0
  15. package/packages/cli/src/components/run-view.ts +256 -0
  16. package/packages/cli/src/components/sidebar.ts +120 -0
  17. package/packages/cli/src/components/status-line.ts +26 -0
  18. package/packages/cli/src/config.ts +107 -0
  19. package/packages/cli/src/index.ts +1606 -0
  20. package/packages/cli/src/overlays/key-input.ts +167 -0
  21. package/packages/cli/src/overlays/model-picker.ts +106 -0
  22. package/packages/cli/src/overlays/session-picker.ts +168 -0
  23. package/packages/cli/src/overlays/wizard.ts +145 -0
  24. package/packages/cli/src/state.ts +133 -0
  25. package/packages/cli/src/theme.ts +88 -0
  26. package/packages/cli/src/turn.ts +266 -0
  27. package/packages/cli/src/utils/cost.ts +111 -0
  28. package/packages/cli/src/utils/format.test.ts +167 -0
  29. package/packages/cli/src/utils/format.ts +248 -0
  30. package/packages/cli/src/utils/highlight.ts +358 -0
  31. package/packages/cli/src/utils/permissions.ts +196 -0
  32. package/packages/core/src/agent/events.ts +36 -0
  33. package/packages/core/src/agent/fallback.test.ts +99 -0
  34. package/packages/core/src/agent/fallback.ts +344 -0
  35. package/packages/core/src/agent/index.ts +35 -0
  36. package/packages/core/src/agent/protocol.test.ts +136 -0
  37. package/packages/core/src/agent/resume-compaction.test.ts +116 -0
  38. package/packages/core/src/agent/roles.ts +188 -0
  39. package/packages/core/src/agent/run.test.ts +207 -0
  40. package/packages/core/src/agent/run.ts +713 -0
  41. package/packages/core/src/agent/scope.ts +34 -0
  42. package/packages/core/src/agent/todos.ts +66 -0
  43. package/packages/core/src/compaction.protocol.test.ts +90 -0
  44. package/packages/core/src/compaction.test.ts +101 -0
  45. package/packages/core/src/compaction.ts +243 -0
  46. package/packages/core/src/config.test.ts +40 -0
  47. package/packages/core/src/config.ts +387 -0
  48. package/packages/core/src/extensions.ts +178 -0
  49. package/packages/core/src/index.ts +157 -0
  50. package/packages/core/src/logger.ts +54 -0
  51. package/packages/core/src/provider/auth.ts +153 -0
  52. package/packages/core/src/provider/complete.ts +63 -0
  53. package/packages/core/src/provider/index.ts +6 -0
  54. package/packages/core/src/provider/openrouter.test.ts +59 -0
  55. package/packages/core/src/provider/openrouter.ts +304 -0
  56. package/packages/core/src/provider/pick-model.ts +43 -0
  57. package/packages/core/src/provider/registry.ts +222 -0
  58. package/packages/core/src/provider/types.ts +61 -0
  59. package/packages/core/src/repo-map.ts +177 -0
  60. package/packages/core/src/session/index.ts +2 -0
  61. package/packages/core/src/session/migration.test.ts +104 -0
  62. package/packages/core/src/session/store-v2-repair.test.ts +209 -0
  63. package/packages/core/src/session/store.test.ts +235 -0
  64. package/packages/core/src/session/store.ts +677 -0
  65. package/packages/core/src/session/types.ts +72 -0
  66. package/packages/core/src/snapshots.ts +107 -0
  67. package/packages/core/src/tools/definitions.ts +365 -0
  68. package/packages/core/src/tools/executor.test.ts +122 -0
  69. package/packages/core/src/tools/executor.ts +1363 -0
  70. package/packages/core/src/tools/index.ts +5 -0
  71. package/packages/core/src/tools/search.ts +201 -0
  72. package/scripts/postinstall.js +121 -0
  73. package/scripts/preinstall.js +51 -0
@@ -0,0 +1,26 @@
1
+ /**
2
+ * StatusLine — a single-line pi-tui component whose text can be replaced.
3
+ *
4
+ * Rendering-only: `main()` owns what the text says.
5
+ */
6
+
7
+ import {truncateToWidth} from '@earendil-works/pi-tui';
8
+ import type {Component} from '@earendil-works/pi-tui';
9
+
10
+ export class StatusLine implements Component {
11
+ private _text: string;
12
+
13
+ constructor(text: string) {
14
+ this._text = text;
15
+ }
16
+
17
+ setText(text: string): void {
18
+ this._text = text;
19
+ }
20
+
21
+ invalidate(): void {}
22
+
23
+ render(width: number): string[] {
24
+ return [truncateToWidth(this._text, width)];
25
+ }
26
+ }
@@ -0,0 +1,107 @@
1
+ /**
2
+ * CLI configuration.
3
+ *
4
+ * Values come from environment variables, then `~/.pal/config.json`, then
5
+ * built-in defaults. Invalid values are reported and ignored rather than
6
+ * silently producing NaN (which previously flowed into retry backoff and the
7
+ * context limit).
8
+ */
9
+
10
+ import {readPalConfig, loadPermissionConfig} from '@pal/core';
11
+ import type {PermissionConfig} from '@pal/core';
12
+
13
+ export interface Config {
14
+ model: string;
15
+ systemPrompt: string;
16
+ maxToolRounds: number;
17
+ maxRetries: number;
18
+ retryBaseMs: number;
19
+ contextLimit: number;
20
+ reasoningEffort: 'low' | 'medium' | 'high';
21
+ /** Extension package names to load (default: ['@pal/web-search']). */
22
+ extensions: string[];
23
+ }
24
+
25
+ const DEFAULT_SYSTEM_PROMPT = [
26
+ "pal — a terminal coding agent working in the user's project.",
27
+ 'TOOLS: Never guess about files — read them. Batch independent tool calls in one response.',
28
+ 'PLAN: For any task needing more than ~2 steps, call `todo` first with the full list and update it as you progress. Keep exactly one item in_progress.',
29
+ 'VERIFY: After editing code, run `verify` to confirm nothing broke.',
30
+ "DON'T LOOP: Never repeat a tool call with identical arguments — it cannot give a different result. If something fails twice, change approach or report the blocker.",
31
+ 'STOP: Once every todo item is done and the request is satisfied, stop calling tools and reply. Do not re-read files you already have.',
32
+ 'DELEGATE: For broad multi-file exploration, use `delegate` to keep your own context small.',
33
+ 'Windows shell: the bash tool ALREADY runs inside cmd.exe. Write native commands directly (`dir`, `type`, `findstr`, `where`) and NEVER prefix them with `cmd /c`. Unix commands (`ls`, `cat`, `grep`, `head`, `rm`) do not exist here. Keep commands to a single line without `&&` chains when possible. Be concise; show code only when asked.',
34
+ ].join('\n');
35
+
36
+ const EFFORTS = ['low', 'medium', 'high'] as const;
37
+
38
+ /** Parse a non-negative integer env var, warning and falling back when invalid. */
39
+ function intEnv(name: string, fallback: number, min = 0): number {
40
+ const raw = process.env[name]?.trim();
41
+ if (!raw) return fallback;
42
+ if (!/^\d+$/.test(raw)) {
43
+ console.error(`pal: ignoring invalid ${name}=${JSON.stringify(raw)} — using ${fallback}`);
44
+ return fallback;
45
+ }
46
+ const n = Number.parseInt(raw, 10);
47
+ if (n < min) {
48
+ console.error(`pal: ${name}=${n} is below the minimum ${min} — using ${fallback}`);
49
+ return fallback;
50
+ }
51
+ return n;
52
+ }
53
+
54
+ function effortEnv(): 'low' | 'medium' | 'high' {
55
+ const raw = process.env.REASONING_EFFORT;
56
+ if (raw === undefined || raw === '') return 'medium';
57
+ if ((EFFORTS as readonly string[]).includes(raw)) return raw as (typeof EFFORTS)[number];
58
+ console.error(`pal: ignoring invalid REASONING_EFFORT=${JSON.stringify(raw)} — using medium`);
59
+ return 'medium';
60
+ }
61
+
62
+ function strEnv(name: string, fallback: string): string {
63
+ const raw = process.env[name];
64
+ return raw && raw.trim() ? raw : fallback;
65
+ }
66
+
67
+ export function loadConfig(): Config {
68
+ const saved = readPalConfig();
69
+ const savedModel =
70
+ typeof saved.model === 'string' && saved.model.trim() ? saved.model : undefined;
71
+ const savedPrompt =
72
+ typeof saved.systemPrompt === 'string' && saved.systemPrompt.trim()
73
+ ? saved.systemPrompt
74
+ : undefined;
75
+
76
+ // Extensions: use saved list or default to the shipped set.
77
+ const savedExtensions = Array.isArray(saved.extensions) ? saved.extensions : undefined;
78
+ const extensions = savedExtensions ?? ['@pal/web-search', '@pal/agents', '@pal/mcp'];
79
+
80
+ return {
81
+ model: strEnv('MODEL', strEnv('PAL_MODEL', savedModel ?? 'deepseek/deepseek-chat')),
82
+ systemPrompt: strEnv('SYSTEM_PROMPT', savedPrompt ?? DEFAULT_SYSTEM_PROMPT),
83
+ maxToolRounds: intEnv('MAX_TOOL_ROUNDS', 100, 1),
84
+ maxRetries: intEnv('MAX_RETRIES', 1, 0),
85
+ retryBaseMs: intEnv('RETRY_BASE_MS', 2000, 0),
86
+ contextLimit: intEnv('CONTEXT_LIMIT', 100_000, 1000),
87
+ reasoningEffort: effortEnv(),
88
+ extensions,
89
+ };
90
+ }
91
+
92
+ // ── Permissions ──────────────────────────────────────────────────────────────
93
+
94
+ let _cachedPermissions: PermissionConfig | null = null;
95
+
96
+ /** Load and cache the merged permission config. Clears cache on /reload. */
97
+ export function loadPermissions(): PermissionConfig {
98
+ if (!_cachedPermissions) {
99
+ _cachedPermissions = loadPermissionConfig();
100
+ }
101
+ return _cachedPermissions;
102
+ }
103
+
104
+ /** Clear permission cache (for /reload or testing). */
105
+ export function clearPermissionsCache(): void {
106
+ _cachedPermissions = null;
107
+ }