@lukstei/dsh-log 0.0.0-stage → 0.2.2-rc.5.11

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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Lukas Steinbrecher
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,101 @@
1
- # Temporary Holding Version
1
+ # @lukstei/dsh-log
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ ## Summary
4
+
5
+ Routes Cordis logger output to stdout and/or log files, with per-logger severity thresholds for each destination. Use it to keep a persistent log of selected loggers.
6
+
7
+ ## Table of Contents
8
+
9
+ - [Use this package](#use-this-package)
10
+ - [Understand the implementation](#understand-the-implementation)
11
+ - [Further Exploration](#further-exploration)
12
+ - [Model Experience](#model-experience)
13
+ - [Known Limitations and Deferred Work](#known-limitations-and-deferred-work)
14
+ - [Dev Note](#dev-note)
15
+
16
+ -----
17
+
18
+ <a id="use-this-package"></a>
19
+ ## Use this package
20
+
21
+ The shipped [`cordis.patch.yml`](cordis.patch.yml) mounts one `stdout` output with `default: 2` (INFO). Mount with file output:
22
+
23
+ ```yaml
24
+ - insert:
25
+ - id: file-log
26
+ name: '@lukstei/dsh-log'
27
+ config:
28
+ outputs:
29
+ - target: stdout
30
+ levels: { default: 2, jev-audit: -1 }
31
+ - target: file
32
+ filePath: ~/.dsh/cache/approvals.log
33
+ levels: { default: -1, jev-audit: 2 }
34
+ ```
35
+
36
+ | Field | Default | Meaning |
37
+ |---|---|---|
38
+ | `outputs` | none | Array of destinations. Each registers its own Cordis exporter. |
39
+ | `outputs[].target` | required | `stdout` or `file`. |
40
+ | `outputs[].filePath` | required for `file` | Log file path. `~` or `~/...` expands to the home directory. |
41
+ | `outputs[].levels` | required | Map of logger name to threshold. `default` is the catch-all. |
42
+
43
+ Levels: `-1` silenced, `0` ERROR, `1` WARN, `2` INFO, `3` DEBUG. A message is written when its level is at most the threshold. `default: -1` plus named loggers gives an include-list.
44
+
45
+ Line format: `<ISO timestamp> [<LEVEL padded to 5>] [<logger>] <message>`.
46
+
47
+ If the host already prints logs to the console, a `stdout` output duplicates them.
48
+
49
+ ### Plugin dependencies
50
+
51
+ No plugin dependencies. The plugin has no `inject`; it registers `ctx.logger.exporter` on the Cordis context.
52
+
53
+ Non-plugin requirement: write access to any configured `outputs[].filePath` (the file target).
54
+
55
+ Used by: nothing mounts it as a dependency.
56
+
57
+ -----
58
+
59
+ <a id="understand-the-implementation"></a>
60
+ ## Understand the implementation
61
+
62
+ <details>
63
+ <summary>Implementation internals — click to expand</summary>
64
+
65
+ Single file: [`src/index.ts`](src/index.ts). Tests: [`src/index.test.js`](src/index.test.js). Exports `Config`, `formatMessage`, `expandHome`, `createFileWriter`, `apply`.
66
+
67
+ - `apply` loops over `outputs` and calls `ctx.logger.exporter({ colors: false, levels, export })` for each.
68
+ - File writes use `appendFileSync`. The parent directory is created recursively on the first write.
69
+ - Write errors are swallowed so a failing disk cannot trigger recursive logging.
70
+ - Config is a schemastery union on `target`; `filePath` and `levels` are required.
71
+
72
+ </details>
73
+
74
+ -----
75
+
76
+ <a id="further-exploration"></a>
77
+ ## Further Exploration
78
+
79
+ - Upstream: [DSH module graph](https://github.com/deepseek-ai/deepseek-harness/blob/master/docs/module-graph.md).
80
+
81
+ <a id="model-experience"></a>
82
+ ## Model Experience
83
+
84
+ No model-visible surface. This package adds no tools, prompt text, or context to the model.
85
+
86
+ <a id="known-limitations-and-deferred-work"></a>
87
+ ## Known Limitations and Deferred Work
88
+
89
+ - No rotation or size limit on log files.
90
+ - File write failures are silent.
91
+ - A configured `outputs` entry with an empty array writes nothing.
92
+
93
+ <a id="dev-note"></a>
94
+ ### Dev Note
95
+
96
+ <details>
97
+ <summary>Working context for maintainers — click to expand</summary>
98
+
99
+ None.
100
+
101
+ </details>
@@ -0,0 +1,7 @@
1
+ - insert:
2
+ - id: file-log
3
+ name: '@lukstei/dsh-log'
4
+ config:
5
+ outputs:
6
+ - target: stdout
7
+ levels: { default: 2 }
package/dist/index.js ADDED
@@ -0,0 +1,50 @@
1
+ import { appendFileSync, mkdirSync } from "node:fs";
2
+ import { homedir } from "node:os";
3
+ import path from "node:path";
4
+ import { format } from "node:util";
5
+ import Schema from "@deepseek-ai/schemastery";
6
+ // src/index.ts
7
+ const name = "file-log";
8
+ const levels = Schema.dict(Schema.number()).description("Log severity per logger name; `default` is the catch-all, -1 silences.");
9
+ const Config = Schema.object({ outputs: Schema.array(Schema.union([Schema.object({
10
+ target: Schema.const("stdout").required(),
11
+ levels: levels.required()
12
+ }), Schema.object({
13
+ target: Schema.const("file").required(),
14
+ filePath: Schema.string().required().description("Log file path; a leading `~` expands to home."),
15
+ levels: levels.required()
16
+ })])).description("Destinations; each receives the loggers its levels admit.") });
17
+ function formatMessage(message) {
18
+ const ts = new Date(message.ts).toISOString();
19
+ const type = String(message.type).toUpperCase().padEnd(5);
20
+ const text = format(...message.args);
21
+ return `${ts} [${type}] [${message.name}] ${text}\n`;
22
+ }
23
+ function expandHome(filePath) {
24
+ return filePath === "~" || filePath.startsWith("~/") ? path.join(homedir(), filePath.slice(1)) : filePath;
25
+ }
26
+ function createFileWriter(rawPath) {
27
+ const filePath = expandHome(rawPath);
28
+ let dirEnsured = false;
29
+ return (content) => {
30
+ try {
31
+ if (!dirEnsured) {
32
+ mkdirSync(path.dirname(filePath), { recursive: true });
33
+ dirEnsured = true;
34
+ }
35
+ appendFileSync(filePath, content, "utf8");
36
+ } catch {}
37
+ };
38
+ }
39
+ function apply(ctx, config) {
40
+ for (const output of config.outputs) {
41
+ const write = output.target === "stdout" ? (line) => process.stdout.write(line) : createFileWriter(output.filePath);
42
+ const exporter = {
43
+ colors: false,
44
+ levels: output.levels,
45
+ export: (message) => write(formatMessage(message))
46
+ };
47
+ ctx.logger.exporter(exporter);
48
+ }
49
+ }
50
+ export { Config, apply, createFileWriter, expandHome, formatMessage, name };
package/package.json CHANGED
@@ -1,6 +1,59 @@
1
1
  {
2
2
  "name": "@lukstei/dsh-log",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.2.2-rc.5.11",
4
+ "description": "File logging exporter for DSH",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "exports": {
8
+ ".": {
9
+ "types": "./src/index.ts",
10
+ "default": "./dist/index.js"
11
+ }
12
+ },
13
+ "dsh": {
14
+ "bundle": {
15
+ "patch": "./cordis.patch.yml"
16
+ }
17
+ },
18
+ "peerDependencies": {
19
+ "@deepseek-ai/cordis": "*",
20
+ "@deepseek-ai/schemastery": "*"
21
+ },
22
+ "devDependencies": {
23
+ "@deepseek-ai/cordis": "4.1.0",
24
+ "@deepseek-ai/schemastery": "3.19.0",
25
+ "@types/node": "^26.0.0",
26
+ "typescript": "^7.0.2"
27
+ },
28
+ "files": [
29
+ "src",
30
+ "dist",
31
+ "README.md",
32
+ "cordis.patch.yml",
33
+ "!src/**/*.spec.*",
34
+ "!src/**/*.test.*",
35
+ "!src/**/*.stories.*",
36
+ "!src/**/stories",
37
+ "!src/**/*.e2e.*",
38
+ "!src/**/__snapshots__",
39
+ "!src/**/fixtures"
40
+ ],
41
+ "types": "./src/index.ts",
42
+ "license": "MIT",
43
+ "repository": {
44
+ "type": "git",
45
+ "url": "git+https://github.com/lukstei/dsh-plugins.git",
46
+ "directory": "packages/dsh-log"
47
+ },
48
+ "publishConfig": {
49
+ "access": "public"
50
+ },
51
+ "scripts": {
52
+ "build": "tsdown --config tsdown.config.ts --logLevel error",
53
+ "dev": "tsdown --config tsdown.config.ts --watch",
54
+ "check": "biome check --reporter=concise .",
55
+ "typecheck": "tsc --noEmit",
56
+ "test": "node --test --test-reporter=dot",
57
+ "verify": "pnpm --silent run check && pnpm --silent run build && pnpm --silent run typecheck && pnpm --silent run test"
58
+ }
6
59
  }
package/src/index.ts ADDED
@@ -0,0 +1,86 @@
1
+ import { appendFileSync, mkdirSync } from "node:fs";
2
+ import { homedir } from "node:os";
3
+ import path from "node:path";
4
+ import { format } from "node:util";
5
+ import type { Context, Exporter, Message } from "@deepseek-ai/cordis";
6
+ import Schema from "@deepseek-ai/schemastery";
7
+
8
+ export const name = "file-log";
9
+
10
+ export type LogMessage = Message;
11
+
12
+ export type Output = {
13
+ /** Cordis per-logger minimum severity; -1 silences a logger. */
14
+ levels: Record<string, number>;
15
+ } & ({ target: "stdout" } | { target: "file"; filePath: string });
16
+
17
+ export interface Config {
18
+ outputs: Output[];
19
+ }
20
+
21
+ const levels = Schema.dict(Schema.number()).description(
22
+ "Log severity per logger name; `default` is the catch-all, -1 silences.",
23
+ );
24
+
25
+ export const Config: Schema<Config> = Schema.object({
26
+ outputs: Schema.array(
27
+ Schema.union([
28
+ Schema.object({
29
+ target: Schema.const("stdout").required(),
30
+ levels: levels.required(),
31
+ }),
32
+ Schema.object({
33
+ target: Schema.const("file").required(),
34
+ filePath: Schema.string()
35
+ .required()
36
+ .description("Log file path; a leading `~` expands to home."),
37
+ levels: levels.required(),
38
+ }),
39
+ ]),
40
+ ).description("Destinations; each receives the loggers its levels admit."),
41
+ });
42
+
43
+ export function formatMessage(message: LogMessage): string {
44
+ const ts = new Date(message.ts).toISOString();
45
+ const type = String(message.type).toUpperCase().padEnd(5);
46
+ const text = format(...message.args);
47
+ return `${ts} [${type}] [${message.name}] ${text}\n`;
48
+ }
49
+
50
+ export function expandHome(filePath: string): string {
51
+ return filePath === "~" || filePath.startsWith("~/")
52
+ ? path.join(homedir(), filePath.slice(1))
53
+ : filePath;
54
+ }
55
+
56
+ export function createFileWriter(rawPath: string): (content: string) => void {
57
+ const filePath = expandHome(rawPath);
58
+ let dirEnsured = false;
59
+
60
+ return (content: string) => {
61
+ try {
62
+ if (!dirEnsured) {
63
+ mkdirSync(path.dirname(filePath), { recursive: true });
64
+ dirEnsured = true;
65
+ }
66
+ appendFileSync(filePath, content, "utf8");
67
+ } catch {
68
+ // edge case: disk write failures must not throw or cause recursive logger crashes
69
+ }
70
+ };
71
+ }
72
+
73
+ export function apply(ctx: Context, config: Config): void {
74
+ for (const output of config.outputs) {
75
+ const write =
76
+ output.target === "stdout"
77
+ ? (line: string) => process.stdout.write(line)
78
+ : createFileWriter(output.filePath);
79
+ const exporter: Exporter = {
80
+ colors: false,
81
+ levels: output.levels,
82
+ export: (message) => write(formatMessage(message)),
83
+ };
84
+ ctx.logger.exporter(exporter);
85
+ }
86
+ }