saving-token 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 ADDED
@@ -0,0 +1,63 @@
1
+ # saving-token
2
+
3
+ A native writer makes file changes; the parent agent decides and reviews. You choose the writer model during setup. The parent model and global defaults stay unchanged.
4
+
5
+ Inspired by [karpathy-guidelines](https://github.com/multica-ai/andrej-karpathy-skills). Delegation aims to reduce parent-context output; extra context and retries can increase total tokens.
6
+
7
+ ## Install
8
+
9
+ ### Codex via npm (after publication)
10
+
11
+ After the package is published to npm, run:
12
+
13
+ ```bash
14
+ npx saving-token@latest install --agent codex
15
+ ```
16
+
17
+ This interactively prompts you to choose a writer model and optional reasoning effort, then asks you to confirm installation.
18
+
19
+ ### Manual / multi-platform
20
+
21
+ ```bash
22
+ bash skills/saving-token/scripts/setup.sh
23
+ ```
24
+
25
+ Choose **platform → model → optional reasoning effort → confirm**. The model menu offers a few suggestions and a custom ID option, with no default selection. Suggestions do not verify account availability. Leave effort blank to use the host's default behavior.
26
+
27
+ | Platform | Skill location | Writer configuration |
28
+ |---|---|---|
29
+ | Codex | `${CODEX_HOME:-~/.codex}/skills/saving-token/` | `${CODEX_HOME:-~/.codex}/agents/saving-token-writer.toml` |
30
+ | Claude Code | `~/.claude/skills/saving-token/` | `~/.claude/agents/saving-token-writer.md` |
31
+ | Cursor | `~/.cursor/skills/saving-token/` | `~/.cursor/agents/saving-token-writer.md` |
32
+
33
+ Restart the host, then invoke `$saving-token` in Codex or `/saving-token` in standalone Claude Code and Cursor. Automatic Skill discovery remains available. Verify the writer model in runtime task metadata when exposed; generated configuration alone does not prove routing. Claude Code and Cursor may substitute a model under account or administrator policy.
34
+
35
+ To automate an already approved installation:
36
+
37
+ ```bash
38
+ bash skills/saving-token/scripts/setup.sh --target codex --model '<model-id>' --yes
39
+ ```
40
+
41
+ `--target` and `--model` are required without a terminal. Add `--reasoning-effort <effort>` only if supported by the selected model. Explicit `--model` skips the menu; `--yes` approves installation and displayed replacements, without choosing a model.
42
+
43
+ Rerun setup to change the writer model. Existing distributed Skill files and the writer configuration are replaced after confirmation; extra files in the Skill directory are preserved. Setup also works from the installed Skill's `scripts/setup.sh`.
44
+
45
+ ## Claude Code plugin
46
+
47
+ ```text
48
+ /plugin marketplace add JerryWu1234/saving-token
49
+ /plugin install saving-token@saving-token
50
+ ```
51
+
52
+ Claude's plugin configuration collects the required `writer_model` as text; it does not use the script's menu. The plugin leaves reasoning effort to the host. Invoke `/saving-token:saving-token`; its writer is `saving-token:saving-token-writer`. Change the model through plugin configuration, then reload the session. Use either the plugin or standalone installation.
53
+
54
+ ## Structure
55
+
56
+ - [`skills/saving-token/SKILL.md`](skills/saving-token/SKILL.md): canonical delegation and review rules.
57
+ - `skills/saving-token/scripts/setup.sh` and `assets/`: standalone installer and native agent templates.
58
+ - `agents/` and `.claude-plugin/`: Claude plugin writer and marketplace metadata.
59
+ - `AGENTS.md`, `CLAUDE.md`, [`CURSOR.md`](CURSOR.md), and `.cursor/rules/`: repository adapters that point to the Skill.
60
+
61
+ Other hosts can read the Skill or `AGENTS.md`, but delegation requires writable native subagents and independent model configuration. Without those capabilities, support is instruction-only.
62
+
63
+ Official references: [Codex subagents](https://developers.openai.com/codex/subagents), [Claude subagents](https://code.claude.com/docs/en/sub-agents), [Claude plugins](https://code.claude.com/docs/en/plugins-reference), [Cursor subagents](https://cursor.com/docs/subagents), [Agent Skills](https://agentskills.io/specification).
@@ -0,0 +1,36 @@
1
+ #!/usr/bin/env node
2
+ 'use strict';
3
+
4
+ const path = require('node:path');
5
+ const { spawnSync } = require('node:child_process');
6
+
7
+ const args = process.argv.slice(2);
8
+
9
+ if (
10
+ args.length !== 3 ||
11
+ args[0] !== 'install' ||
12
+ args[1] !== '--agent' ||
13
+ args[2] !== 'codex'
14
+ ) {
15
+ console.error('Usage: saving-token install --agent codex');
16
+ process.exit(1);
17
+ }
18
+
19
+ const setupPath = path.join(
20
+ __dirname,
21
+ '..',
22
+ 'skills',
23
+ 'saving-token',
24
+ 'scripts',
25
+ 'setup.sh'
26
+ );
27
+ const result = spawnSync('bash', [setupPath, '--target', 'codex'], {
28
+ stdio: 'inherit'
29
+ });
30
+
31
+ if (result.error) {
32
+ console.error(`Failed to start bash: ${result.error.message}`);
33
+ process.exit(1);
34
+ }
35
+
36
+ process.exit(result.status === null ? 1 : result.status);
package/package.json ADDED
@@ -0,0 +1,14 @@
1
+ {
2
+ "name": "saving-token",
3
+ "version": "0.1.0",
4
+ "bin": {
5
+ "saving-token": "bin/saving-token.cjs"
6
+ },
7
+ "files": [
8
+ "bin/saving-token.cjs",
9
+ "skills/saving-token"
10
+ ],
11
+ "engines": {
12
+ "node": ">=18"
13
+ }
14
+ }
@@ -0,0 +1,41 @@
1
+ ---
2
+ name: saving-token
3
+ description: Delegate file changes to a user-configured writer subagent while the parent agent directs and reviews. Use for code, script, and document edits or generation.
4
+ ---
5
+
6
+ # Saving Token
7
+
8
+ The parent directs and reviews; a native writer implements and verifies.
9
+ If your identity is `saving-token-writer` or `saving-token:saving-token-writer`, implement directly and never delegate again. The remaining rules are parent-only.
10
+
11
+ ## Configure
12
+
13
+ - Use `saving-token-writer` on Codex, standalone Claude Code, or Cursor; use `saving-token:saving-token-writer` for the Claude plugin.
14
+ - When setup is requested or the writer is missing, collect the platform and the user's model choice. Reasoning effort is optional and must be supported by that model.
15
+ - With installation approval, run the bundled `scripts/setup.sh`. It offers platform/model selection and previews replacements before confirmation. For automation, pass `--target <codex|claude|cursor> --model <id>`, optionally `--reasoning-effort <effort>`, and `--yes` only after approval. Do not generate substitute setup code.
16
+ - The Claude plugin collects `writer_model` through plugin configuration and leaves effort to the host. Do not install a duplicate standalone writer.
17
+ - Running the approved setup script is the only parent-side write exception. Preserve the parent model and global subagent defaults.
18
+ - If a writable native writer or independent model configuration is unavailable, report instruction-only compatibility and ask before implementing directly.
19
+ - Configuration is not runtime proof. Check exposed model metadata and disclose mismatches; never silently substitute a model yourself. Claude Code and Cursor may apply host-level fallback.
20
+
21
+ ## Delegate
22
+
23
+ - Delegate every file write, including edits, deletions, documents, temporary scripts, and formatting.
24
+ - Give goals and acceptance criteria, not implementation text to paste. Prefer file paths and issue locations over copied source or conversation history.
25
+ - Batch related changes into one scoped task and reuse the writer for revisions.
26
+ - The writer follows project rules and authorization boundaries, preserves user edits, implements directly, and runs relevant checks.
27
+
28
+ ```text
29
+ Goal: <expected behavior>
30
+ Scope: <paths; prohibited changes>
31
+ Verify: <acceptance criteria and checks>
32
+ Return: changed paths; check results; blockers.
33
+ ```
34
+
35
+ ## Accept
36
+
37
+ - Inspect the actual diff, new files, and check evidence; never accept from the writer summary alone.
38
+ - Send remaining defects and acceptance conditions to the same writer, then review again. Stop and report blockers or repeated failures without progress.
39
+ - Report the outcome, verification, and material routing uncertainty concisely. Keep full logs in files when needed.
40
+
41
+ Delegation aims to reduce parent-context output; a second context and retries can increase total token usage.
@@ -0,0 +1,15 @@
1
+ ---
2
+ name: saving-token-writer
3
+ description: Implement file changes delegated by the saving-token Skill and run verification.
4
+ model: "__WRITER_MODEL__"
5
+ effort: "__REASONING_EFFORT__"
6
+ disallowedTools:
7
+ - Agent
8
+ ---
9
+
10
+ # Saving Token Writer
11
+
12
+ Implement directly. Never delegate or invoke another subagent.
13
+ Follow project rules and authorization boundaries, and preserve existing user edits.
14
+ Make only the requested changes and run the requested checks.
15
+ Return changed paths, check commands and results, and blockers only.
@@ -0,0 +1,11 @@
1
+ name = "saving-token-writer"
2
+ description = "Implement file changes delegated by the saving-token Skill and run verification."
3
+ model = "__WRITER_MODEL__"
4
+ model_reasoning_effort = "__REASONING_EFFORT__"
5
+
6
+ developer_instructions = """
7
+ Implement directly. Do not delegate further.
8
+ Follow project rules and preserve existing user edits.
9
+ Run the requested checks.
10
+ Return changed paths, check results, and blockers only.
11
+ """
@@ -0,0 +1,14 @@
1
+ ---
2
+ name: saving-token-writer
3
+ description: Implement file changes delegated by the saving-token Skill and run verification.
4
+ model: "__WRITER_MODEL__"
5
+ readonly: false
6
+ is_background: false
7
+ ---
8
+
9
+ # Saving Token Writer
10
+
11
+ Implement directly. Never delegate or invoke another subagent.
12
+ Follow project rules and authorization boundaries, and preserve existing user edits.
13
+ Make only the requested changes and run the requested checks.
14
+ Return changed paths, check commands and results, and blockers only.
@@ -0,0 +1,184 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+
4
+ fail() { printf 'Error: %s\n' "$*" >&2; exit 1; }
5
+
6
+ usage() {
7
+ cat <<'HELP'
8
+ Usage: setup.sh [--target codex|claude|cursor] [--model ID]
9
+ [--reasoning-effort EFFORT] [--yes]
10
+
11
+ Choose a platform and writer model, preview, then confirm installation.
12
+ --target PLATFORM Prompted when omitted; required without a terminal.
13
+ --model ID Skip the model menu; required without a terminal.
14
+ --reasoning-effort EFFORT Optional. Omit to use the host's default behavior.
15
+ --yes Approve installation and displayed replacements.
16
+ -h, --help Show this help.
17
+
18
+ Model suggestions are not an account availability check. Use only models and
19
+ reasoning efforts supported by your host and account. --yes never picks a model.
20
+ HELP
21
+ }
22
+
23
+ SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd -P)"
24
+ SKILL_SOURCE="$(cd -- "$SCRIPT_DIR/.." && pwd -P)"
25
+ target=''
26
+ writer_model=''
27
+ reasoning_effort=''
28
+ model_was_set=false
29
+ effort_was_set=false
30
+ assume_yes=false
31
+
32
+ while [[ $# -gt 0 ]]; do
33
+ case "$1" in
34
+ --target|--model|--reasoning-effort)
35
+ [[ $# -ge 2 && -n "$2" && "$2" != -* ]] || fail "$1 requires a value."
36
+ case "$1" in
37
+ --target) target=$2 ;;
38
+ --model) writer_model=$2; model_was_set=true ;;
39
+ --reasoning-effort) reasoning_effort=$2; effort_was_set=true ;;
40
+ esac
41
+ shift 2 ;;
42
+ --yes) assume_yes=true; shift ;;
43
+ -h|--help) usage; exit 0 ;;
44
+ *) fail "Unknown option: $1" ;;
45
+ esac
46
+ done
47
+
48
+ [[ -n "${HOME:-}" ]] || fail 'HOME is not set.'
49
+ if [[ -z "$target" ]]; then
50
+ [[ -t 0 ]] || fail 'Pass --target in non-interactive use.'
51
+ IFS= read -r -p 'Platform: 1) codex 2) claude 3) cursor: ' target || fail 'No platform selected.'
52
+ case "$target" in 1) target=codex ;; 2) target=claude ;; 3) target=cursor ;; esac
53
+ fi
54
+
55
+ case "$target" in
56
+ codex)
57
+ codex_home="${CODEX_HOME:-$HOME/.codex}"
58
+ skill_target="$codex_home/skills/saving-token"
59
+ agent_dir="$codex_home/agents"
60
+ agent_file='saving-token-writer.toml'
61
+ models=(gpt-5.6-luna gpt-5.6-terra gpt-5.3-codex-spark)
62
+ ;;
63
+ claude)
64
+ skill_target="$HOME/.claude/skills/saving-token"
65
+ agent_dir="$HOME/.claude/agents"
66
+ agent_file='saving-token-writer.md'
67
+ models=(haiku sonnet opus)
68
+ ;;
69
+ cursor)
70
+ skill_target="$HOME/.cursor/skills/saving-token"
71
+ agent_dir="$HOME/.cursor/agents"
72
+ agent_file='saving-token-writer.md'
73
+ models=(composer-2.5 gpt-5.6-sol)
74
+ ;;
75
+ *) fail "Unsupported target '$target'. Expected codex, claude, or cursor." ;;
76
+ esac
77
+
78
+ if [[ "$model_was_set" != true ]]; then
79
+ [[ -t 0 ]] || fail 'Pass --model in non-interactive use.'
80
+ printf '\nWriter model suggestions (availability depends on your account):\n'
81
+ for i in "${!models[@]}"; do printf ' %s) %s\n' "$((i + 1))" "${models[$i]}"; done
82
+ printf ' c) Custom model ID\n q) Cancel\n'
83
+ IFS= read -r -p 'Choose a model: ' choice || fail 'No model selected.'
84
+ case "$choice" in
85
+ q|Q) printf 'Installation cancelled; no files were changed.\n'; exit 0 ;;
86
+ c|C) IFS= read -r -p 'Writer model ID: ' writer_model || fail 'No model selected.' ;;
87
+ [1-3])
88
+ [[ "$choice" -le "${#models[@]}" ]] || fail 'Invalid model selection.'
89
+ writer_model=${models[$((choice - 1))]} ;;
90
+ *) fail 'Choose a listed number, c, or q; no model is selected by default.' ;;
91
+ esac
92
+ fi
93
+ [[ "$writer_model" =~ ^[a-zA-Z0-9][a-zA-Z0-9._:/-]*$ ]] || fail 'Model ID must be nonempty, without whitespace or parameters; use letters, digits, ., _, :, /, or -.'
94
+
95
+ case "$writer_model" in
96
+ inherit|auto) fail 'Choose a specific writer model instead of inherit or auto.' ;;
97
+ esac
98
+
99
+ if [[ "$effort_was_set" != true && "$assume_yes" != true && -t 0 ]]; then
100
+ IFS= read -r -p 'Reasoning effort (Enter to omit): ' reasoning_effort || fail 'Input cancelled.'
101
+ fi
102
+ case "$reasoning_effort" in
103
+ ''|none|minimal|low|medium|high|xhigh|max|ultra) ;;
104
+ *) fail 'Unknown reasoning effort; use none, minimal, low, medium, high, xhigh, max, or ultra if your model supports it.' ;;
105
+ esac
106
+ if [[ "$target" == claude ]]; then
107
+ case "$reasoning_effort" in
108
+ ''|low|medium|high|xhigh|max) ;;
109
+ *) fail 'Claude effort must be low, medium, high, xhigh, or max if supported by your model.' ;;
110
+ esac
111
+ fi
112
+
113
+ template_path="$SKILL_SOURCE/assets/$target/$agent_file.template"
114
+ agent_target="$agent_dir/$agent_file"
115
+ distributed_files=(SKILL.md scripts/setup.sh assets/codex/saving-token-writer.toml.template assets/claude/saving-token-writer.md.template assets/cursor/saving-token-writer.md.template)
116
+ for file in "${distributed_files[@]}"; do
117
+ [[ -f "$SKILL_SOURCE/$file" ]] || fail "Missing required Skill file: $SKILL_SOURCE/$file"
118
+ done
119
+ skill_source_is_target=false
120
+ if [[ -d "$skill_target" && "$(cd -- "$skill_target" && pwd -P)" == "$SKILL_SOURCE" ]]; then
121
+ skill_source_is_target=true
122
+ fi
123
+
124
+ printf '\nPlatform: %s\nWriter model: %s\nReasoning effort: %s\n' "$target" "$writer_model" "${reasoning_effort:-omitted (host default)}"
125
+ printf 'Skill target: %s\nAgent target: %s\n' "$skill_target" "$agent_target"
126
+ printf 'The parent model and global defaults remain unchanged. Model availability and runtime routing are not verified.\n'
127
+ if [[ "$target" != codex ]]; then
128
+ printf 'The host may substitute a model because of account or administrator policy.\n'
129
+ fi
130
+ if [[ "$skill_source_is_target" == true ]]; then
131
+ printf 'Running from the installed Skill; only the writer configuration will change.\n'
132
+ elif [[ -e "$skill_target" ]]; then
133
+ printf 'Existing distributed Skill files will be replaced; extra files will be preserved.\n'
134
+ fi
135
+ [[ ! -e "$agent_target" ]] || printf 'Existing writer configuration will be replaced.\n'
136
+
137
+ if [[ "$assume_yes" != true ]]; then
138
+ IFS= read -r -p 'Install this configuration? [y/N] ' answer || fail 'Confirmation required; use --yes after approval.'
139
+ case "$answer" in
140
+ y|Y|yes|YES|Yes) ;;
141
+ *) printf 'Installation cancelled; no files were changed.\n'; exit 0 ;;
142
+ esac
143
+ else
144
+ printf 'Install this configuration? yes (--yes)\n'
145
+ fi
146
+
147
+ render_agent_config() {
148
+ local line model=$writer_model model_count=0 effort_count=0
149
+ if [[ "$target" == cursor && -n "$reasoning_effort" ]]; then
150
+ model+="[effort=$reasoning_effort]"
151
+ fi
152
+ while IFS= read -r line || [[ -n "$line" ]]; do
153
+ if [[ "$line" == *'__WRITER_MODEL__'* ]]; then
154
+ model_count=$((model_count + 1))
155
+ line=${line//__WRITER_MODEL__/$model}
156
+ fi
157
+ if [[ "$line" == *'__REASONING_EFFORT__'* ]]; then
158
+ effort_count=$((effort_count + 1))
159
+ [[ -n "$reasoning_effort" ]] || continue
160
+ line=${line//__REASONING_EFFORT__/$reasoning_effort}
161
+ fi
162
+ printf '%s\n' "$line"
163
+ done < "$template_path"
164
+ [[ $model_count -eq 1 ]] || fail 'Agent template must contain exactly one model placeholder.'
165
+ if [[ "$target" != cursor ]]; then
166
+ [[ $effort_count -eq 1 ]] || fail 'Agent template must contain exactly one effort placeholder.'
167
+ fi
168
+ }
169
+
170
+ mkdir -p "$agent_dir"
171
+ temporary_agent="$(mktemp "$agent_dir/.${agent_file}.XXXXXX")"
172
+ trap 'rm -f "$temporary_agent"' EXIT
173
+ render_agent_config > "$temporary_agent"
174
+ chmod 600 "$temporary_agent"
175
+ if [[ "$skill_source_is_target" != true ]]; then
176
+ for file in "${distributed_files[@]}"; do
177
+ mkdir -p "$(dirname -- "$skill_target/$file")"
178
+ cp "$SKILL_SOURCE/$file" "$skill_target/$file"
179
+ done
180
+ chmod u+x "$skill_target/scripts/setup.sh"
181
+ fi
182
+ mv -f "$temporary_agent" "$agent_target"
183
+ trap - EXIT
184
+ printf '\nConfigured saving-token for %s. Start a new session and verify the writer model with a small task.\n' "$target"