@causyne/agent 1.20.120 → 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 (59) 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 +22 -339
  9. package/src/agentLoop.ts +40 -347
  10. package/src/autoUpdate.js +111 -8
  11. package/src/autoUpdate.ts +144 -8
  12. package/src/cliMode.js +16 -2
  13. package/src/commands.js +10 -9
  14. package/src/config.js +42 -63
  15. package/src/configVault.js +204 -0
  16. package/src/configVault.ts +213 -0
  17. package/src/core/contextCompactor.js +70 -11
  18. package/src/core/contextCompactor.ts +83 -11
  19. package/src/dynamicCatalogue.js +42 -73
  20. package/src/dynamicCatalogue.ts +74 -60
  21. package/src/entrypoint.js +77 -4
  22. package/src/headlessCli.js +304 -0
  23. package/src/headlessCli.ts +380 -0
  24. package/src/mcp/mcpClient.js +38 -11
  25. package/src/mcp/mcpClient.ts +44 -11
  26. package/src/mcp/mcpRegistry.js +2 -5
  27. package/src/mcp/mcpRegistry.ts +2 -5
  28. package/src/mcp/mcpSecurity.js +189 -0
  29. package/src/mcp/mcpSecurity.ts +190 -0
  30. package/src/osKeychain.js +209 -0
  31. package/src/osKeychain.ts +245 -0
  32. package/src/providers/anthropic.js +28 -11
  33. package/src/providers/byokHttp.js +354 -0
  34. package/src/providers/byokHttp.ts +454 -0
  35. package/src/providers/byokStream.js +657 -0
  36. package/src/providers/byokStream.ts +759 -0
  37. package/src/providers/dashscope-byok.js +34 -25
  38. package/src/providers/deepseek.js +31 -22
  39. package/src/providers/gemini.js +40 -13
  40. package/src/providers/moonshot.js +31 -22
  41. package/src/providers/muse.js +10 -10
  42. package/src/providers/ollama.js +25 -10
  43. package/src/providers/openai-compatible.js +46 -14
  44. package/src/providers/openrouter.js +63 -29
  45. package/src/providers/openrouter.ts +73 -29
  46. package/src/providers/qwen-byok.js +33 -16
  47. package/src/providers/xai.js +31 -22
  48. package/src/sandbox.js +77 -56
  49. package/src/sandboxPolicy.js +1208 -0
  50. package/src/sandboxPolicy.ts +1300 -0
  51. package/src/sessionJournal.js +47 -0
  52. package/src/sessionJournal.ts +49 -0
  53. package/src/tools/osSandbox.js +473 -0
  54. package/src/tools/osSandbox.ts +554 -0
  55. package/src/tools/persistentShell.js +8 -3
  56. package/src/tools/subprocessEnv.js +197 -0
  57. package/src/tools/subprocessEnv.ts +212 -0
  58. package/src/tools/sysRun.js +39 -6
  59. package/src/tools/sysRun.ts +53 -7
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@causyne/agent",
3
- "version": "1.20.120",
3
+ "version": "1.20.121",
4
4
  "description": "Agentic AI for software, tools, and computer workflows",
5
5
  "main": "bin/causyne.js",
6
6
  "type": "module",
