@parall/agent-core 1.18.0 → 1.18.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,40 @@
1
+ /**
2
+ * Shared workspace instructions seeded into every self-hosted bridge runtime
3
+ * (Claude Code writes this to `CLAUDE.md`, Codex to `AGENTS.md`). The text and
4
+ * the Parall CLI detection helpers live together so the seeded command
5
+ * examples and the runtime-side suppression logic cannot drift apart. Each
6
+ * bridge package is responsible for its own filesystem write —
7
+ * `@parall/agent-core` stays runtime-neutral and exports only text + pure
8
+ * helpers here.
9
+ */
10
+ export declare const BRIDGE_WORKSPACE_INSTRUCTIONS = "# Agent workspace\n\nYou are an agent in Parall IM. You participate in chats, handle tasks, and interact exclusively through the Parall CLI.\n\n## Message Model\n\nIncoming events are rendered as structured `[Event: ...]` blocks.\nEach event includes `[Chat: ... (prll://cht_xxx)]` \u2014 use that chat ID (or full URI) when replying.\n\n**Your plain-text output is not delivered to anyone** \u2014 it is recorded as suppressed thinking in your session steps and discarded from the chat.\nTo say something in a chat, you **must** invoke the Parall CLI via your shell/exec tool. To stay silent, simply do not invoke it.\n\n## Parall CLI\n\nAll outbound interactions go through `@parall/cli`. Credentials are pre-injected as environment variables \u2014 no setup needed.\n\n- `npx --yes @parall/cli@latest messages send prll://cht_xxx --text \"...\"` \u2014 reply into the triggering chat\n- `npx --yes @parall/cli@latest dm prll://usr_xxx --text \"...\" [--no-reply]` \u2014 direct message another user\n- `npx --yes @parall/cli@latest tasks update prll://tsk_xxx --status in_progress` \u2014 task state\n- `npx --yes @parall/cli@latest no-reply [--reason \"...\"]` \u2014 explicitly declare this turn silent (audit signal; not required for silence, just clarifies intent)\n\nThe bridge injects Parall context via environment variables. The static credentials `PRLL_API_URL`, `PRLL_API_KEY`, and `PRLL_ORG_ID` are always set. Per-dispatch context \u2014 `PRLL_SESSION_ID`, `PRLL_CHAT_ID`, `PRLL_TRIGGER_MESSAGE_ID`, `PRLL_STEP_ID_FILE` \u2014 is set in subprocess-per-dispatch runtimes (Claude Code); in long-running runtimes (Codex) those may be absent and the CLI will fall back to whatever defaults you supply on the command line.\n\n## Guardrails\n\n- A dispatch may coalesce multiple events. Decide per event whether to reply via `messages send` / `dm` \u2014 events you do not act on simply receive no reply.\n- If an event carries `[Hint: no_reply]`, do not send anything for that event. `no-reply` is optional and only useful as an explicit intent marker.\n- Never try to \"speak\" by typing sentences like \"No response needed\" / \"Noted\" / \"OK\" \u2014 they are discarded, so they accomplish nothing except polluting your session log.\n- Keep CLI replies concise and task-focused.\n\nSee `docs/engineering-design/agent-dm-loop-prevention.md` \u00A7 Layer 0 for why plain text is never auto-projected.\n";
11
+ /** Extracts the `command` string from a shell/bash tool call's input payload. */
12
+ export declare function extractShellCommand(input: unknown): string | undefined;
13
+ /**
14
+ * Returns the non-flag tokens that follow a Parall CLI invocation in
15
+ * `command`, or `null` if the command isn't a Parall CLI call.
16
+ *
17
+ * Handles all documented launch forms — bare `parall`, `npx [--yes|-y]
18
+ * @parall/cli[@version]`, `pnpm (exec|dlx) parall` — and skips npx flags so
19
+ * `npx --yes` matches the same way as `npx -y`. Uses space-delimited
20
+ * tokenization rather than a regex so that `messages send --no-reply` is
21
+ * correctly classified as a `messages send` invocation (not the receiver-side
22
+ * `no-reply` subcommand).
23
+ */
24
+ export declare function parseParallCliInvocation(command: string): string[] | null;
25
+ /**
26
+ * Detects whether a shell command invokes the Parall CLI to send a
27
+ * chat-visible side effect (`messages send` or `dm`). Bridge adapters use
28
+ * this to suppress the immediately-following runtime text so the user
29
+ * doesn't see the same message twice — once from the CLI call, once
30
+ * projected from runtime output.
31
+ */
32
+ export declare function isParallSendCommand(command: string | undefined): boolean;
33
+ /**
34
+ * Detects whether a shell command invokes `parall no-reply`, which signals
35
+ * the agent wants the whole turn silenced. Bridge adapters use this to
36
+ * flip a sticky suppression flag for the rest of the dispatch so no text
37
+ * event from that turn is projected into chat.
38
+ */
39
+ export declare function isParallNoReplyCommand(command: string | undefined): boolean;
40
+ //# sourceMappingURL=bridge-workspace.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bridge-workspace.d.ts","sourceRoot":"","sources":["../src/bridge-workspace.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,eAAO,MAAM,6BAA6B,m3EA+BzC,CAAC;AAEF,iFAAiF;AACjF,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CAItE;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,IAAI,CAmBzE;AAED;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,MAAM,GAAG,SAAS,GAAG,OAAO,CAKxE;AAED;;;;;GAKG;AACH,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,MAAM,GAAG,SAAS,GAAG,OAAO,CAI3E"}
@@ -0,0 +1,113 @@
1
+ /**
2
+ * Shared workspace instructions seeded into every self-hosted bridge runtime
3
+ * (Claude Code writes this to `CLAUDE.md`, Codex to `AGENTS.md`). The text and
4
+ * the Parall CLI detection helpers live together so the seeded command
5
+ * examples and the runtime-side suppression logic cannot drift apart. Each
6
+ * bridge package is responsible for its own filesystem write —
7
+ * `@parall/agent-core` stays runtime-neutral and exports only text + pure
8
+ * helpers here.
9
+ */
10
+ export const BRIDGE_WORKSPACE_INSTRUCTIONS = `# Agent workspace
11
+
12
+ You are an agent in Parall IM. You participate in chats, handle tasks, and interact exclusively through the Parall CLI.
13
+
14
+ ## Message Model
15
+
16
+ Incoming events are rendered as structured \`[Event: ...]\` blocks.
17
+ Each event includes \`[Chat: ... (prll://cht_xxx)]\` — use that chat ID (or full URI) when replying.
18
+
19
+ **Your plain-text output is not delivered to anyone** — it is recorded as suppressed thinking in your session steps and discarded from the chat.
20
+ To say something in a chat, you **must** invoke the Parall CLI via your shell/exec tool. To stay silent, simply do not invoke it.
21
+
22
+ ## Parall CLI
23
+
24
+ All outbound interactions go through \`@parall/cli\`. Credentials are pre-injected as environment variables — no setup needed.
25
+
26
+ - \`npx --yes @parall/cli@latest messages send prll://cht_xxx --text "..."\` — reply into the triggering chat
27
+ - \`npx --yes @parall/cli@latest dm prll://usr_xxx --text "..." [--no-reply]\` — direct message another user
28
+ - \`npx --yes @parall/cli@latest tasks update prll://tsk_xxx --status in_progress\` — task state
29
+ - \`npx --yes @parall/cli@latest no-reply [--reason "..."]\` — explicitly declare this turn silent (audit signal; not required for silence, just clarifies intent)
30
+
31
+ The bridge injects Parall context via environment variables. The static credentials \`PRLL_API_URL\`, \`PRLL_API_KEY\`, and \`PRLL_ORG_ID\` are always set. Per-dispatch context — \`PRLL_SESSION_ID\`, \`PRLL_CHAT_ID\`, \`PRLL_TRIGGER_MESSAGE_ID\`, \`PRLL_STEP_ID_FILE\` — is set in subprocess-per-dispatch runtimes (Claude Code); in long-running runtimes (Codex) those may be absent and the CLI will fall back to whatever defaults you supply on the command line.
32
+
33
+ ## Guardrails
34
+
35
+ - A dispatch may coalesce multiple events. Decide per event whether to reply via \`messages send\` / \`dm\` — events you do not act on simply receive no reply.
36
+ - If an event carries \`[Hint: no_reply]\`, do not send anything for that event. \`no-reply\` is optional and only useful as an explicit intent marker.
37
+ - Never try to "speak" by typing sentences like "No response needed" / "Noted" / "OK" — they are discarded, so they accomplish nothing except polluting your session log.
38
+ - Keep CLI replies concise and task-focused.
39
+
40
+ See \`docs/engineering-design/agent-dm-loop-prevention.md\` § Layer 0 for why plain text is never auto-projected.
41
+ `;
42
+ /** Extracts the `command` string from a shell/bash tool call's input payload. */
43
+ export function extractShellCommand(input) {
44
+ if (!input || typeof input !== "object")
45
+ return undefined;
46
+ const command = input.command;
47
+ return typeof command === "string" && command.trim() ? command.trim() : undefined;
48
+ }
49
+ /**
50
+ * Returns the non-flag tokens that follow a Parall CLI invocation in
51
+ * `command`, or `null` if the command isn't a Parall CLI call.
52
+ *
53
+ * Handles all documented launch forms — bare `parall`, `npx [--yes|-y]
54
+ * @parall/cli[@version]`, `pnpm (exec|dlx) parall` — and skips npx flags so
55
+ * `npx --yes` matches the same way as `npx -y`. Uses space-delimited
56
+ * tokenization rather than a regex so that `messages send --no-reply` is
57
+ * correctly classified as a `messages send` invocation (not the receiver-side
58
+ * `no-reply` subcommand).
59
+ */
60
+ export function parseParallCliInvocation(command) {
61
+ const tokens = command.replace(/\s+/g, " ").trim().split(" ");
62
+ let i = 0;
63
+ if (tokens[i] === "parall") {
64
+ i++;
65
+ }
66
+ else if (tokens[i] === "npx") {
67
+ i++;
68
+ while (i < tokens.length && tokens[i].startsWith("-"))
69
+ i++;
70
+ if (i >= tokens.length || !/^@parall\/cli(?:@.+)?$/.test(tokens[i]))
71
+ return null;
72
+ i++;
73
+ }
74
+ else if (tokens[i] === "pnpm") {
75
+ i++;
76
+ if (i < tokens.length && (tokens[i] === "exec" || tokens[i] === "dlx"))
77
+ i++;
78
+ if (i >= tokens.length || tokens[i] !== "parall")
79
+ return null;
80
+ i++;
81
+ }
82
+ else {
83
+ return null;
84
+ }
85
+ return tokens.slice(i).filter((t) => !t.startsWith("-"));
86
+ }
87
+ /**
88
+ * Detects whether a shell command invokes the Parall CLI to send a
89
+ * chat-visible side effect (`messages send` or `dm`). Bridge adapters use
90
+ * this to suppress the immediately-following runtime text so the user
91
+ * doesn't see the same message twice — once from the CLI call, once
92
+ * projected from runtime output.
93
+ */
94
+ export function isParallSendCommand(command) {
95
+ if (!command)
96
+ return false;
97
+ const sub = parseParallCliInvocation(command);
98
+ if (!sub || sub.length === 0)
99
+ return false;
100
+ return sub[0] === "dm" || (sub[0] === "messages" && sub[1] === "send");
101
+ }
102
+ /**
103
+ * Detects whether a shell command invokes `parall no-reply`, which signals
104
+ * the agent wants the whole turn silenced. Bridge adapters use this to
105
+ * flip a sticky suppression flag for the rest of the dispatch so no text
106
+ * event from that turn is projected into chat.
107
+ */
108
+ export function isParallNoReplyCommand(command) {
109
+ if (!command)
110
+ return false;
111
+ const sub = parseParallCliInvocation(command);
112
+ return sub?.[0] === "no-reply";
113
+ }
package/dist/index.d.ts CHANGED
@@ -3,6 +3,7 @@ export * from "./session-state.js";
3
3
  export * from "./routing.js";
