@pragma-sh/sidecar-kit 0.1.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.
- package/README.md +18 -0
- package/package.json +38 -0
- package/src/index.ts +32 -0
package/README.md
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# @pragma-sh/sidecar-kit
|
|
2
|
+
|
|
3
|
+
NDJSON stdin helpers for Pragma host sidecars. Part of [Pragma](https://github.com/pragma-sh/pragma) — a desktop workspace for
|
|
4
|
+
running persistent, worktree-scoped coding agents.
|
|
5
|
+
|
|
6
|
+
Small shared runtime for a long-lived process a Pragma host supervises over
|
|
7
|
+
standard streams. Used by Pragma's own sidecars and by
|
|
8
|
+
[`@pragma-sh/automations`](https://www.npmjs.com/package/@pragma-sh/automations).
|
|
9
|
+
|
|
10
|
+
```sh
|
|
11
|
+
bun add @pragma-sh/sidecar-kit
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
Docs: <https://pragma-app.sh/docs>
|
|
15
|
+
|
|
16
|
+
## License
|
|
17
|
+
|
|
18
|
+
AGPL-3.0-only. See [LICENSE](https://github.com/pragma-sh/pragma/blob/main/LICENSE).
|
package/package.json
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@pragma-sh/sidecar-kit",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Shared stdin/NDJSON helpers for Pragma's Bun-compiled host sidecars.",
|
|
5
|
+
"homepage": "https://github.com/pragma-sh/pragma#readme",
|
|
6
|
+
"bugs": "https://github.com/pragma-sh/pragma/issues",
|
|
7
|
+
"license": "AGPL-3.0-only",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/pragma-sh/pragma.git",
|
|
11
|
+
"directory": "packages/sidecar-kit"
|
|
12
|
+
},
|
|
13
|
+
"files": [
|
|
14
|
+
"src",
|
|
15
|
+
"!src/**/*.test.ts"
|
|
16
|
+
],
|
|
17
|
+
"type": "module",
|
|
18
|
+
"main": "./src/index.ts",
|
|
19
|
+
"module": "./src/index.ts",
|
|
20
|
+
"types": "./src/index.ts",
|
|
21
|
+
"exports": {
|
|
22
|
+
".": "./src/index.ts",
|
|
23
|
+
"./package.json": "./package.json"
|
|
24
|
+
},
|
|
25
|
+
"publishConfig": {
|
|
26
|
+
"access": "public"
|
|
27
|
+
},
|
|
28
|
+
"scripts": {
|
|
29
|
+
"typecheck": "tsc --noEmit",
|
|
30
|
+
"test": "bun --bun vitest run",
|
|
31
|
+
"lint": "oxlint ."
|
|
32
|
+
},
|
|
33
|
+
"devDependencies": {
|
|
34
|
+
"@types/node": "^24.12.3",
|
|
35
|
+
"typescript": "^6.0.3",
|
|
36
|
+
"vitest": "^4.1.8"
|
|
37
|
+
}
|
|
38
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Splits `process.stdin` into trimmed, non-empty NDJSON lines and invokes
|
|
3
|
+
* `onLine` for each one. Shared by every host sidecar's line-buffered stdin
|
|
4
|
+
* reader (`pragma-ai`, `pragma-automations`, `pragma-plugins`) so the
|
|
5
|
+
* buffer-scan logic isn't hand-copied per package.
|
|
6
|
+
*
|
|
7
|
+
* `onEnd` runs exactly once when the supervising process closes stdin. A
|
|
8
|
+
* long-lived sidecar must use it to release its own timers/listeners and exit:
|
|
9
|
+
* parent death closes the pipe even when the parent cannot run Rust cleanup.
|
|
10
|
+
*/
|
|
11
|
+
export function readStdinLines(onLine: (line: string) => void, onEnd?: () => void): void {
|
|
12
|
+
let buffer = "";
|
|
13
|
+
let ended = false;
|
|
14
|
+
const finish = (): void => {
|
|
15
|
+
if (ended) return;
|
|
16
|
+
ended = true;
|
|
17
|
+
onEnd?.();
|
|
18
|
+
};
|
|
19
|
+
process.stdin.setEncoding("utf8");
|
|
20
|
+
process.stdin.on("data", (chunk: string) => {
|
|
21
|
+
buffer += chunk;
|
|
22
|
+
let newline = buffer.indexOf("\n");
|
|
23
|
+
while (newline >= 0) {
|
|
24
|
+
const line = buffer.slice(0, newline).trim();
|
|
25
|
+
buffer = buffer.slice(newline + 1);
|
|
26
|
+
if (line) onLine(line);
|
|
27
|
+
newline = buffer.indexOf("\n");
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
process.stdin.once("end", finish);
|
|
31
|
+
process.stdin.once("close", finish);
|
|
32
|
+
}
|