@causyne/agent 1.20.118 → 1.20.121

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 (101) hide show
  1. package/package.json +1 -1
  2. package/src/agent/errorClassifier.js +113 -0
  3. package/src/agent/errorClassifier.ts +161 -0
  4. package/src/agent/promptIntent.js +200 -0
  5. package/src/agent/promptIntent.ts +203 -0
  6. package/src/agent/toolArgValidator.js +97 -0
  7. package/src/agent/toolArgValidator.ts +112 -0
  8. package/src/agentLoop.js +51 -351
  9. package/src/agentLoop.ts +69 -363
  10. package/src/autoUpdate.js +111 -8
  11. package/src/autoUpdate.ts +144 -8
  12. package/src/browser/causyneBrowser.js +231 -136
  13. package/src/browser/causyneBrowser.ts +229 -140
  14. package/src/browser/searchProviders.js +41 -30
  15. package/src/browser/searchProviders.ts +24 -14
  16. package/src/browser/workspacePathSafety.js +50 -0
  17. package/src/browser/workspacePathSafety.ts +50 -0
  18. package/src/browser/workspacePreview.js +27 -4
  19. package/src/browser/workspacePreview.ts +28 -4
  20. package/src/cliMode.js +17 -3
  21. package/src/commands.js +15 -22
  22. package/src/config.js +42 -63
  23. package/src/configVault.js +204 -0
  24. package/src/configVault.ts +213 -0
  25. package/src/core/contextCompactor.js +70 -11
  26. package/src/core/contextCompactor.ts +83 -11
  27. package/src/creative/liveBridge.js +34 -1
  28. package/src/creative/liveBridge.ts +28 -1
  29. package/src/dynamicCatalogue.js +42 -73
  30. package/src/dynamicCatalogue.ts +74 -60
  31. package/src/entrypoint.js +77 -4
  32. package/src/headlessCli.js +304 -0
  33. package/src/headlessCli.ts +380 -0
  34. package/src/mcp/mcpClient.js +38 -11
  35. package/src/mcp/mcpClient.ts +44 -11
  36. package/src/mcp/mcpRegistry.js +2 -5
  37. package/src/mcp/mcpRegistry.ts +2 -5
  38. package/src/mcp/mcpSecurity.js +189 -0
  39. package/src/mcp/mcpSecurity.ts +190 -0
  40. package/src/observer/evidence.js +23 -0
  41. package/src/observer/evidence.ts +21 -0
  42. package/src/osKeychain.js +209 -0
  43. package/src/osKeychain.ts +245 -0
  44. package/src/providers/anthropic.js +61 -28
  45. package/src/providers/base.js +14 -0
  46. package/src/providers/byokHttp.js +354 -0
  47. package/src/providers/byokHttp.ts +454 -0
  48. package/src/providers/byokStream.js +657 -0
  49. package/src/providers/byokStream.ts +759 -0
  50. package/src/providers/dashscope-byok.js +47 -32
  51. package/src/providers/deepseek.js +43 -39
  52. package/src/providers/gemini.js +73 -38
  53. package/src/providers/moonshot.js +43 -33
  54. package/src/providers/muse.js +10 -10
  55. package/src/providers/ollama.js +46 -31
  56. package/src/providers/openai-compatible.js +57 -32
  57. package/src/providers/openrouter.js +77 -113
  58. package/src/providers/openrouter.ts +99 -118
  59. package/src/providers/qwen-byok.js +46 -23
  60. package/src/providers/toolContracts.js +9 -3
  61. package/src/providers/toolContracts.ts +9 -3
  62. package/src/providers/wireNormalizer.js +238 -0
  63. package/src/providers/wireNormalizer.ts +279 -0
  64. package/src/providers/xai.js +43 -33
  65. package/src/sandbox.js +77 -56
  66. package/src/sandboxPolicy.js +1208 -0
  67. package/src/sandboxPolicy.ts +1300 -0
  68. package/src/sessionJournal.js +47 -0
  69. package/src/sessionJournal.ts +49 -0
  70. package/src/tools/browserAutomator.js +13 -1
  71. package/src/tools/browserAutomator.ts +13 -0
  72. package/src/tools/creativeApps.js +2 -1
  73. package/src/tools/creativeApps.ts +2 -1
  74. package/src/tools/gameAssetFetcher.js +130 -26
  75. package/src/tools/gameAssetHarvester.js +80 -58
  76. package/src/tools/nativeEngine.js +1 -1
  77. package/src/tools/nativeEngine.ts +1 -1
  78. package/src/tools/osSandbox.js +473 -0
  79. package/src/tools/osSandbox.ts +554 -0
  80. package/src/tools/persistentShell.js +8 -3
  81. package/src/tools/registry.js +13 -0
  82. package/src/tools/subprocessEnv.js +197 -0
  83. package/src/tools/subprocessEnv.ts +212 -0
  84. package/src/tools/sysRun.js +39 -6
  85. package/src/tools/sysRun.ts +53 -7
  86. package/src/tools/toolScanner.js +596 -140
  87. package/src/tools/toolScanner.ts +665 -147
  88. package/src/tools/toolSelfRepair.js +243 -114
  89. package/src/tools/toolSelfRepair.ts +262 -111
  90. package/src/tools/webFetch.js +161 -24
  91. package/src/tools/webFetch.ts +157 -22
  92. package/src/tools/webSearch.js +33 -4
  93. package/src/tools/webSearch.ts +27 -4
  94. package/src/tui/sessionPicker.js +132 -35
  95. package/src/tui/sessionPicker.ts +153 -32
  96. package/src/tui/sessionPickerView.js +277 -34
  97. package/src/tui/sessionPickerView.ts +328 -34
  98. package/src/tui/statusLine.js +3 -0
  99. package/src/tui/statusLine.ts +5 -0
  100. package/src/tui/workspaceIdentity.js +133 -0
  101. package/src/tui/workspaceIdentity.ts +146 -0