4
4
  export * from "./event-format.js";
5
5
  export * from "./prompt-fragments.js";
6
+ export * from "./bridge-workspace.js";
6
7
  export * from "./dispatch-adapter.js";
7
8
  export * from "./gateway-base.js";
8
9
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,oBAAoB,CAAC;AACnC,cAAc,cAAc,CAAC;AAC7B,cAAc,mBAAmB,CAAC;AAClC,cAAc,uBAAuB,CAAC;AACtC,cAAc,uBAAuB,CAAC;AACtC,cAAc,mBAAmB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,oBAAoB,CAAC;AACnC,cAAc,cAAc,CAAC;AAC7B,cAAc,mBAAmB,CAAC;AAClC,cAAc,uBAAuB,CAAC;AACtC,cAAc,uBAAuB,CAAC;AACtC,cAAc,uBAAuB,CAAC;AACtC,cAAc,mBAAmB,CAAC"}
package/dist/index.js CHANGED
@@ -3,5 +3,6 @@ export * from "./session-state.js";
3
3
  export * from "./routing.js";
4
4
  export * from "./event-format.js";
5
5
  export * from "./prompt-fragments.js";
6
+ export * from "./bridge-workspace.js";
6
7
  export * from "./dispatch-adapter.js";
7
8
  export * from "./gateway-base.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@parall/agent-core",
