@ac-kit/app-system 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/LICENSE +28 -0
- package/README.md +45 -0
- package/dist/async/file-lock.d.ts +38 -0
- package/dist/async/file-lock.d.ts.map +1 -0
- package/dist/async/file-lock.js +67 -0
- package/dist/async/file-lock.js.map +1 -0
- package/dist/async/udp-bind-lock.d.ts +75 -0
- package/dist/async/udp-bind-lock.d.ts.map +1 -0
- package/dist/async/udp-bind-lock.js +85 -0
- package/dist/async/udp-bind-lock.js.map +1 -0
- package/dist/fs/artifact-cache.d.ts +124 -0
- package/dist/fs/artifact-cache.d.ts.map +1 -0
- package/dist/fs/artifact-cache.js +183 -0
- package/dist/fs/artifact-cache.js.map +1 -0
- package/dist/fs/rotate-log-files.d.ts +20 -0
- package/dist/fs/rotate-log-files.d.ts.map +1 -0
- package/dist/fs/rotate-log-files.js +45 -0
- package/dist/fs/rotate-log-files.js.map +1 -0
- package/dist/fs/rotating-file-sink.d.ts +42 -0
- package/dist/fs/rotating-file-sink.d.ts.map +1 -0
- package/dist/fs/rotating-file-sink.js +213 -0
- package/dist/fs/rotating-file-sink.js.map +1 -0
- package/dist/index.d.ts +23 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +23 -0
- package/dist/index.js.map +1 -0
- package/dist/os/get-processes-snapshot.d.ts +56 -0
- package/dist/os/get-processes-snapshot.d.ts.map +1 -0
- package/dist/os/get-processes-snapshot.js +197 -0
- package/dist/os/get-processes-snapshot.js.map +1 -0
- package/dist/os/host-metrics.d.ts +43 -0
- package/dist/os/host-metrics.d.ts.map +1 -0
- package/dist/os/host-metrics.js +78 -0
- package/dist/os/host-metrics.js.map +1 -0
- package/dist/os/process-kill-by-pid-file.d.ts +35 -0
- package/dist/os/process-kill-by-pid-file.d.ts.map +1 -0
- package/dist/os/process-kill-by-pid-file.js +48 -0
- package/dist/os/process-kill-by-pid-file.js.map +1 -0
- package/dist/os/process-wait-pid.d.ts +18 -0
- package/dist/os/process-wait-pid.d.ts.map +1 -0
- package/dist/os/process-wait-pid.js +26 -0
- package/dist/os/process-wait-pid.js.map +1 -0
- package/dist/os/ps.d.ts +98 -0
- package/dist/os/ps.d.ts.map +1 -0
- package/dist/os/ps.js +165 -0
- package/dist/os/ps.js.map +1 -0
- package/dist/os/sysfs.d.ts +19 -0
- package/dist/os/sysfs.d.ts.map +1 -0
- package/dist/os/sysfs.js +66 -0
- package/dist/os/sysfs.js.map +1 -0
- package/dist/process/child-process-message-sink.d.ts +21 -0
- package/dist/process/child-process-message-sink.d.ts.map +1 -0
- package/dist/process/child-process-message-sink.js +16 -0
- package/dist/process/child-process-message-sink.js.map +1 -0
- package/dist/process/error-listeners.d.ts +56 -0
- package/dist/process/error-listeners.d.ts.map +1 -0
- package/dist/process/error-listeners.js +113 -0
- package/dist/process/error-listeners.js.map +1 -0
- package/dist/process/exit-manager.d.ts +58 -0
- package/dist/process/exit-manager.d.ts.map +1 -0
- package/dist/process/exit-manager.js +88 -0
- package/dist/process/exit-manager.js.map +1 -0
- package/dist/process/has-binary.d.ts +25 -0
- package/dist/process/has-binary.d.ts.map +1 -0
- package/dist/process/has-binary.js +35 -0
- package/dist/process/has-binary.js.map +1 -0
- package/dist/process/pid-file.d.ts +17 -0
- package/dist/process/pid-file.d.ts.map +1 -0
- package/dist/process/pid-file.js +25 -0
- package/dist/process/pid-file.js.map +1 -0
- package/dist/process/process-pid-file.d.ts +37 -0
- package/dist/process/process-pid-file.d.ts.map +1 -0
- package/dist/process/process-pid-file.js +57 -0
- package/dist/process/process-pid-file.js.map +1 -0
- package/dist/process/report-process.d.ts +36 -0
- package/dist/process/report-process.d.ts.map +1 -0
- package/dist/process/report-process.js +121 -0
- package/dist/process/report-process.js.map +1 -0
- package/dist/shell/shorten-posix-path.d.ts +10 -0
- package/dist/shell/shorten-posix-path.d.ts.map +1 -0
- package/dist/shell/shorten-posix-path.js +19 -0
- package/dist/shell/shorten-posix-path.js.map +1 -0
- package/dist/terminal/node-terminal.d.ts +11 -0
- package/dist/terminal/node-terminal.d.ts.map +1 -0
- package/dist/terminal/node-terminal.js +162 -0
- package/dist/terminal/node-terminal.js.map +1 -0
- package/dist/text/charset-decode-stream.d.ts +13 -0
- package/dist/text/charset-decode-stream.d.ts.map +1 -0
- package/dist/text/charset-decode-stream.js +51 -0
- package/dist/text/charset-decode-stream.js.map +1 -0
- package/dist/text/charset-encode-stream.d.ts +12 -0
- package/dist/text/charset-encode-stream.d.ts.map +1 -0
- package/dist/text/charset-encode-stream.js +47 -0
- package/dist/text/charset-encode-stream.js.map +1 -0
- package/package.json +75 -0
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export type HasBinaryOptions = {
|
|
2
|
+
/** Working directory for the resolver process. Default: `process.cwd()`. */
|
|
3
|
+
cwd?: string;
|
|
4
|
+
/**
|
|
5
|
+
* Environment variables for the resolver process (affects `PATH`). Default:
|
|
6
|
+
* `process.env`.
|
|
7
|
+
*/
|
|
8
|
+
env?: NodeJS.ProcessEnv;
|
|
9
|
+
/** Aborts the check. */
|
|
10
|
+
signal?: AbortSignal;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Check whether a binary is available on `PATH`.
|
|
14
|
+
*
|
|
15
|
+
* Delegates to the platform's own resolver (`which` on POSIX, `where` on
|
|
16
|
+
* Windows) instead of re-implementing `PATH`/`PATHEXT` lookup.
|
|
17
|
+
*
|
|
18
|
+
* @param command Executable name.
|
|
19
|
+
* @param options
|
|
20
|
+
* @returns `true` unless the command cannot be found.
|
|
21
|
+
* @throws {Error} If the platform resolver itself (`which`/`where`) is not
|
|
22
|
+
* available on this system.
|
|
23
|
+
*/
|
|
24
|
+
export declare function hasBinary(command: string, options?: HasBinaryOptions): Promise<boolean>;
|
|
25
|
+
//# sourceMappingURL=has-binary.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"has-binary.d.ts","sourceRoot":"","sources":["../../src/process/has-binary.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,gBAAgB,GAAG;IAC9B,4EAA4E;IAC5E,GAAG,CAAC,EAAE,MAAM,CAAC;IAEb;;;OAGG;IACH,GAAG,CAAC,EAAE,MAAM,CAAC,UAAU,CAAC;IAExB,wBAAwB;IACxB,MAAM,CAAC,EAAE,WAAW,CAAC;CACrB,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,wBAAsB,SAAS,CAC9B,OAAO,EAAE,MAAM,EACf,OAAO,CAAC,EAAE,gBAAgB,GACxB,OAAO,CAAC,OAAO,CAAC,CAsBlB"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { isNodeErrorWithCode, spawnProcess } from "@ac-kit/node";
|
|
2
|
+
/**
|
|
3
|
+
* Check whether a binary is available on `PATH`.
|
|
4
|
+
*
|
|
5
|
+
* Delegates to the platform's own resolver (`which` on POSIX, `where` on
|
|
6
|
+
* Windows) instead of re-implementing `PATH`/`PATHEXT` lookup.
|
|
7
|
+
*
|
|
8
|
+
* @param command Executable name.
|
|
9
|
+
* @param options
|
|
10
|
+
* @returns `true` unless the command cannot be found.
|
|
11
|
+
* @throws {Error} If the platform resolver itself (`which`/`where`) is not
|
|
12
|
+
* available on this system.
|
|
13
|
+
*/
|
|
14
|
+
export async function hasBinary(command, options) {
|
|
15
|
+
const resolver = process.platform === "win32" ? "where" : "which";
|
|
16
|
+
try {
|
|
17
|
+
await spawnProcess(resolver, [command], {
|
|
18
|
+
cwd: options?.cwd,
|
|
19
|
+
env: options?.env,
|
|
20
|
+
signal: options?.signal,
|
|
21
|
+
});
|
|
22
|
+
return true;
|
|
23
|
+
}
|
|
24
|
+
catch (error) {
|
|
25
|
+
if (isNodeErrorWithCode(error, "ENOENT")) {
|
|
26
|
+
throw new Error(`"${resolver}" is not available on this system`);
|
|
27
|
+
}
|
|
28
|
+
if (options?.signal?.aborted) {
|
|
29
|
+
throw error;
|
|
30
|
+
}
|
|
31
|
+
// which/where exit non-zero specifically to report "not found".
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=has-binary.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"has-binary.js","sourceRoot":"","sources":["../../src/process/has-binary.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAgBjE;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,KAAK,UAAU,SAAS,CAC9B,OAAe,EACf,OAA0B;IAE1B,MAAM,QAAQ,GAAG,OAAO,CAAC,QAAQ,KAAK,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC;IAElE,IAAI,CAAC;QACJ,MAAM,YAAY,CAAC,QAAQ,EAAE,CAAC,OAAO,CAAC,EAAE;YACvC,GAAG,EAAE,OAAO,EAAE,GAAG;YACjB,GAAG,EAAE,OAAO,EAAE,GAAG;YACjB,MAAM,EAAE,OAAO,EAAE,MAAM;SACvB,CAAC,CAAC;QACH,OAAO,IAAI,CAAC;IACb,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QAChB,IAAI,mBAAmB,CAAC,KAAK,EAAE,QAAQ,CAAC,EAAE,CAAC;YAC1C,MAAM,IAAI,KAAK,CAAC,IAAI,QAAQ,mCAAmC,CAAC,CAAC;QAClE,CAAC;QAED,IAAI,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC;YAC9B,MAAM,KAAK,CAAC;QACb,CAAC;QAED,gEAAgE;QAChE,OAAO,KAAK,CAAC;IACd,CAAC;AACF,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { PathLike } from "node:fs";
|
|
2
|
+
import { readFile, writeFile } from "node:fs/promises";
|
|
3
|
+
/**
|
|
4
|
+
* Read a PID from a file.
|
|
5
|
+
*
|
|
6
|
+
* @param path The path to the PID file.
|
|
7
|
+
* @returns The PID read from the file.
|
|
8
|
+
*/
|
|
9
|
+
export declare function readPidFile(path: PathLike, options?: Parameters<typeof readFile>[1]): Promise<number>;
|
|
10
|
+
/**
|
|
11
|
+
* Write a PID to a file.
|
|
12
|
+
*
|
|
13
|
+
* @param path The path to the PID file.
|
|
14
|
+
* @param pid The PID to write to the file.
|
|
15
|
+
*/
|
|
16
|
+
export declare function writePidFile(path: PathLike, pid: number, options?: Parameters<typeof writeFile>[2]): Promise<void>;
|
|
17
|
+
//# sourceMappingURL=pid-file.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pid-file.d.ts","sourceRoot":"","sources":["../../src/process/pid-file.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACxC,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAEvD;;;;;GAKG;AACH,wBAAsB,WAAW,CAChC,IAAI,EAAE,QAAQ,EACd,OAAO,CAAC,EAAE,UAAU,CAAC,OAAO,QAAQ,CAAC,CAAC,CAAC,CAAC,GACtC,OAAO,CAAC,MAAM,CAAC,CASjB;AAED;;;;;GAKG;AACH,wBAAsB,YAAY,CACjC,IAAI,EAAE,QAAQ,EACd,GAAG,EAAE,MAAM,EACX,OAAO,CAAC,EAAE,UAAU,CAAC,OAAO,SAAS,CAAC,CAAC,CAAC,CAAC,GACvC,OAAO,CAAC,IAAI,CAAC,CAEf"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { readFile, writeFile } from "node:fs/promises";
|
|
2
|
+
/**
|
|
3
|
+
* Read a PID from a file.
|
|
4
|
+
*
|
|
5
|
+
* @param path The path to the PID file.
|
|
6
|
+
* @returns The PID read from the file.
|
|
7
|
+
*/
|
|
8
|
+
export async function readPidFile(path, options) {
|
|
9
|
+
const content = await readFile(path, options ?? null);
|
|
10
|
+
const pid = parseInt(content.toString(), 10);
|
|
11
|
+
if (Number.isNaN(pid)) {
|
|
12
|
+
throw new Error(`Invalid PID in file: ${path.toString()}`);
|
|
13
|
+
}
|
|
14
|
+
return pid;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Write a PID to a file.
|
|
18
|
+
*
|
|
19
|
+
* @param path The path to the PID file.
|
|
20
|
+
* @param pid The PID to write to the file.
|
|
21
|
+
*/
|
|
22
|
+
export async function writePidFile(path, pid, options) {
|
|
23
|
+
await writeFile(path, pid.toString(), options);
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=pid-file.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pid-file.js","sourceRoot":"","sources":["../../src/process/pid-file.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAEvD;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAChC,IAAc,EACd,OAAwC;IAExC,MAAM,OAAO,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,OAAO,IAAI,IAAI,CAAC,CAAC;IAEtD,MAAM,GAAG,GAAG,QAAQ,CAAC,OAAO,CAAC,QAAQ,EAAE,EAAE,EAAE,CAAC,CAAC;IAC7C,IAAI,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC;QACvB,MAAM,IAAI,KAAK,CAAC,wBAAwB,IAAI,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC;IAC5D,CAAC;IAED,OAAO,GAAG,CAAC;AACZ,CAAC;AAED;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY,CACjC,IAAc,EACd,GAAW,EACX,OAAyC;IAEzC,MAAM,SAAS,CAAC,IAAI,EAAE,GAAG,CAAC,QAAQ,EAAE,EAAE,OAAO,CAAC,CAAC;AAChD,CAAC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Class to manage a PID file for the current process.
|
|
3
|
+
*
|
|
4
|
+
* This class provides methods to write the current process PID to a specified
|
|
5
|
+
* file and to remove the PID file when it is no longer needed.
|
|
6
|
+
*
|
|
7
|
+
* Note: The PID file is automatically removed when the process exits, if it was
|
|
8
|
+
* created by this class instance.
|
|
9
|
+
*
|
|
10
|
+
* Example usage:
|
|
11
|
+
*
|
|
12
|
+
* ```ts
|
|
13
|
+
* const pidFile = new ProcessPidFile("/var/run/myapp.pid");
|
|
14
|
+
* await pidFile.write();
|
|
15
|
+
* // ... application logic ...
|
|
16
|
+
* await pidFile.remove();
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
export declare class ProcessPidFile {
|
|
20
|
+
private readonly filePath;
|
|
21
|
+
private exitHandler;
|
|
22
|
+
constructor(filePath: string);
|
|
23
|
+
/**
|
|
24
|
+
* Writes the current process PID to the PID file and sets up a handler to
|
|
25
|
+
* remove the PID file on process exit.
|
|
26
|
+
*
|
|
27
|
+
* Note: If the process crashes or is forcefully terminated, the PID file may
|
|
28
|
+
* not be removed. In such cases, manual cleanup may be necessary.
|
|
29
|
+
*
|
|
30
|
+
* This method ensures that the directory for the PID file exists before
|
|
31
|
+
* writing the file.
|
|
32
|
+
*/
|
|
33
|
+
write(): Promise<void>;
|
|
34
|
+
/** Removes the PID file if it exists and cleans up the exit handler. */
|
|
35
|
+
remove(): Promise<void>;
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=process-pid-file.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"process-pid-file.d.ts","sourceRoot":"","sources":["../../src/process/process-pid-file.ts"],"names":[],"mappings":"AASA;;;;;;;;;;;;;;;;;GAiBG;AACH,qBAAa,cAAc;IAGd,OAAO,CAAC,QAAQ,CAAC,QAAQ;IAFrC,OAAO,CAAC,WAAW,CAAyB;IAE5C,YAA6B,QAAQ,EAAE,MAAM,EAAI;IAEjD;;;;;;;;;OASG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAW3B;IAED,wEAAwE;IAClE,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC,CAO5B;CACD"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { existsSync, unlinkSync } from "node:fs";
|
|
2
|
+
import { unlink } from "node:fs/promises";
|
|
3
|
+
import { existsAsync } from "@ac-kit/node";
|
|
4
|
+
import { ExitManager, ExitManagerPriority } from "./exit-manager.js";
|
|
5
|
+
import { writePidFile } from "./pid-file.js";
|
|
6
|
+
/**
|
|
7
|
+
* Class to manage a PID file for the current process.
|
|
8
|
+
*
|
|
9
|
+
* This class provides methods to write the current process PID to a specified
|
|
10
|
+
* file and to remove the PID file when it is no longer needed.
|
|
11
|
+
*
|
|
12
|
+
* Note: The PID file is automatically removed when the process exits, if it was
|
|
13
|
+
* created by this class instance.
|
|
14
|
+
*
|
|
15
|
+
* Example usage:
|
|
16
|
+
*
|
|
17
|
+
* ```ts
|
|
18
|
+
* const pidFile = new ProcessPidFile("/var/run/myapp.pid");
|
|
19
|
+
* await pidFile.write();
|
|
20
|
+
* // ... application logic ...
|
|
21
|
+
* await pidFile.remove();
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
export class ProcessPidFile {
|
|
25
|
+
filePath;
|
|
26
|
+
exitHandler = null;
|
|
27
|
+
constructor(filePath) {
|
|
28
|
+
this.filePath = filePath;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Writes the current process PID to the PID file and sets up a handler to
|
|
32
|
+
* remove the PID file on process exit.
|
|
33
|
+
*
|
|
34
|
+
* Note: If the process crashes or is forcefully terminated, the PID file may
|
|
35
|
+
* not be removed. In such cases, manual cleanup may be necessary.
|
|
36
|
+
*
|
|
37
|
+
* This method ensures that the directory for the PID file exists before
|
|
38
|
+
* writing the file.
|
|
39
|
+
*/
|
|
40
|
+
async write() {
|
|
41
|
+
await writePidFile(this.filePath, process.pid);
|
|
42
|
+
this.exitHandler = ExitManager.getInstance().registerExitHandler(async () => {
|
|
43
|
+
if (existsSync(this.filePath)) {
|
|
44
|
+
unlinkSync(this.filePath);
|
|
45
|
+
}
|
|
46
|
+
}, ExitManagerPriority.VERY_LATE);
|
|
47
|
+
}
|
|
48
|
+
/** Removes the PID file if it exists and cleans up the exit handler. */
|
|
49
|
+
async remove() {
|
|
50
|
+
if (await existsAsync(this.filePath)) {
|
|
51
|
+
await unlink(this.filePath);
|
|
52
|
+
}
|
|
53
|
+
this.exitHandler?.();
|
|
54
|
+
this.exitHandler = null;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
//# sourceMappingURL=process-pid-file.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"process-pid-file.js","sourceRoot":"","sources":["../../src/process/process-pid-file.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACjD,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAG1C,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAE3C,OAAO,EAAE,WAAW,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AACrE,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAE7C;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,OAAO,cAAc;IAGG,QAAQ;IAF7B,WAAW,GAAoB,IAAI,CAAC;IAE5C,YAA6B,QAAgB;wBAAhB,QAAQ;IAAW,CAAC;IAEjD;;;;;;;;;OASG;IACH,KAAK,CAAC,KAAK;QACV,MAAM,YAAY,CAAC,IAAI,CAAC,QAAQ,EAAE,OAAO,CAAC,GAAG,CAAC,CAAC;QAE/C,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC,WAAW,EAAE,CAAC,mBAAmB,CAC/D,KAAK,IAAI,EAAE;YACV,IAAI,UAAU,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC;gBAC/B,UAAU,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;YAC3B,CAAC;QACF,CAAC,EACD,mBAAmB,CAAC,SAAS,CAC7B,CAAC;IACH,CAAC;IAED,wEAAwE;IACxE,KAAK,CAAC,MAAM;QACX,IAAI,MAAM,WAAW,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC;YACtC,MAAM,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QAC7B,CAAC;QAED,IAAI,CAAC,WAAW,EAAE,EAAE,CAAC;QACrB,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC;IACzB,CAAC;CACD"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { type ISink, type ReportScopeId } from "@ac-kit/app-report";
|
|
2
|
+
import { type ProcessResult, type SpawnProcessOptions, type SpawnedProcess } from "@ac-kit/node";
|
|
3
|
+
export type SpawnReportedProcessOptions = SpawnProcessOptions & {
|
|
4
|
+
/** Receives the scope, the output lines and the outcome. */
|
|
5
|
+
readonly sink: ISink<never>;
|
|
6
|
+
/** Nests the process scope under an open one. */
|
|
7
|
+
readonly parentScopeId?: ReportScopeId | null;
|
|
8
|
+
/** Scope title. Defaults to the command. */
|
|
9
|
+
readonly title?: string | null;
|
|
10
|
+
/** Scope key. Defaults to the command. */
|
|
11
|
+
readonly key?: string | null;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Streams a running child's output into a sink, one `output` event per line.
|
|
15
|
+
*
|
|
16
|
+
* @param child The handle to read from; its stream must have been piped.
|
|
17
|
+
* @param sink The destination.
|
|
18
|
+
* @param scopeId Attributes the events to an already-open scope.
|
|
19
|
+
* @returns A promise resolving once the child has exited and every event has
|
|
20
|
+
* been written.
|
|
21
|
+
*/
|
|
22
|
+
export declare function reportProcessOutput(child: SpawnedProcess, sink: ISink<never>, scopeId?: ReportScopeId | null): Promise<void>;
|
|
23
|
+
/**
|
|
24
|
+
* Runs a command as a reported scope: a `scope-start`/`scope-end` pair carrying
|
|
25
|
+
* the command, working directory, exit code and signal, wrapping one `output`
|
|
26
|
+
* event per line the child printed.
|
|
27
|
+
*
|
|
28
|
+
* @param command The executable to run.
|
|
29
|
+
* @param args Arguments passed to it verbatim.
|
|
30
|
+
* @param options The sink and scope identity, plus everything
|
|
31
|
+
* {@link SpawnProcessOptions} accepts.
|
|
32
|
+
* @returns The exit status and the captured streams.
|
|
33
|
+
* @throws Whatever `spawnProcess` throws, after the scope has been closed.
|
|
34
|
+
*/
|
|
35
|
+
export declare function spawnReportedProcess(command: string, args: readonly string[] | undefined, options: SpawnReportedProcessOptions): Promise<ProcessResult>;
|
|
36
|
+
//# sourceMappingURL=report-process.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"report-process.d.ts","sourceRoot":"","sources":["../../src/process/report-process.ts"],"names":[],"mappings":"AAAA,OAAO,EAKN,KAAK,KAAK,EACV,KAAK,aAAa,EAElB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAEN,KAAK,aAAa,EAClB,KAAK,mBAAmB,EACxB,KAAK,cAAc,EAEnB,MAAM,cAAc,CAAC;AAEtB,MAAM,MAAM,2BAA2B,GAAG,mBAAmB,GAAG;IAC/D,4DAA4D;IAC5D,QAAQ,CAAC,IAAI,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC;IAE5B,iDAAiD;IACjD,QAAQ,CAAC,aAAa,CAAC,EAAE,aAAa,GAAG,IAAI,CAAC;IAE9C,4CAA4C;IAC5C,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAE/B,0CAA0C;IAC1C,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAC7B,CAAC;AAEF;;;;;;;;GAQG;AACH,wBAAsB,mBAAmB,CACxC,KAAK,EAAE,cAAc,EACrB,IAAI,EAAE,KAAK,CAAC,KAAK,CAAC,EAClB,OAAO,GAAE,aAAa,GAAG,IAAW,GAClC,OAAO,CAAC,IAAI,CAAC,CAoBf;AAkBD;;;;;;;;;;;GAWG;AACH,wBAAsB,oBAAoB,CACzC,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,SAAS,MAAM,EAAE,GAAG,SAAS,EACnC,OAAO,EAAE,2BAA2B,GAClC,OAAO,CAAC,aAAa,CAAC,CAuExB"}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { ATTR_PROCESS_COMMAND, ATTR_PROCESS_CWD, ATTR_PROCESS_EXIT_CODE, ATTR_PROCESS_SIGNAL, } from "@ac-kit/app-report";
|
|
2
|
+
import { ProcessExitError, spawnProcess, } from "@ac-kit/node";
|
|
3
|
+
/**
|
|
4
|
+
* Streams a running child's output into a sink, one `output` event per line.
|
|
5
|
+
*
|
|
6
|
+
* @param child The handle to read from; its stream must have been piped.
|
|
7
|
+
* @param sink The destination.
|
|
8
|
+
* @param scopeId Attributes the events to an already-open scope.
|
|
9
|
+
* @returns A promise resolving once the child has exited and every event has
|
|
10
|
+
* been written.
|
|
11
|
+
*/
|
|
12
|
+
export async function reportProcessOutput(child, sink, scopeId = null) {
|
|
13
|
+
const written = [];
|
|
14
|
+
// Subscribes before the first await, so no line can slip past.
|
|
15
|
+
child.subscribe("output", (stream, line) => {
|
|
16
|
+
// A synchronous sink returns nothing and needs no bookkeeping.
|
|
17
|
+
const pending = sink.write({
|
|
18
|
+
kind: "output",
|
|
19
|
+
timestamp: Date.now(),
|
|
20
|
+
scopeId,
|
|
21
|
+
stream,
|
|
22
|
+
chunk: line,
|
|
23
|
+
});
|
|
24
|
+
if (pending) {
|
|
25
|
+
written.push(pending);
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
await child.waitForExit();
|
|
29
|
+
await Promise.all(written);
|
|
30
|
+
}
|
|
31
|
+
function exitAttributes_(result, failure) {
|
|
32
|
+
if (result) {
|
|
33
|
+
return { code: result.code, signal: result.signal };
|
|
34
|
+
}
|
|
35
|
+
if (failure instanceof ProcessExitError) {
|
|
36
|
+
return {
|
|
37
|
+
code: typeof failure.code === "number" ? failure.code : null,
|
|
38
|
+
signal: failure.signal,
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
return { code: null, signal: null };
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Runs a command as a reported scope: a `scope-start`/`scope-end` pair carrying
|
|
45
|
+
* the command, working directory, exit code and signal, wrapping one `output`
|
|
46
|
+
* event per line the child printed.
|
|
47
|
+
*
|
|
48
|
+
* @param command The executable to run.
|
|
49
|
+
* @param args Arguments passed to it verbatim.
|
|
50
|
+
* @param options The sink and scope identity, plus everything
|
|
51
|
+
* {@link SpawnProcessOptions} accepts.
|
|
52
|
+
* @returns The exit status and the captured streams.
|
|
53
|
+
* @throws Whatever `spawnProcess` throws, after the scope has been closed.
|
|
54
|
+
*/
|
|
55
|
+
export async function spawnReportedProcess(command, args, options) {
|
|
56
|
+
const { sink, parentScopeId, title, key, ...spawnOptions } = options;
|
|
57
|
+
const startedAt = Date.now();
|
|
58
|
+
const cwd = options.cwd ?? process.cwd();
|
|
59
|
+
const scopeId = globalThis.crypto.randomUUID();
|
|
60
|
+
await sink.write({
|
|
61
|
+
kind: "scope-start",
|
|
62
|
+
timestamp: startedAt,
|
|
63
|
+
scopeId,
|
|
64
|
+
parentId: parentScopeId ?? null,
|
|
65
|
+
title: title ?? command,
|
|
66
|
+
key: key ?? command,
|
|
67
|
+
attributes: { [ATTR_PROCESS_COMMAND]: command, [ATTR_PROCESS_CWD]: cwd },
|
|
68
|
+
});
|
|
69
|
+
const written = [];
|
|
70
|
+
let result = null;
|
|
71
|
+
let failure = null;
|
|
72
|
+
try {
|
|
73
|
+
result = await spawnProcess(command, args, {
|
|
74
|
+
...spawnOptions,
|
|
75
|
+
onOutput: (stream, line) => {
|
|
76
|
+
const pending = sink.write({
|
|
77
|
+
kind: "output",
|
|
78
|
+
timestamp: Date.now(),
|
|
79
|
+
scopeId,
|
|
80
|
+
stream,
|
|
81
|
+
chunk: line,
|
|
82
|
+
});
|
|
83
|
+
if (pending) {
|
|
84
|
+
written.push(pending);
|
|
85
|
+
}
|
|
86
|
+
},
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
catch (error) {
|
|
90
|
+
failure = error;
|
|
91
|
+
}
|
|
92
|
+
await Promise.all(written);
|
|
93
|
+
const exit = exitAttributes_(result, failure);
|
|
94
|
+
const durationMs = Date.now() - startedAt;
|
|
95
|
+
const status = options.signal?.aborted
|
|
96
|
+
? "cancelled"
|
|
97
|
+
: failure !== null || exit.code !== 0
|
|
98
|
+
? "failed"
|
|
99
|
+
: "ok";
|
|
100
|
+
await sink.write({
|
|
101
|
+
kind: "scope-end",
|
|
102
|
+
timestamp: startedAt + durationMs,
|
|
103
|
+
scopeId,
|
|
104
|
+
status,
|
|
105
|
+
durationMs,
|
|
106
|
+
...(status === "failed" && failure instanceof Error
|
|
107
|
+
? { error: failure }
|
|
108
|
+
: {}),
|
|
109
|
+
attributes: {
|
|
110
|
+
[ATTR_PROCESS_COMMAND]: command,
|
|
111
|
+
[ATTR_PROCESS_CWD]: cwd,
|
|
112
|
+
[ATTR_PROCESS_EXIT_CODE]: exit.code,
|
|
113
|
+
[ATTR_PROCESS_SIGNAL]: exit.signal,
|
|
114
|
+
},
|
|
115
|
+
});
|
|
116
|
+
if (failure !== null) {
|
|
117
|
+
throw failure;
|
|
118
|
+
}
|
|
119
|
+
return result;
|
|
120
|
+
}
|
|
121
|
+
//# sourceMappingURL=report-process.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"report-process.js","sourceRoot":"","sources":["../../src/process/report-process.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,oBAAoB,EACpB,gBAAgB,EAChB,sBAAsB,EACtB,mBAAmB,GAInB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EACN,gBAAgB,EAIhB,YAAY,GACZ,MAAM,cAAc,CAAC;AAgBtB;;;;;;;;GAQG;AACH,MAAM,CAAC,KAAK,UAAU,mBAAmB,CACxC,KAAqB,EACrB,IAAkB,EAClB,OAAO,GAAyB,IAAI;IAEpC,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AAC,CAAC;IAE3B,MAAM,IAAI,GAAG,eAAe,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC9C,MAAM,UAAU,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,SAAS,CAAC;IAC1C,MAAM,MAAM,GAAsB,OAAO,CAAC,MAAM,EAAE,OAAO;QACxD,CAAC,CAAC,WAAW;QACb,CAAC,CAAC,OAAO,KAAK,IAAI,IAAI,IAAI,CAAC,IAAI,KAAK,CAAC;YACpC,CAAC,CAAC,QAAQ;YACV,CAAC,CAAC,IAAI,CAAC;IAET,MAAM,IAAI,CAAC,KAAK,CAAC;QAChB,IAAI,EAAE,WAAW;QACjB,SAAS,EAAE,SAAS,GAAG,UAAU;QACjC,OAAO;QACP,MAAM;QACN,UAAU;QACV,GAAG,CAAC,MAAM,KAAK,QAAQ,IAAI,OAAO,YAAY,KAAK;YAClD,CAAC,CAAC,EAAE,KAAK,EAAE,OAAO,EAAE;YACpB,CAAC,CAAC,EAAE,CAAC;QACN,UAAU,EAAE;YACX,CAAC,oBAAoB,CAAC,EAAE,OAAO;YAC/B,CAAC,gBAAgB,CAAC,EAAE,GAAG;YACvB,CAAC,sBAAsB,CAAC,EAAE,IAAI,CAAC,IAAI;YACnC,CAAC,mBAAmB,CAAC,EAAE,IAAI,CAAC,MAAM;SAClC;KACD,CAAC,CAAC;IAEH,IAAI,OAAO,KAAK,IAAI,EAAE,CAAC;QACtB,MAAM,OAAO,CAAC;IACf,CAAC;IACD,OAAO,MAAuB,CAAC;AAChC,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns the path relative to the current working directory or to the home
|
|
3
|
+
* directory, whichever is shorter. If the path is the current working
|
|
4
|
+
* directory, returns ".".
|
|
5
|
+
*
|
|
6
|
+
* @param path The path to make relative.
|
|
7
|
+
* @returns The relative path.
|
|
8
|
+
*/
|
|
9
|
+
export declare function shortenPosixPath(path: string): string;
|
|
10
|
+
//# sourceMappingURL=shorten-posix-path.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shorten-posix-path.d.ts","sourceRoot":"","sources":["../../src/shell/shorten-posix-path.ts"],"names":[],"mappings":"AAEA;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAarD"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { relative as relativePath } from "node:path";
|
|
2
|
+
/**
|
|
3
|
+
* Returns the path relative to the current working directory or to the home
|
|
4
|
+
* directory, whichever is shorter. If the path is the current working
|
|
5
|
+
* directory, returns ".".
|
|
6
|
+
*
|
|
7
|
+
* @param path The path to make relative.
|
|
8
|
+
* @returns The relative path.
|
|
9
|
+
*/
|
|
10
|
+
export function shortenPosixPath(path) {
|
|
11
|
+
const fromCwd = relativePath(process.cwd(), path);
|
|
12
|
+
let fromHome;
|
|
13
|
+
if (process.env.HOME) {
|
|
14
|
+
const relativeFromHome = relativePath(process.env.HOME, path);
|
|
15
|
+
fromHome = `~${relativeFromHome ? `/${relativeFromHome}` : ""}`;
|
|
16
|
+
}
|
|
17
|
+
return ((fromHome && fromHome.length < fromCwd.length ? fromHome : fromCwd) || ".");
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=shorten-posix-path.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shorten-posix-path.js","sourceRoot":"","sources":["../../src/shell/shorten-posix-path.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,IAAI,YAAY,EAAE,MAAM,WAAW,CAAC;AAErD;;;;;;;GAOG;AACH,MAAM,UAAU,gBAAgB,CAAC,IAAY;IAC5C,MAAM,OAAO,GAAG,YAAY,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,IAAI,CAAC,CAAC;IAElD,IAAI,QAA4B,CAAC;IAEjC,IAAI,OAAO,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC;QACtB,MAAM,gBAAgB,GAAG,YAAY,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;QAC9D,QAAQ,GAAG,IAAI,gBAAgB,CAAC,CAAC,CAAC,IAAI,gBAAgB,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC;IACjE,CAAC;IAED,OAAO,CACN,CAAC,QAAQ,IAAI,QAAQ,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,GAAG,CAC1E,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Terminal } from "@ac-kit/app-terminal";
|
|
2
|
+
/**
|
|
3
|
+
* The Node adapter for `Terminal` (`@ac-kit/app-terminal`) — reads `stream`'s
|
|
4
|
+
* TTY properties and `process.env`.
|
|
5
|
+
*
|
|
6
|
+
* `columns`/`rows` are getters, not values captured at construction: they must
|
|
7
|
+
* reflect the terminal's current size after a `resize` event fires, not its
|
|
8
|
+
* size when `nodeTerminal` was called.
|
|
9
|
+
*/
|
|
10
|
+
export declare function nodeTerminal(stream: NodeJS.WriteStream): Terminal;
|
|
11
|
+
//# sourceMappingURL=node-terminal.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"node-terminal.d.ts","sourceRoot":"","sources":["../../src/terminal/node-terminal.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AA8JrD;;;;;;;GAOG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,MAAM,CAAC,WAAW,GAAG,QAAQ,CAwCjE"}
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import { existsSync } from "node:fs";
|
|
2
|
+
import { VoidEvent } from "@ac-kit/async";
|
|
3
|
+
import { CLEAR_SCREEN, ENTER_ALT_SCREEN, EXIT_ALT_SCREEN, } from "@ac-kit/format-ansi";
|
|
4
|
+
/**
|
|
5
|
+
* Heuristics below match the widely-used `is-unicode-supported`/
|
|
6
|
+
* `supports-hyperlinks` packages' logic — not proprietary, just the standard
|
|
7
|
+
* approach every terminal-capability-detection library converges on. Always
|
|
8
|
+
* false-positive/false-negative prone by nature (a terminal can lie about
|
|
9
|
+
* itself via env vars); `hyperlinks`/`unicode` are advisory, not guaranteed.
|
|
10
|
+
*/
|
|
11
|
+
function detectUnicodeSupport(env) {
|
|
12
|
+
if (process.platform !== "win32") {
|
|
13
|
+
return env.TERM !== "linux";
|
|
14
|
+
}
|
|
15
|
+
return Boolean(env.CI ||
|
|
16
|
+
env.WT_SESSION ||
|
|
17
|
+
env.TERMINUS_SUBLIME ||
|
|
18
|
+
env.ConEmuTask === "{cmd::Cmder}" ||
|
|
19
|
+
env.TERM_PROGRAM === "vscode" ||
|
|
20
|
+
env.TERM === "xterm-256color" ||
|
|
21
|
+
env.TERM === "alacritty");
|
|
22
|
+
}
|
|
23
|
+
const HYPERLINK_TERM_PROGRAMS = new Set([
|
|
24
|
+
"vscode",
|
|
25
|
+
"hyper",
|
|
26
|
+
"wezterm",
|
|
27
|
+
"iterm.app",
|
|
28
|
+
]);
|
|
29
|
+
function detectHyperlinkSupport(interactive, env) {
|
|
30
|
+
if (env.FORCE_HYPERLINK && env.FORCE_HYPERLINK !== "0") {
|
|
31
|
+
return true;
|
|
32
|
+
}
|
|
33
|
+
if (!interactive || env.CI) {
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
36
|
+
if (process.platform === "win32") {
|
|
37
|
+
return Boolean(env.WT_SESSION);
|
|
38
|
+
}
|
|
39
|
+
if (env.TERM_PROGRAM) {
|
|
40
|
+
return HYPERLINK_TERM_PROGRAMS.has(env.TERM_PROGRAM.toLowerCase());
|
|
41
|
+
}
|
|
42
|
+
return Boolean(env.VTE_VERSION);
|
|
43
|
+
}
|
|
44
|
+
// from https://github.com/vercel/detect-agent/blob/main/agents.json (Licensed under Apache 2.0)
|
|
45
|
+
function detectAiAgent(env, noTty) {
|
|
46
|
+
// cursor
|
|
47
|
+
if (env.CURSOR_TRACE_ID) {
|
|
48
|
+
return true;
|
|
49
|
+
}
|
|
50
|
+
// cursor-cli
|
|
51
|
+
if (env.CURSOR_AGENT || env.CURSOR_EXTENSION_HOST_ROLE === "agent-exec") {
|
|
52
|
+
return true;
|
|
53
|
+
}
|
|
54
|
+
// kimi
|
|
55
|
+
if (env.KIMI_PLUGIN_ROOT) {
|
|
56
|
+
return true;
|
|
57
|
+
}
|
|
58
|
+
// grok
|
|
59
|
+
if (env.GROK_PLUGIN_ROOT || env.GROK_PLUGIN_DATA) {
|
|
60
|
+
return true;
|
|
61
|
+
}
|
|
62
|
+
if (env.GEMINI_CLI) {
|
|
63
|
+
return true;
|
|
64
|
+
}
|
|
65
|
+
if (env.CLINE_ACTIVE) {
|
|
66
|
+
return true;
|
|
67
|
+
}
|
|
68
|
+
// codex
|
|
69
|
+
if (env.CODEX_SANDBOX ||
|
|
70
|
+
env.CODEX_CI ||
|
|
71
|
+
env.CODEX_THREAD_ID ||
|
|
72
|
+
env.CODEX_SANDBOX_NETWORK_DISABLED) {
|
|
73
|
+
return true;
|
|
74
|
+
}
|
|
75
|
+
if (env.ANTIGRAVITY_AGENT || env.ANTIGRAVITY_CLI_ALIAS) {
|
|
76
|
+
return true;
|
|
77
|
+
}
|
|
78
|
+
if (env.AUGMENT_AGENT) {
|
|
79
|
+
return true;
|
|
80
|
+
}
|
|
81
|
+
if (env.OPENCODE_CLIENT || env.OPENCODE) {
|
|
82
|
+
return true;
|
|
83
|
+
}
|
|
84
|
+
if (env.GOOSE_PROVIDER) {
|
|
85
|
+
return true;
|
|
86
|
+
}
|
|
87
|
+
if (env.JUNIE_DATA || env.JUNIE_SHIM_PATH) {
|
|
88
|
+
return true;
|
|
89
|
+
}
|
|
90
|
+
if (env.PATH?.search(/\.pi[\\/]agent/) !== -1) {
|
|
91
|
+
return true;
|
|
92
|
+
}
|
|
93
|
+
if (env.CLAUDE_CODE_IS_COWORK && (env.CLAUDECODE || env.CLAUDE_CODE)) {
|
|
94
|
+
return true;
|
|
95
|
+
}
|
|
96
|
+
if (env.CLAUDECODE || env.CLAUDE_CODE) {
|
|
97
|
+
return true;
|
|
98
|
+
}
|
|
99
|
+
if (env.REPL_ID) {
|
|
100
|
+
return true;
|
|
101
|
+
}
|
|
102
|
+
if (env.COPILOT_MODEL || env.COPILOT_ALLOW_ALL || env.COPILOT_GITHUB_TOKEN) {
|
|
103
|
+
return true;
|
|
104
|
+
}
|
|
105
|
+
if (env.TERM_PROGRAM === "kiro" && noTty) {
|
|
106
|
+
return true;
|
|
107
|
+
}
|
|
108
|
+
if (env.OPENCLAW_SHELL) {
|
|
109
|
+
return true;
|
|
110
|
+
}
|
|
111
|
+
// devin agent detection
|
|
112
|
+
if (existsSync("/opt/.devin")) {
|
|
113
|
+
return true;
|
|
114
|
+
}
|
|
115
|
+
return false;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* The Node adapter for `Terminal` (`@ac-kit/app-terminal`) — reads `stream`'s
|
|
119
|
+
* TTY properties and `process.env`.
|
|
120
|
+
*
|
|
121
|
+
* `columns`/`rows` are getters, not values captured at construction: they must
|
|
122
|
+
* reflect the terminal's current size after a `resize` event fires, not its
|
|
123
|
+
* size when `nodeTerminal` was called.
|
|
124
|
+
*/
|
|
125
|
+
export function nodeTerminal(stream) {
|
|
126
|
+
const env = process.env;
|
|
127
|
+
const noTty = !stream.isTTY;
|
|
128
|
+
const resize = new VoidEvent();
|
|
129
|
+
const aiAgent = detectAiAgent(env, noTty);
|
|
130
|
+
const interactive = !noTty && !aiAgent;
|
|
131
|
+
stream.on("resize", () => resize.emit());
|
|
132
|
+
return {
|
|
133
|
+
interactive,
|
|
134
|
+
get columns() {
|
|
135
|
+
return interactive ? stream.columns : 80;
|
|
136
|
+
},
|
|
137
|
+
get rows() {
|
|
138
|
+
return interactive ? stream.rows : 24;
|
|
139
|
+
},
|
|
140
|
+
colorDepth: interactive ? stream.getColorDepth() : 1,
|
|
141
|
+
unicode: !aiAgent && detectUnicodeSupport(env),
|
|
142
|
+
hyperlinks: !aiAgent && detectHyperlinkSupport(interactive, env),
|
|
143
|
+
resize,
|
|
144
|
+
// Spreading a plain method-only object here is safe; spreading `terminal`
|
|
145
|
+
// itself (built separately) would have flattened the getters above into
|
|
146
|
+
// frozen snapshot values instead.
|
|
147
|
+
...(interactive
|
|
148
|
+
? {
|
|
149
|
+
enterAltScreen: () => {
|
|
150
|
+
stream.write(ENTER_ALT_SCREEN);
|
|
151
|
+
},
|
|
152
|
+
exitAltScreen: () => {
|
|
153
|
+
stream.write(EXIT_ALT_SCREEN);
|
|
154
|
+
},
|
|
155
|
+
clear: () => {
|
|
156
|
+
stream.write(CLEAR_SCREEN);
|
|
157
|
+
},
|
|
158
|
+
}
|
|
159
|
+
: {}),
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
//# sourceMappingURL=node-terminal.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"node-terminal.js","sourceRoot":"","sources":["../../src/terminal/node-terminal.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAGrC,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAC1C,OAAO,EACN,YAAY,EAEZ,gBAAgB,EAChB,eAAe,GACf,MAAM,qBAAqB,CAAC;AAE7B;;;;;;GAMG;AACH,SAAS,oBAAoB,CAAC,GAAsB;IACnD,IAAI,OAAO,CAAC,QAAQ,KAAK,OAAO,EAAE,CAAC;QAClC,OAAO,GAAG,CAAC,IAAI,KAAK,OAAO,CAAC;IAC7B,CAAC;IAED,OAAO,OAAO,CACb,GAAG,CAAC,EAAE;QACN,GAAG,CAAC,UAAU;QACd,GAAG,CAAC,gBAAgB;QACpB,GAAG,CAAC,UAAU,KAAK,cAAc;QACjC,GAAG,CAAC,YAAY,KAAK,QAAQ;QAC7B,GAAG,CAAC,IAAI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AI,oBAAoB,CAAC,GAAG,CAAC;QAC9C,UAAU,EAAE,CAAC,OAAO,IAAI,sBAAsB,CAAC,WAAW,EAAE,GAAG,CAAC;QAChE,MAAM;QACN,0EAA0E;QAC1E,wEAAwE;QACxE,kCAAkC;QAClC,GAAG,CAAC,WAAW;YACd,CAAC,CAAC;gBACA,cAAc,EAAE,GAAG,EAAE;oBACpB,MAAM,CAAC,KAAK,CAAC,gBAAgB,CAAC,CAAC;gBAChC,CAAC;gBACD,aAAa,EAAE,GAAG,EAAE;oBACnB,MAAM,CAAC,KAAK,CAAC,eAAe,CAAC,CAAC;gBAC/B,CAAC;gBACD,KAAK,EAAE,GAAG,EAAE;oBACX,MAAM,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC;gBAC5B,CAAC;aACD;YACF,CAAC,CAAC,EAAE,CAAC;KACN,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Decodes byte chunks into strings using the given charset.
|
|
3
|
+
*
|
|
4
|
+
* Uses the platform {@link TextDecoder} where the charset is supported and
|
|
5
|
+
* iconv-lite for everything else. Split multi-byte sequences are carried across
|
|
6
|
+
* chunk boundaries.
|
|
7
|
+
*/
|
|
8
|
+
export declare class CharsetDecodeStream extends TransformStream<Uint8Array, string> {
|
|
9
|
+
#private;
|
|
10
|
+
constructor(charset?: string);
|
|
11
|
+
get charset(): string;
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=charset-decode-stream.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"charset-decode-stream.d.ts","sourceRoot":"","sources":["../../src/text/charset-decode-stream.ts"],"names":[],"mappings":"AAIA;;;;;;GAMG;AACH,qBAAa,mBAAoB,SAAQ,eAAe,CAAC,UAAU,EAAE,MAAM,CAAC;;IAG3E,YAAY,OAAO,SAAU,EAoC5B;IAED,IAAI,OAAO,IAAI,MAAM,CAEpB;CACD"}
|