agent-tail-core 0.3.1 → 0.3.3

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/dist/cli.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { n as cmd_run, r as cmd_wrap, t as cmd_init } from "./commands-LpvDep8T.mjs";
2
+ import { n as cmd_run, r as cmd_wrap, t as cmd_init } from "./commands-B32lAAvI.mjs";
3
3
  import { parseArgs } from "node:util";
4
4
 
5
5
  //#region src/cli.ts
@@ -16,6 +16,7 @@ const HELP = `
16
16
  --max-sessions <n> Max sessions to keep (default: 10)
17
17
  --no-combined Don't write to combined.log
18
18
  --exclude <pattern> Exclude lines matching pattern (repeatable, /regex or substring)
19
+ --mute <name> Mute a service from terminal and combined.log (repeatable, still logs to <name>.log)
19
20
  -h, --help Show this help
20
21
 
21
22
  \x1b[1mExamples:\x1b[0m
@@ -47,6 +48,10 @@ function parse_cli_options(args) {
47
48
  type: "string",
48
49
  multiple: true
49
50
  },
51
+ mute: {
52
+ type: "string",
53
+ multiple: true
54
+ },
50
55
  help: {
51
56
  type: "boolean",
52
57
  short: "h",
@@ -65,7 +70,8 @@ function parse_cli_options(args) {
65
70
  log_dir: values["log-dir"] ?? "tmp/logs",
66
71
  max_sessions: parseInt(values["max-sessions"] ?? "10", 10),
67
72
  combined: !values["no-combined"],
68
- excludes: values.exclude ?? []
73
+ excludes: values.exclude ?? [],
74
+ mutes: values.mute ?? []
69
75
  },
70
76
  positionals,
71
77
  rest
@@ -17,6 +17,7 @@ function should_exclude(message, excludes) {
17
17
  //#endregion
18
18
  //#region src/log-manager.ts
19
19
  const PLUGIN_PREFIX = "\x1B[36m[agent-tail]\x1B[0m";
20
+ const SESSION_ENV_VAR = "AGENT_TAIL_SESSION";
20
21
  let session_counter = 0;
21
22
  var LogManager = class {
22
23
  constructor(options) {
@@ -70,6 +71,17 @@ var LogManager = class {
70
71
  } catch {}
71
72
  }
72
73
  /**
74
+ * Join an existing session directory. Creates the log file if it doesn't
75
+ * exist. Use this when a parent process (e.g. `agent-tail run`) has
76
+ * already created the session and passed its path via AGENT_TAIL_SESSION.
77
+ */
78
+ join_session(session_dir) {
79
+ const log_file = path.join(session_dir, this.options.logFileName);
80
+ if (!fs.existsSync(log_file)) fs.writeFileSync(log_file, "");
81
+ console.log(`${PLUGIN_PREFIX} Writing to ${log_file}`);
82
+ return log_file;
83
+ }
84
+ /**
73
85
  * Resolve the current session directory. If a `latest` symlink exists and
74
86
  * points to a valid directory, return it. Otherwise create a new session.
75
87
  */
@@ -144,7 +156,8 @@ const DEFAULT_CLI_OPTIONS = {
144
156
  log_dir: "tmp/logs",
145
157
  max_sessions: 10,
146
158
  combined: true,
147
- excludes: []
159
+ excludes: [],
160
+ mutes: []
148
161
  };
149
162
  function create_manager(options) {
150
163
  return new LogManager(resolve_options({
@@ -270,13 +283,17 @@ function cmd_run(project_root, service_args, options = DEFAULT_CLI_OPTIONS) {
270
283
  const tag = `${COLORS[i % COLORS.length]}[${svc.name}]${RESET}`;
271
284
  const log_file = path.join(session_dir, `${svc.name}.log`);
272
285
  const log_stream = fs.createWriteStream(log_file, { flags: "a" });
286
+ const is_muted = options.mutes.includes(svc.name);
273
287
  const child = spawn(svc.command, {
274
288
  stdio: [
275
289
  "inherit",
276
290
  "pipe",
277
291
  "pipe"
278
292
  ],
279
- env: { ...process.env },
293
+ env: {
294
+ ...process.env,
295
+ [SESSION_ENV_VAR]: session_dir
296
+ },
280
297
  shell: true
281
298
  });
282
299
  function handle(target, chunk) {
@@ -284,12 +301,16 @@ function cmd_run(project_root, service_args, options = DEFAULT_CLI_OPTIONS) {
284
301
  for (let j = 0; j < lines.length; j++) if (lines[j].length > 0) {
285
302
  if (options.excludes.length && should_exclude(lines[j], options.excludes)) continue;
286
303
  log_stream.write(lines[j] + "\n");
287
- target.write(`${tag} ${lines[j]}\n`);
288
- combined_stream?.write(`[${svc.name}] ${lines[j]}\n`);
304
+ if (!is_muted) {
305
+ target.write(`${tag} ${lines[j]}\n`);
306
+ combined_stream?.write(`[${svc.name}] ${lines[j]}\n`);
307
+ }
289
308
  } else if (j < lines.length - 1) {
290
309
  log_stream.write("\n");
291
- target.write("\n");
292
- combined_stream?.write("\n");
310
+ if (!is_muted) {
311
+ target.write("\n");
312
+ combined_stream?.write("\n");
313
+ }
293
314
  }
294
315
  }
295
316
  child.stdout?.on("data", (chunk) => handle(process.stdout, chunk));
@@ -317,4 +338,4 @@ function cmd_run(project_root, service_args, options = DEFAULT_CLI_OPTIONS) {
317
338
  }
318
339
 
319
340
  //#endregion
320
- export { resolve_session_dir as a, LogManager as c, parse_service_configs as i, should_exclude as l, cmd_run as n, DEFAULT_OPTIONS as o, cmd_wrap as r, resolve_options as s, cmd_init as t };
341
+ export { resolve_session_dir as a, LogManager as c, parse_service_configs as i, SESSION_ENV_VAR as l, cmd_run as n, DEFAULT_OPTIONS as o, cmd_wrap as r, resolve_options as s, cmd_init as t, should_exclude as u };
package/dist/index.d.mts CHANGED
@@ -46,6 +46,7 @@ declare function should_exclude(message: string, excludes: string[]): boolean;
46
46
  declare function generate_client_script(options: ResolvedOptions): string;
47
47
  //#endregion
48
48
  //#region src/log-manager.d.ts
49
+ declare const SESSION_ENV_VAR = "AGENT_TAIL_SESSION";
49
50
  declare class LogManager {
50
51
  private options;
51
52
  constructor(options: ResolvedOptions);
@@ -53,6 +54,12 @@ declare class LogManager {
53
54
  create_session_name(): string;
54
55
  update_latest_symlink(log_dir: string, session_dir: string): void;
55
56
  prune_sessions(log_dir: string): void;
57
+ /**
58
+ * Join an existing session directory. Creates the log file if it doesn't
59
+ * exist. Use this when a parent process (e.g. `agent-tail run`) has
60
+ * already created the session and passed its path via AGENT_TAIL_SESSION.
61
+ */
62
+ join_session(session_dir: string): string;
56
63
  /**
57
64
  * Resolve the current session directory. If a `latest` symlink exists and
58
65
  * points to a valid directory, return it. Otherwise create a new session.
@@ -67,6 +74,7 @@ interface CliOptions {
67
74
  max_sessions: number;
68
75
  combined: boolean;
69
76
  excludes: string[];
77
+ mutes: string[];
70
78
  }
71
79
  /**
72
80
  * Create a new log session. Returns the session directory path.
@@ -92,4 +100,4 @@ declare function cmd_wrap(project_root: string, name: string, command: string[],
92
100
  */
93
101
  declare function cmd_run(project_root: string, service_args: string[], options?: CliOptions): Promise<void>;
94
102
  //#endregion
95
- export { type BrowserLogsOptions, type CliOptions, DEFAULT_OPTIONS, type LogEntry, LogManager, type ResolvedOptions, type ServiceConfig, cmd_init, cmd_run, cmd_wrap, format_log_line, generate_client_script, parse_service_configs, resolve_options, resolve_session_dir, should_exclude };
103
+ export { type BrowserLogsOptions, type CliOptions, DEFAULT_OPTIONS, type LogEntry, LogManager, type ResolvedOptions, SESSION_ENV_VAR, type ServiceConfig, cmd_init, cmd_run, cmd_wrap, format_log_line, generate_client_script, parse_service_configs, resolve_options, resolve_session_dir, should_exclude };
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { a as resolve_session_dir, c as LogManager, i as parse_service_configs, l as should_exclude, n as cmd_run, o as DEFAULT_OPTIONS, r as cmd_wrap, s as resolve_options, t as cmd_init } from "./commands-LpvDep8T.mjs";
1
+ import { a as resolve_session_dir, c as LogManager, i as parse_service_configs, l as SESSION_ENV_VAR, n as cmd_run, o as DEFAULT_OPTIONS, r as cmd_wrap, s as resolve_options, t as cmd_init, u as should_exclude } from "./commands-B32lAAvI.mjs";
2
2
 
3
3
  //#region src/formatter.ts
4
4
  function format_log_line(entry) {
@@ -121,4 +121,4 @@ function generate_client_script(options) {
121
121
  }
122
122
 
123
123
  //#endregion
124
- export { DEFAULT_OPTIONS, LogManager, cmd_init, cmd_run, cmd_wrap, format_log_line, generate_client_script, parse_service_configs, resolve_options, resolve_session_dir, should_exclude };
124
+ export { DEFAULT_OPTIONS, LogManager, SESSION_ENV_VAR, cmd_init, cmd_run, cmd_wrap, format_log_line, generate_client_script, parse_service_configs, resolve_options, resolve_session_dir, should_exclude };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "agent-tail-core",
3
3
  "type": "module",
4
- "version": "0.3.1",
4
+ "version": "0.3.3",
5
5
  "description": "Core utilities for agent-tail log capture plugins.",
6
6
  "license": "MIT",
7
7
  "repository": {