3
- "version": "1.18.0",
3
+ "version": "1.18.1",
4
4
  "description": "Shared agent runtime orchestration helpers for Parall",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -0,0 +1,107 @@
1
+ /**
2
+ * Shared workspace instructions seeded into every self-hosted bridge runtime
3
+ * (Claude Code writes this to `CLAUDE.md`, Codex to `AGENTS.md`). The text and
4
+ * the Parall CLI detection helpers live together so the seeded command
5
+ * examples and the runtime-side suppression logic cannot drift apart. Each
6
+ * bridge package is responsible for its own filesystem write —
7
+ * `@parall/agent-core` stays runtime-neutral and exports only text + pure
8
+ * helpers here.
9
+ */
10
+
11
+ export const BRIDGE_WORKSPACE_INSTRUCTIONS = `# Agent workspace
12
+
13
+ You are an agent in Parall IM. You participate in chats, handle tasks, and interact exclusively through the Parall CLI.
14
+
15
+ ## Message Model
16
+
17
+ Incoming events are rendered as structured \`[Event: ...]\` blocks.
18
+ Each event includes \`[Chat: ... (prll://cht_xxx)]\` — use that chat ID (or full URI) when replying.
19
+
20
+ **Your plain-text output is not delivered to anyone** — it is recorded as suppressed thinking in your session steps and discarded from the chat.
21
+ To say something in a chat, you **must** invoke the Parall CLI via your shell/exec tool. To stay silent, simply do not invoke it.
22
+
23
+ ## Parall CLI
24
+
25
+ All outbound interactions go through \`@parall/cli\`. Credentials are pre-injected as environment variables — no setup needed.
26
+
27
+ - \`npx --yes @parall/cli@latest messages send prll://cht_xxx --text "..."\` — reply into the triggering chat
28
+ - \`npx --yes @parall/cli@latest dm prll://usr_xxx --text "..." [--no-reply]\` — direct message another user
29
+ - \`npx --yes @parall/cli@latest tasks update prll://tsk_xxx --status in_progress\` — task state
30
+ - \`npx --yes @parall/cli@latest no-reply [--reason "..."]\` — explicitly declare this turn silent (audit signal; not required for silence, just clarifies intent)
31
+
32
+ The bridge injects Parall context via environment variables. The static credentials \`PRLL_API_URL\`, \`PRLL_API_KEY\`, and \`PRLL_ORG_ID\` are always set. Per-dispatch context — \`PRLL_SESSION_ID\`, \`PRLL_CHAT_ID\`, \`PRLL_TRIGGER_MESSAGE_ID\`, \`PRLL_STEP_ID_FILE\` — is set in subprocess-per-dispatch runtimes (Claude Code); in long-running runtimes (Codex) those may be absent and the CLI will fall back to whatever defaults you supply on the command line.
33
+
34
+ ## Guardrails
35
+
36
+ - A dispatch may coalesce multiple events. Decide per event whether to reply via \`messages send\` / \`dm\` — events you do not act on simply receive no reply.
37
+ - If an event carries \`[Hint: no_reply]\`, do not send anything for that event. \`no-reply\` is optional and only useful as an explicit intent marker.
38
+ - Never try to "speak" by typing sentences like "No response needed" / "Noted" / "OK" — they are discarded, so they accomplish nothing except polluting your session log.
39
+ - Keep CLI replies concise and task-focused.
40
+
41
+ See \`docs/engineering-design/agent-dm-loop-prevention.md\` § Layer 0 for why plain text is never auto-projected.
42
+ `;
43
+
44
+ /** Extracts the `command` string from a shell/bash tool call's input payload. */
45
+ export function extractShellCommand(input: unknown): string | undefined {
46
+ if (!input || typeof input !== "object") return undefined;
47
+ const command = (input as { command?: unknown }).command;
48
+ return typeof command === "string" && command.trim() ? command.trim() : undefined;
49
+ }
50
+
51
+ /**
52
+ * Returns the non-flag tokens that follow a Parall CLI invocation in
53
+ * `command`, or `null` if the command isn't a Parall CLI call.
54
+ *
55
+ * Handles all documented launch forms — bare `parall`, `npx [--yes|-y]
56
+ * @parall/cli[@version]`, `pnpm (exec|dlx) parall` — and skips npx flags so
57
+ * `npx --yes` matches the same way as `npx -y`. Uses space-delimited
58
+ * tokenization rather than a regex so that `messages send --no-reply` is
59
+ * correctly classified as a `messages send` invocation (not the receiver-side
60
+ * `no-reply` subcommand).
61
+ */
62
+ export function parseParallCliInvocation(command: string): string[] | null {
63
+ const tokens = command.replace(/\s+/g, " ").trim().split(" ");
64
+ let i = 0;
65
+ if (tokens[i] === "parall") {
66
+ i++;
67
+ } else if (tokens[i] === "npx") {
68
+ i++;
69
+ while (i < tokens.length && tokens[i].startsWith("-")) i++;
70
+ if (i >= tokens.length || !/^@parall\/cli(?:@.+)?$/.test(tokens[i])) return null;
71
+ i++;
72
+ } else if (tokens[i] === "pnpm") {
73
+ i++;
74
+ if (i < tokens.length && (tokens[i] === "exec" || tokens[i] === "dlx")) i++;
75
+ if (i >= tokens.length || tokens[i] !== "parall") return null;
76
+ i++;
77
+ } else {
78
+ return null;
79
+ }
80
+ return tokens.slice(i).filter((t) => !t.startsWith("-"));
81
+ }
82
+
83
+ /**
84
+ * Detects whether a shell command invokes the Parall CLI to send a
85
+ * chat-visible side effect (`messages send` or `dm`). Bridge adapters use
86
+ * this to suppress the immediately-following runtime text so the user
87
+ * doesn't see the same message twice — once from the CLI call, once
88
+ * projected from runtime output.
89
+ */
90
+ export function isParallSendCommand(command: string | undefined): boolean {
91
+ if (!command) return false;
92
+ const sub = parseParallCliInvocation(command);
93
+ if (!sub || sub.length === 0) return false;
94
+ return sub[0] === "dm" || (sub[0] === "messages" && sub[1] === "send");
95
+ }
96
+
97
+ /**
98
+ * Detects whether a shell command invokes `parall no-reply`, which signals
99
+ * the agent wants the whole turn silenced. Bridge adapters use this to
100
+ * flip a sticky suppression flag for the rest of the dispatch so no text
101
+ * event from that turn is projected into chat.
102
+ */
103
+ export function isParallNoReplyCommand(command: string | undefined): boolean {
104
+ if (!command) return false;
105
+ const sub = parseParallCliInvocation(command);
106
+ return sub?.[0] === "no-reply";
107
+ }
package/src/index.ts CHANGED
@@ -3,5 +3,6 @@ export * from "./session-state.js";
3
3
  export * from "./routing.js";
4
4
  export * from "./event-format.js";
5
5
  export * from "./prompt-fragments.js";
6
+ export * from "./bridge-workspace.js";
6
7
  export * from "./dispatch-adapter.js";
7
8
  export * from "./gateway-base.js";