@@ -0,0 +1,113 @@
1
+ /**
2
+ * Causyne Agent — Error Classifier & Retry Guidance (Sector 3)
3
+ *
4
+ * Extracted from `AgentLoop` into a standalone Strict TypeScript module so error
5
+ * classification and retry hints are independently testable and honor structured
6
+ * HTTP/network metadata (`ProviderHttpError.status`, `code: 'ETIMEDOUT'`, partial usage).
7
+ */
8
+ export function classifyAgentError(error) {
9
+ const errObj = typeof error === 'object' && error !== null ? error : null;
10
+ if (errObj?.code === 'PROVIDER_NO_PROGRESS')
11
+ return 'fatal';
12
+ if (errObj?.code === 'AGY_NATIVE_ACTION_DENIED' ||
13
+ errObj?.code === 'AGY_NATIVE_ACTION_BUDGET' ||
14
+ errObj?.code === 'AGY_DESKTOP_TASK_LIMIT') {
15
+ return 'fatal';
16
+ }
17
+ // A provider may have charged for completed steps before the turn failed.
18
+ // Replaying that turn can repeat actions and spend the same tokens again.
19
+ const spent = Number(errObj?.partialUsage?.promptTokens || 0) +
20
+ Number(errObj?.partialUsage?.completionTokens || 0);
21
+ if (spent > 0)
22
+ return 'fatal';
23
+ const msg = (typeof error === 'string'
24
+ ? error
25
+ : typeof errObj?.message === 'string'
26
+ ? errObj.message
27
+ : '').toLowerCase();
28
+ if (errObj?.name === 'OpenRouterPrivacyConstraintError' ||
29
+ msg.includes('matching the privacy policy') ||
30
+ msg.includes('data_collection=')) {
31
+ return 'fatal';
32
+ }
33
+ if (msg.includes('free usage limit') ||
34
+ msg.includes('subscribe to opencode') ||
35
+ msg.includes('opencode.ai/go') ||
36
+ msg.includes('insufficient_quota') ||
37
+ msg.includes('credit balance is too low')) {
38
+ return 'fatal';
39
+ }
40
+ // Honor structured HTTP status codes and transport error codes directly
41
+ const status = typeof errObj?.status === 'number' ? errObj.status : null;
42
+ if (status === 429)
43
+ return 'rate_limit';
44
+ if (status === 401 || status === 403)
45
+ return 'auth_error';
46
+ if (status === 400)
47
+ return 'invalid_request_error';
48
+ if (status !== null && status >= 500 && status <= 599)
49
+ return 'network_error';
50
+ if (errObj?.code === 'ETIMEDOUT' ||
51
+ errObj?.code === 'ECONNREFUSED' ||
52
+ errObj?.code === 'ECONNRESET') {
53
+ return 'network_error';
54
+ }
55
+ if (msg.includes('syntax') || msg.includes('unexpected token') || msg.includes('invalid json')) {
56
+ return 'syntax_error';
57
+ }
58
+ if (msg.includes('enoent') ||
59
+ msg.includes('no such file') ||
60
+ msg.includes('not found') ||
61
+ msg.includes('does not exist')) {
62
+ return 'path_not_found';
63
+ }
64
+ if (msg.includes('econnrefused') ||
65
+ msg.includes('econnreset') ||
66
+ msg.includes('etimedout') ||
67
+ msg.includes('fetch failed') ||
68
+ msg.includes('network')) {
69
+ return 'network_error';
70
+ }
71
+ if (msg.includes('rate limit') ||
72
+ msg.includes('429') ||
73
+ msg.includes('too many requests') ||
74
+ msg.includes('quota')) {
75
+ return 'rate_limit';
76
+ }
77
+ if (msg.includes('eacces') || msg.includes('permission denied') || msg.includes('eperm')) {
78
+ return 'permission_denied';
79
+ }
80
+ if (msg.includes('401') ||
81
+ msg.includes('403') ||
82
+ msg.includes('unauthorized') ||
83
+ msg.includes('api key')) {
84
+ return 'auth_error';
85
+ }
86
+ if (msg.includes('400') ||
87
+ msg.includes('invalid_parameter') ||
88
+ msg.includes('invalid_request') ||
89
+ msg.includes('required property') ||
90
+ msg.includes('bad request')) {
91
+ return 'invalid_request_error';
92
+ }
93
+ if (msg.includes('kill') || msg.includes('abort') || msg.includes('signal') || msg.includes('fatal')) {
94
+ return 'fatal';
95
+ }
96
+ if (error instanceof TypeError || error instanceof ReferenceError || error instanceof RangeError) {
97
+ return 'fatal';
98
+ }
99
+ return 'unknown_error';
100
+ }
101
+ const RETRY_HINTS = {
102
+ syntax_error: 'Check your command syntax or JSON structure. Ensure quotes are balanced.',
103
+ path_not_found: 'The file or directory does not exist. Use fs.list to verify the path first, or create it with fs.write/mkdir.',
104
+ network_error: 'Network connectivity issue. Wait a moment and retry. If persistent, check if the URL is correct.',
105
+ rate_limit: 'API rate limit hit. Wait 5-10 seconds before retrying.',
106
+ permission_denied: 'Permission denied. Check if the path is within allowed workspace paths. Try a different directory.',
107
+ auth_error: 'Authentication failed. Do NOT retry — the API key may be invalid.',
108
+ invalid_request_error: 'API request format error (400 Bad Request). Do NOT retry — check model parameter compliance.',
109
+ unknown_error: 'An unexpected error occurred. Try a different approach entirely.'
110
+ };
111
+ export function getRetryHintForError(errorType) {
112
+ return RETRY_HINTS[errorType] ?? RETRY_HINTS.unknown_error;
113
+ }
@@ -0,0 +1,161 @@
1
+ /**
2
+ * Causyne Agent — Error Classifier & Retry Guidance (Sector 3)
3
+ *
4
+ * Extracted from `AgentLoop` into a standalone Strict TypeScript module so error
5
+ * classification and retry hints are independently testable and honor structured
6
+ * HTTP/network metadata (`ProviderHttpError.status`, `code: 'ETIMEDOUT'`, partial usage).
7
+ */
8
+
9
+ export type AgentErrorClass =
10
+ | 'fatal'
11
+ | 'syntax_error'
12
+ | 'path_not_found'
13
+ | 'network_error'
14
+ | 'rate_limit'
15
+ | 'permission_denied'
16
+ | 'auth_error'
17
+ | 'invalid_request_error'
18
+ | 'unknown_error';
19
+
20
+ interface StructuredErrorLike {
21
+ code?: unknown;
22
+ name?: unknown;
23
+ status?: unknown;
24
+ message?: unknown;
25
+ partialUsage?: {
26
+ promptTokens?: unknown;
27
+ completionTokens?: unknown;
28
+ };
29
+ }
30
+
31
+ export function classifyAgentError(error: unknown): AgentErrorClass {
32
+ const errObj: StructuredErrorLike | null =
33
+ typeof error === 'object' && error !== null ? (error as StructuredErrorLike) : null;
34
+
35
+ if (errObj?.code === 'PROVIDER_NO_PROGRESS') return 'fatal';
36
+ if (
37
+ errObj?.code === 'AGY_NATIVE_ACTION_DENIED' ||
38
+ errObj?.code === 'AGY_NATIVE_ACTION_BUDGET' ||
39
+ errObj?.code === 'AGY_DESKTOP_TASK_LIMIT'
40
+ ) {
41
+ return 'fatal';
42
+ }
43
+
44
+ // A provider may have charged for completed steps before the turn failed.
45
+ // Replaying that turn can repeat actions and spend the same tokens again.
46
+ const spent =
47
+ Number(errObj?.partialUsage?.promptTokens || 0) +
48
+ Number(errObj?.partialUsage?.completionTokens || 0);
49
+ if (spent > 0) return 'fatal';
50
+
51
+ const msg = (
52
+ typeof error === 'string'
53
+ ? error
54
+ : typeof errObj?.message === 'string'
55
+ ? errObj.message
56
+ : ''
57
+ ).toLowerCase();
58
+
59
+ if (
60
+ errObj?.name === 'OpenRouterPrivacyConstraintError' ||
61
+ msg.includes('matching the privacy policy') ||
62
+ msg.includes('data_collection=')
63
+ ) {
64
+ return 'fatal';
65
+ }
66
+ if (
67
+ msg.includes('free usage limit') ||
68
+ msg.includes('subscribe to opencode') ||
69
+ msg.includes('opencode.ai/go') ||
70
+ msg.includes('insufficient_quota') ||
71
+ msg.includes('credit balance is too low')
72
+ ) {
73
+ return 'fatal';
74
+ }
75
+
76
+ // Honor structured HTTP status codes and transport error codes directly
77
+ const status = typeof errObj?.status === 'number' ? errObj.status : null;
78
+ if (status === 429) return 'rate_limit';
79
+ if (status === 401 || status === 403) return 'auth_error';
80
+ if (status === 400) return 'invalid_request_error';
81
+ if (status !== null && status >= 500 && status <= 599) return 'network_error';
82
+ if (
83
+ errObj?.code === 'ETIMEDOUT' ||
84
+ errObj?.code === 'ECONNREFUSED' ||
85
+ errObj?.code === 'ECONNRESET'
86
+ ) {
87
+ return 'network_error';
88
+ }
89
+
90
+ if (msg.includes('syntax') || msg.includes('unexpected token') || msg.includes('invalid json')) {
91
+ return 'syntax_error';
92
+ }
93
+ if (
94
+ msg.includes('enoent') ||
95
+ msg.includes('no such file') ||
96
+ msg.includes('not found') ||
97
+ msg.includes('does not exist')
98
+ ) {
99
+ return 'path_not_found';
100
+ }
101
+ if (
102
+ msg.includes('econnrefused') ||
103
+ msg.includes('econnreset') ||
104
+ msg.includes('etimedout') ||
105
+ msg.includes('fetch failed') ||
106
+ msg.includes('network')
107
+ ) {
108
+ return 'network_error';
109
+ }
110
+ if (
111
+ msg.includes('rate limit') ||
112
+ msg.includes('429') ||
113
+ msg.includes('too many requests') ||
114
+ msg.includes('quota')
115
+ ) {
116
+ return 'rate_limit';
117
+ }
118
+ if (msg.includes('eacces') || msg.includes('permission denied') || msg.includes('eperm')) {
119
+ return 'permission_denied';
120
+ }
121
+ if (
122
+ msg.includes('401') ||
123
+ msg.includes('403') ||
124
+ msg.includes('unauthorized') ||
125
+ msg.includes('api key')
126
+ ) {
127
+ return 'auth_error';
128
+ }
129
+ if (
130
+ msg.includes('400') ||
131
+ msg.includes('invalid_parameter') ||
132
+ msg.includes('invalid_request') ||
133
+ msg.includes('required property') ||
134
+ msg.includes('bad request')
135
+ ) {
136
+ return 'invalid_request_error';
137
+ }
138
+ if (msg.includes('kill') || msg.includes('abort') || msg.includes('signal') || msg.includes('fatal')) {
139
+ return 'fatal';
140
+ }
141
+ if (error instanceof TypeError || error instanceof ReferenceError || error instanceof RangeError) {
142
+ return 'fatal';
143
+ }
144
+
145
+ return 'unknown_error';
146
+ }
147
+
148
+ const RETRY_HINTS: Record<string, string> = {
149
+ syntax_error: 'Check your command syntax or JSON structure. Ensure quotes are balanced.',
150
+ path_not_found: 'The file or directory does not exist. Use fs.list to verify the path first, or create it with fs.write/mkdir.',
151
+ network_error: 'Network connectivity issue. Wait a moment and retry. If persistent, check if the URL is correct.',
152
+ rate_limit: 'API rate limit hit. Wait 5-10 seconds before retrying.',
153
+ permission_denied: 'Permission denied. Check if the path is within allowed workspace paths. Try a different directory.',
154
+ auth_error: 'Authentication failed. Do NOT retry — the API key may be invalid.',
155
+ invalid_request_error: 'API request format error (400 Bad Request). Do NOT retry — check model parameter compliance.',
156
+ unknown_error: 'An unexpected error occurred. Try a different approach entirely.'
157
+ };
158
+
159
+ export function getRetryHintForError(errorType: string): string {
160
+ return RETRY_HINTS[errorType] ?? RETRY_HINTS.unknown_error!;
161
+ }
@@ -0,0 +1,200 @@
1
+ /**
2
+ * Causyne Agent — Prompt Intent & Response Classification Helpers (Sector 3)
3
+ *
4
+ * Extracted from `AgentLoop` into a cohesive Strict TypeScript module.
5
+ * Re-exported from `src/agentLoop.ts` for full backward compatibility.
6
+ */
7
+ import { isDirectGameTask as isDirectGameTaskDecision } from '../decideTools.js';
8
+ import { isNoExecutionPrompt, isReadOnlyOrExplanatoryPrompt } from '../launchIntent.js';
9
+ export function isActionableTaskPrompt(text) {
10
+ const t = (text || '').trim();
11
+ if (!t)
12
+ return false;
13
+ // A no-execution request can be satisfied by analysis without mandatory tool calls.
14
+ if (isNoExecutionPrompt(t))
15
+ return false;
16
+ const pureGreeting = /^(hi|hello|hey|yo|halo|hai|p|assalamu['a]?[l]?aikum|good\s+(morning|afternoon|evening))[.!?, ]*$/i.test(t);
17
+ if (pureGreeting)
18
+ return false;
19
+ const actionKeywords = /\b(continue|resume|proceed|lanjut\w*|create|build|make|write|code|implement|fix|optimize|refactor|generate|add|setup|install|run|open|launch|start|play|serve|preview|deploy|delete|remove|update|change|test|review|inspect|search|find|download|buat\w*|bikin\w*|perbaik\w*|tambah\w*|ubah\w*|hapus\w*|jalan\w*|pasang\w*|analis\w*|cek\w*|rancang\w*|desain\w*|kerjakan\w*|tolong\w*|bantu\w*|ganti\w*|tulis\w*|kembangkan\w*)\b/i;
20
+ if (actionKeywords.test(t))
21
+ return true;
22
+ return false; // Length alone does not turn an information question into an execution order.
23
+ }
24
+ export function isGenericHandoffResponse(text) {
25
+ const answer = (text || '').trim();
26
+ if (!answer || answer.length > 500)
27
+ return false;
28
+ const lower = answer.toLowerCase();
29
+ const handoff = /\b(let me know what you would like to do next|what would you like me to do next|how (can|may) i help|what can i help you with|feel free to (ask|tell me))\b/i.test(lower);
30
+ const verifiedOutcome = /\b(completed|changed|set the (desktop|wallpaper)|saved|created|installed|verified|downloaded|finished)\b/i.test(lower);
31
+ return handoff && !verifiedOutcome;
32
+ }
33
+ export function isDesktopWallpaperChangePrompt(text) {
34
+ const t = (text || '').trim();
35
+ if (!t)
36
+ return false;
37
+ // Explanatory questions or prompts that explicitly forbid execution are never wallpaper mutation requests
38
+ if (isNoExecutionPrompt(t) || isReadOnlyOrExplanatoryPrompt(t))
39
+ return false;
40
+ if (/^(?:why|how|what|does|can\s+you\s+explain|explain|tell\s+me|show\s+me\s+how)\b/i.test(t))
41
+ return false;
42
+ if (/\b(?:why|how)\s+does\b/i.test(t))
43
+ return false;
44
+ // Debugging wallpaper-related source or regexes is not a request to mutate macOS.
45
+ if (/\b(?:test|review|audit|analy[sz]e|debug|refactor|inspect|explain|write|implement)\b[\s\S]{0,140}\b(?:regex|code|source|logic|verification|readback|function|script|test)\b/i.test(t))
46
+ return false;
47
+ return /\b(?:change|set|switch|replace)\s+(?:(?:my|the|this|current|desktop|mac|macos)\s+){0,4}(?:desktop picture|wallpaper|desktop background)\b/i.test(t);
48
+ }
49
+ export function isExecutionOrLaunchTaskPrompt(text) {
50
+ const t = (text || '').trim();
51
+ if (!t)
52
+ return false;
53
+ return /\b(open|launch|start|run|play|serve|preview)\b/i.test(t)
54
+ && !/\b(create|build|make|write|code|implement|generate|refactor)\b/i.test(t);
55
+ }
56
+ export function isCodeAuthoringTaskPrompt(text) {
57
+ const t = (text || '').trim();
58
+ if (!t)
59
+ return false;
60
+ if (isExecutionOrLaunchTaskPrompt(t))
61
+ return false;
62
+ return /\b(create|build|make|write|code|implement|generate|game|3js|three?\.?js|three?js|app)\b/i.test(t);
63
+ }
64
+ export function extractSkillIdFromPrompt(prompt) {
65
+ const text = String(prompt || '').trim();
66
+ if (!text)
67
+ return '';
68
+ const stopWords = new Set([
69
+ 'the', 'a', 'an', 'this', 'that', 'from', 'in', 'with',
70
+ 'using', 'for', 'to', 'by', 'and', 'or', 'of'
71
+ ]);
72
+ const leadingTrim = new Set(['`', '"', "'", '(', '[']);
73
+ const trailingTrim = new Set(['`', '"', "'", ')', ',', '.', ';', ':', '!', '?', ']', '\\']);
74
+ const cleanCandidate = (raw) => {
75
+ const trimmed = raw.trim();
76
+ let start = 0;
77
+ let end = trimmed.length;
78
+ while (start < end && leadingTrim.has(trimmed[start]))
79
+ start++;
80
+ while (end > start && trailingTrim.has(trimmed[end - 1]))
81
+ end--;
82
+ const stripped = trimmed.slice(start, end);
83
+ if (!stripped || stopWords.has(stripped.toLowerCase()))
84
+ return '';
85
+ if (/^(?:fs_read_skill|fs_read_skil|read_skill|read_skil|tool_search)$/i.test(stripped)) {
86
+ return '';
87
+ }
88
+ return stripped;
89
+ };
90
+ const isFileExt = (candidate) => /\.(?:ts|tsx|js|jsx|mjs|cjs|py|go|rs|java|kt|json|html|css|gradle|apk|aab|dex)$/i.test(candidate);
91
+ const cuedSlashMatch = text.match(/(?:\bskill_id|\bskill|\bfs_read_skil{1,2})(?:\s*[:=]\s*|\s+)[`"']?([a-zA-Z0-9][a-zA-Z0-9_.-]{0,80}\/[a-zA-Z0-9][a-zA-Z0-9_.-]{0,120})[`"']?/i);
92
+ if (cuedSlashMatch?.[1]) {
93
+ const candidate = cleanCandidate(cuedSlashMatch[1]);
94
+ if (candidate && !isFileExt(candidate)) {
95
+ return candidate;
96
+ }
97
+ }
98
+ for (const m of text.matchAll(/\b([a-zA-Z0-9][a-zA-Z0-9_.-]{0,80}\/[a-zA-Z0-9][a-zA-Z0-9_.-]{0,120})\b/g)) {
99
+ const candidate = cleanCandidate(m[1] || '');
100
+ if (candidate && !isFileExt(candidate)) {
101
+ return candidate;
102
+ }
103
+ }
104
+ const explicitQuotedMatch = text.match(/(?:\bskill_id|\bskill)(?:\s*[:=]\s*|\s+)(?:the\s+)?[`"']([^`"'\n\r]{2,120})[`"']/i);
105
+ if (explicitQuotedMatch?.[1]) {
106
+ const candidate = cleanCandidate(explicitQuotedMatch[1]);
107
+ if (candidate)
108
+ return candidate;
109
+ }
110
+ const bareMatch = text.match(/(?:\bskill_id\s*[:=]\s*|\bskill\s*[:=]\s*|\bskill\s+(?:called\s+|named\s+)?)([a-zA-Z0-9][a-zA-Z0-9_.-]{1,120})/i);
111
+ if (bareMatch?.[1]) {
112
+ const candidate = cleanCandidate(bareMatch[1]);
113
+ if (candidate)
114
+ return candidate;
115
+ }
116
+ return '';
117
+ }
118
+ export function isDirectGameTask(text) {
119
+ return isDirectGameTaskDecision(text);
120
+ }
121
+ export function isProviderPlanOrQuotaRefusal(text) {
122
+ if (!text || typeof text !== 'string')
123
+ return false;
124
+ const trimmed = text.trim();
125
+ if (!trimmed || trimmed.length > 320)
126
+ return false;
127
+ if (/^upgrade your plan to continue\.?$/i.test(trimmed))
128
+ return true;
129
+ return /\b(upgrade your plan to continue|insufficient[_ ]quota|credit balance is too low|billing hard limit|quota exceeded for|plan limit reached|subscription required to continue)\b/i.test(trimmed);
130
+ }
131
+ /**
132
+ * Detects when an agent response is an intermediate mid-task progress note or
133
+ * transition announcement rather than a finished answer.
134
+ */
135
+ export function isMidTaskProgressText(text) {
136
+ if (!text || typeof text !== 'string')
137
+ return false;
138
+ const trimmed = text.trim();
139
+ if (!trimmed || trimmed.length > 480)
140
+ return false;
141
+ const lower = trimmed.toLowerCase();
142
+ if (lower.includes('?') ||
143
+ lower.includes('let me know') ||
144
+ lower.includes('how can i help') ||
145
+ lower.includes('how may i help') ||
146
+ lower.includes('how can i assist') ||
147
+ lower.includes('what would you like') ||
148
+ lower.includes('what can i help') ||
149
+ lower.includes('feel free to')) {
150
+ return false;
151
+ }
152
+ if (trimmed.includes('```'))
153
+ return false;
154
+ const sentences = trimmed
155
+ .split(/(?:(?<=[.!])\s+|\n+)/)
156
+ .map(s => s.trim())
157
+ .filter(Boolean);
158
+ const lastSentence = (sentences[sentences.length - 1] || trimmed).trim();
159
+ const lastLower = lastSentence.toLowerCase();
160
+ if (trimmed.length <= 280 && (trimmed.endsWith(':') || trimmed.endsWith('...') || trimmed.endsWith('…'))) {
161
+ return true;
162
+ }
163
+ const intentPrefixes = [
164
+ 'let me ',
165
+ "i'll ",
166
+ 'i will ',
167
+ 'now i ',
168
+ 'now let me ',
169
+ "now i'll ",
170
+ 'now i will ',
171
+ 'next, i ',
172
+ 'next i ',
173
+ "next, i'll ",
174
+ "next i'll ",
175
+ 'first, i ',
176
+ 'first i ',
177
+ 'let us ',
178
+ "let's ",
179
+ 'i shall ',
180
+ 'we will ',
181
+ "we'll ",
182
+ 'i am going to ',
183
+ "i'm going to ",
184
+ 'going to '
185
+ ];
186
+ if (intentPrefixes.some(prefix => lastLower.startsWith(prefix) || (trimmed.length <= 280 && lower.startsWith(prefix)))) {
187
+ if (!/\b(?:task completed|all done|everything is ready|finished|complete\.)\b/i.test(lastSentence)) {
188
+ return true;
189
+ }
190
+ }
191
+ const gerundStart = /^(?:now\s+|next,?\s+|currently\s+|still\s+)?(?:writing|pulling|checking|inspecting|building|creating|updating|applying|implementing|generating|fetching|downloading|testing|running|fixing|setting up|configuring|refactoring|adding|modifying|replacing|launching|starting|verifying|confirming|reading|searching|analyzing|preparing|compiling|rendering|extracting|installing|opening|switching|retrying|continuing)\b/i;
192
+ if (gerundStart.test(lastSentence) && lastSentence.length <= 220) {
193
+ return true;
194
+ }
195
+ const actionNowSuffix = /\b(?:writing|pulling|checking|inspecting|building|creating|updating|applying|implementing|generating|fetching|downloading|testing|running|fixing|configuring|refactoring|adding|modifying|replacing|launching|starting|verifying|confirming|reading|searching|analyzing|preparing|compiling|rendering|extracting)\b[^.!?\n]{1,120}\b(?:now|next)\.?$/i;
196
+ if (actionNowSuffix.test(lastSentence)) {
197
+ return true;
198
+ }
199
+ return false;
200
+ }