@@ -0,0 +1,146 @@
1
+ // Dynamic canonical workspace identity & display helpers for Causyne Agent TUI.
2
+ // Authored in Strict TypeScript. Never hardcodes user or project workspace names.
3
+ // Source-available under BUSL-1.1.
4
+
5
+ import fs from 'node:fs';
6
+ import os from 'node:os';
7
+ import path from 'node:path';
8
+ import { safeDisplay } from './text.js';
9
+
10
+ function cleanInlineText(value: unknown): string {
11
+ return safeDisplay(typeof value === 'string' ? value : String(value ?? ''))
12
+ .replace(/[\r\n\t]+/g, ' ')
13
+ .trim();
14
+ }
15
+
16
+ function getUserHomeDir(): string {
17
+ const fromEnv = process.env.HOME || process.env.USERPROFILE || '';
18
+ if (fromEnv && fromEnv.trim()) return fromEnv.trim();
19
+ try {
20
+ return os.homedir() || '';
21
+ } catch {
22
+ return '';
23
+ }
24
+ }
25
+
26
+ function isDriveRoot(value: string): boolean {
27
+ return value.length >= 2
28
+ && value.length <= 3
29
+ && ((value[0]! >= 'A' && value[0]! <= 'Z') || (value[0]! >= 'a' && value[0]! <= 'z'))
30
+ && value[1] === ':'
31
+ && (value.length === 2 || value[2] === '\\' || value[2] === '/');
32
+ }
33
+
34
+ /**
35
+ * Resolve a workspace path into a canonical comparison key.
36
+ * Resolves symlinks (for example `/tmp` vs `/private/tmp` on macOS) when the
37
+ * directory exists on disk, falling back to `path.resolve()` otherwise.
38
+ */
39
+ export function canonicalWorkspacePath(
40
+ workspacePath: string | undefined,
41
+ cache?: Map<string, string>
42
+ ): string {
43
+ if (typeof workspacePath !== 'string') return '';
44
+ const trimmed = workspacePath.trim();
45
+ if (!trimmed) return '';
46
+
47
+ const resolved = path.resolve(trimmed);
48
+ const cached = cache?.get(resolved);
49
+ if (cached !== undefined) return cached;
50
+
51
+ let canonical = resolved;
52
+ try {
53
+ canonical = typeof fs.realpathSync.native === 'function'
54
+ ? fs.realpathSync.native(resolved)
55
+ : fs.realpathSync(resolved);
56
+ } catch {
57
+ // Missing or synthetic paths keep their lexical resolved form.
58
+ }
59
+
60
+ const normalized = process.platform === 'win32' ? canonical.toLowerCase() : canonical;
61
+ if (cache) cache.set(resolved, normalized);
62
+ return normalized;
63
+ }
64
+
65
+ /**
66
+ * True when two workspace paths refer to the same canonical directory.
67
+ */
68
+ export function sameWorkspace(
69
+ first: string | undefined,
70
+ second: string | undefined,
71
+ cache?: Map<string, string>
72
+ ): boolean {
73
+ const a = canonicalWorkspacePath(first, cache);
74
+ const b = canonicalWorkspacePath(second, cache);
75
+ return a.length > 0 && a === b;
76
+ }
77
+
78
+ /**
79
+ * Shorten a workspace path for display by replacing the exact home prefix with `~`.
80
+ * Always sanitized for safe single-line terminal rendering.
81
+ */
82
+ export function shortenWorkspacePath(workspacePath: string | undefined): string {
83
+ if (typeof workspacePath !== 'string' || !workspacePath.trim()) return '(default)';
84
+ const trimmed = workspacePath.trim();
85
+ const home = getUserHomeDir();
86
+ if (home) {
87
+ const resolved = path.resolve(trimmed);
88
+ const resolvedHome = path.resolve(home);
89
+ const cmpResolved = process.platform === 'win32' ? resolved.toLowerCase() : resolved;
90
+ const cmpHome = process.platform === 'win32' ? resolvedHome.toLowerCase() : resolvedHome;
91
+ if (cmpResolved === cmpHome) return '~';
92
+ const prefix = cmpHome.endsWith(path.sep) ? cmpHome : `${cmpHome}${path.sep}`;
93
+ if (cmpResolved.startsWith(prefix)) {
94
+ const tail = resolved.slice(resolvedHome.length);
95
+ return cleanInlineText(`~${tail}`) || '~';
96
+ }
97
+ }
98
+ return cleanInlineText(trimmed) || '(default)';
99
+ }
100
+
101
+ /**
102
+ * Dynamically derive the human-readable workspace folder name from any path
103
+ * without hardcoding user or repository names.
104
+ */
105
+ export function workspaceDisplayName(
106
+ workspacePath: string | undefined,
107
+ cache?: Map<string, string>
108
+ ): string {
109
+ if (typeof workspacePath !== 'string' || !workspacePath.trim()) return 'Current Workspace';
110
+ const trimmed = workspacePath.trim();
111
+ const resolved = path.resolve(trimmed);
112
+ const home = getUserHomeDir();
113
+ if (home && sameWorkspace(resolved, home, cache)) {
114
+ return '~';
115
+ }
116
+ const base = path.basename(resolved);
117
+ const cleanBase = cleanInlineText(base);
118
+ if (cleanBase) return cleanBase;
119
+ const cleanRoot = cleanInlineText(resolved);
120
+ return cleanRoot || 'Current Workspace';
121
+ }
122
+
123
+ /**
124
+ * Format the dynamic section header label for the active workspace's sessions.
125
+ * Preserves the user's folder casing (for example `suika-game SESSIONS (2)` or
126
+ * `causyne-agent SESSIONS (0)`) while handling home and filesystem roots cleanly.
127
+ */
128
+ export function formatWorkspaceSectionTitle(
129
+ workspacePath: string | undefined,
130
+ sessionCount?: number,
131
+ cache?: Map<string, string>
132
+ ): string {
133
+ const name = workspaceDisplayName(workspacePath, cache);
134
+ let base: string;
135
+ if (name === '~') {
136
+ base = 'HOME (~) SESSIONS';
137
+ } else if (name === '/' || isDriveRoot(name)) {
138
+ base = `WORKSPACE (${name}) SESSIONS`;
139
+ } else {
140
+ base = `${name} SESSIONS`;
141
+ }
142
+ if (typeof sessionCount === 'number' && Number.isFinite(sessionCount) && sessionCount >= 0) {
143
+ return `${base} (${Math.floor(sessionCount)})`;
144
+ }
145
+ return base;
146
+ }