@enfocussw/switch-scripting-context 25.11.0-beta.8 → 25.11.1-beta.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.
Files changed (35) hide show
  1. package/CHANGELOG.md +246 -0
  2. package/README.md +45 -48
  3. package/dist/init.d.ts +15 -0
  4. package/dist/init.js +77 -66
  5. package/docs/switch-api/api-versions.md +116 -0
  6. package/docs/switch-api/connection.md +82 -0
  7. package/docs/switch-api/{api-document-classes.md → document-classes.md} +13 -2
  8. package/docs/switch-api/entry-points.md +171 -0
  9. package/docs/switch-api/{api-enums.md → enums.md} +23 -12
  10. package/docs/switch-api/{api-execution-environment.md → execution-environment.md} +39 -12
  11. package/docs/switch-api/{api-flow-element.md → flow-element.md} +23 -7
  12. package/docs/switch-api/{api-http.md → http.md} +10 -1
  13. package/docs/switch-api/job-patterns.md +178 -0
  14. package/docs/switch-api/{api-job.md → job.md} +23 -9
  15. package/docs/switch-api/{api-logging.md → logging.md} +47 -5
  16. package/docs/switch-api/{api-switch.md → switch.md} +68 -4
  17. package/docs/switch-appstore/app-guidelines.md +258 -0
  18. package/docs/switch-appstore/app-manual.md +84 -0
  19. package/docs/switch-appstore/app-store-listing.md +69 -0
  20. package/docs/switch-appstore/app-store-submission.md +83 -0
  21. package/docs/{switch-api/api-debugging.md → switch-project/debugging.md} +9 -0
  22. package/docs/{switch-api/api-logs-and-dataroot.md → switch-project/logs-and-dataroot.md} +10 -1
  23. package/docs/switch-project/project-planning.md +117 -0
  24. package/docs/switch-project/property-documentation.md +75 -0
  25. package/docs/{switch-api/api-property-editors.md → switch-project/property-editors.md} +55 -8
  26. package/docs/{switch-api/api-script-declaration.md → switch-project/script-declaration.md} +47 -13
  27. package/docs/switch-project/script-structure.md +188 -0
  28. package/docs/{switch-api/api-tooling.md → switch-project/tooling.md} +87 -1
  29. package/docs/{switch-api/api-vscode.md → switch-project/vscode.md} +19 -0
  30. package/docs/switch-scripting.md +49 -23
  31. package/package.json +11 -7
  32. package/docs/switch-api/api-connection.md +0 -63
  33. package/docs/switch-api/api-entry-points.md +0 -82
  34. package/docs/switch-api/api-job-patterns.md +0 -79
  35. package/docs/switch-api/api-script-structure.md +0 -85
package/CHANGELOG.md CHANGED
@@ -5,11 +5,257 @@ All notable changes to this package are documented here. Format follows
5
5
 
6
6
  ## [Unreleased]
7
7
 
8
+ ## [25.11.1-beta.0] - 2026-09-15
9
+
10
+ ### Added
11
+
12
+ - New `api-versions.md` lists which Switch release added each scripting API class, method, and
13
+ enum value. The API docs now mark each method, class, and enum value that needs a newer release
14
+ than the baseline with its minimum Switch version. Agents can check calls against the oldest
15
+ Switch a script or app must support.
16
+
17
+ ### Changed
18
+
19
+ - The Node.js version table now covers Switch 25.07, 26.03, and 26.07. It also explains that
20
+ `--pack` and SwitchScripter overwrite `SwitchVersion`, so a packed script can run on a newer
21
+ Node.js than its folder. It covers fallbacks for unlisted values and notes that API methods
22
+ follow the running Switch, not the manifest.
23
+
24
+ ### Fixed
25
+
26
+ - The routing table in `switch-scripting.md` now renders correctly in strict markdown parsers,
27
+ including VS Code's preview. The generated marker comments previously sat between the table's
28
+ header and its first row, which ended the table early per the GFM table spec; they now wrap the
29
+ whole table instead.
30
+
31
+ ## [25.11.0-beta.18] - 2026-09-11
32
+
33
+ ### Fixed
34
+
35
+ - The script declaration doc no longer tells agents to bump `Version` on every declaration change.
36
+ It now says to bump once per release and keep an unreleased number while editing, matching the
37
+ Appstore guidelines. It also notes that SwitchScripter only accepts minor versions for apps.
38
+
39
+ ## [25.11.0-beta.17] - 2026-09-11
40
+
41
+ ### Changed
42
+ - `job.md`'s `sendToData()` entry and `connection.md`'s `getPropertyStringValue()` entry now warn
43
+ directly, at the point an agent is most likely to read them, that there is no way to check in
44
+ advance whether a connection accepts a given traffic light level. The warning previously lived
45
+ only in a separate section agents weren't always reaching first.
46
+
47
+ ## [25.11.0-beta.16] - 2026-09-10
48
+
49
+ ### Added
50
+ - Connection docs clarify that traffic light levels (`Connection.Level.Success`/`Warning`/`Error`)
51
+ only select where `sendToData()`/`sendToLog()` route a job; they cannot be read back from a
52
+ connection object, and `sendToData()` fails the job if no connected level matches. Scripts that
53
+ need optional traffic light routing should expose a custom property and fall back to
54
+ `sendToNull()`.
55
+
56
+ ### Fixed
57
+ - `switch-scripting.md`'s own text told agents to grep a `docs/` prefix that only exists in this
58
+ repo's source tree, not in a consuming project's copied docs folder. Agents following that
59
+ instruction literally hit a folder that doesn't exist. The text now describes the copied layout.
60
+
61
+ ## [25.11.0-beta.15] - 2026-09-10
62
+
63
+ ### Added
64
+ - `property-documentation.md`, `app-store-listing.md`, `app-manual.md`, and
65
+ `app-store-submission.md`: writing guidance for the four separate places app documentation
66
+ ends up (per-property `Tooltip`/`DetailedInfo`, the declaration's listing fields, the uploaded
67
+ app manual document, and the Appstore website submission forms), including which content is
68
+ reused between them, icon specs, and a shared checklist against generic-sounding text.
69
+
70
+ ### Changed
71
+ - Docs reorganized under `docs/`: the scripting API stays in `docs/switch-api/`; project structure
72
+ and tooling docs moved to `docs/switch-project/`; Appstore publishing guidance moved to
73
+ `docs/switch-appstore/`. Update any bookmarked doc paths after upgrading.
74
+ - Dropped the `api-` prefix from doc filenames, for example `switch-api/job.md`, since each file's
75
+ folder already says what kind of doc it is.
76
+ - Each doc file now carries its own routing metadata (trigger and summary) as YAML frontmatter,
77
+ generated into the routing table and README's doc list instead of hand-duplicated in both.
78
+ README's descriptions now match the table's wording exactly; a few had drifted apart.
79
+
80
+ ### Fixed
81
+ - `init` now removes the destination docs folder before copying, instead of only adding and
82
+ overwriting. Previously, a doc renamed or moved between versions left the old file behind
83
+ permanently after an upgrade, since the destination folder is gitignored and nothing surfaced
84
+ the stale copy.
85
+
86
+ ## [25.11.0-beta.14] - 2026-09-09
87
+
88
+ ### Added
89
+ - `switch-scripting.md` now tells agents to grep `docs/switch-api/` for `known issue`, `gotcha`,
90
+ `quirk`, `caveat` to find documented pitfalls before writing code in an area.
91
+ - `api-entry-points.md` documents that a flow restart replays every queued job through `jobArrived`
92
+ again, even one whose processing was deferred to `timerFired`. A script relying on that pattern
93
+ must recognize an already-registered job and return quickly, or a large backlog is slow to clear.
94
+ - `api-project-planning.md`, a pre-scaffolding checklist for new scripts and apps: Script vs App,
95
+ job-processing approach, target OS, Switch version baseline, concurrency, native/binary npm
96
+ dependency feasibility, and Appstore competition risk. Loaded before any files are scaffolded.
97
+
98
+ ### Changed
99
+ - `README.md` no longer uses dashes as punctuation. Wording is unchanged otherwise.
100
+ - The published README now links to the changelog on jsdelivr, pinned to the version being
101
+ installed. Relative links were rewritten by npm to the private repo, so they were dead for
102
+ consumers. `prepack` swaps them in and `postpack` swaps them back.
103
+
104
+ ## [25.11.0-beta.13] - 2026-09-09
105
+
106
+ ### Fixed
107
+ - README's two CHANGELOG links pointed at an unversioned jsdelivr URL, which always serves the
108
+ *latest published* file. On GitHub that showed the published file rather than the repo's live one,
109
+ hiding unreleased entries. Both are now relative links, so GitHub resolves them to the live file.
110
+ - Generated tool config (Cursor, Codex/OpenCode, Windsurf, Zed, Cline) — the "Core rules" block told
111
+ agents never to edit `<ScriptID>.xml` and to send the user to SwitchScripter instead. That has
112
+ contradicted `api-script-declaration.md` and the `switch-scripting.md` key rules since the agent
113
+ editing policy was added, and it sat in an always-on rules file that outranks any doc the agent
114
+ loads later. Now matches the docs: direct editing is fine under the declaration's rules.
115
+
116
+ ### Added
117
+ - `api-switch.md` — a "Translation extraction rules" section under `Switch.tr()`. Extraction is
118
+ static source analysis, so aliasing `Switch.tr`, concatenating with a variable, or interpolating
119
+ a template literal silently produces no translation entry at all. Documents what does work
120
+ (all quote styles, multi-line, literal-only concatenation, marking a string away from its use
121
+ site) and the `%1` + `messageParams` pattern for dynamic values.
122
+ - `api-job-patterns.md` — "Driving a third-party CLI application", the Node.js replacement for the
123
+ legacy `findApplicationPath`/`ApplicationPath` mechanism: a custom path property on the
124
+ `automatic;choosefile;sltextwithvar;scriptexp` chain, resolved once in `flowStartTriggered` into
125
+ `Scope.FlowElement` global data, with `failProcess()` when discovery fails and cleanup in
126
+ `flowStopTriggered`.
127
+ - `api-script-structure.md` — "Packing an app" and SwitchScripter/Switch version compatibility:
128
+ script folders can only be typed `Script` (pack, then retype to `App` in SwitchScripter), extra
129
+ files are unavailable in script-folder mode, the pack ID is always `com.enfocus.*` and is carried
130
+ over by opening the previous `.enfpack`, an app loads only in its build version or newer (no
131
+ Scripter for 25.07/25.11 — use 2024 Fall), and an unsigned app loads only on the machine that
132
+ built it.
133
+ - `api-app-guidelines.md` — the App-only section is now split into Identity and versioning,
134
+ Top-level declaration properties, Password protection, Localization, Icon, Extra files, Source
135
+ and review hygiene, and what review does and doesn't cover. New rules from the App SDK: script ID
136
+ charset and uniqueness, resubmit-without-bumping after a rejection, minor-version format, the
137
+ three-category limit and Product Management approval, unsigned apps always loading under
138
+ "Custom", `DetailedInfo` feeding the generated HTML docs, `ExecutionGroup` coordination for a
139
+ shared third-party application, `Compatibility`/`SupportInfo`/`AppDiscovery` being required to
140
+ build the pack at all, Node.js password protection being unrecoverable, the six-language limit on
141
+ app translations, the 200×200 Appstore icon, and macOS notarization checks via `codesign -dv`.
142
+ - Generated tool config and `switch-scripting.md` key rules — added the entry-point scanner
143
+ constraints (literal `function` keyword; no trailing-backslash string literals, regex literals, or
144
+ non-`word / word` division) to the always-on rules. Previously these lived only in
145
+ `api-entry-points.md`, so an agent making a small edit without opening that file had no signal
146
+ that the failure mode exists, and it fails silently.
147
+
148
+ ### Changed
149
+ - Generated tool config for Cursor, Codex/OpenCode, Windsurf, Zed and Cline now lists each API doc
150
+ with its "Load when" routing text instead of a bare filename, so those agents can open the one
151
+ file they need without reading `switch-scripting.md` first. Costs ~600 tokens in the always-on
152
+ block, saves a ~1,300-token hub read per session.
153
+ - The routing table in `docs/switch-scripting.md` is now the single source for that list. `init.ts`
154
+ parses it (`parseRoutingTable()`); the two hardcoded 19-entry arrays are gone, as is the drift
155
+ they invited.
156
+ - `api-script-structure.md` — moved "App Store submission guidelines" into
157
+ `api-app-guidelines.md` § App-only and "Execution modes" into `api-execution-environment.md`,
158
+ leaving pointers at both old headings. Reviewing an app or reasoning about concurrency previously
159
+ needed two files for one topic. Existing anchor links still resolve.
160
+ - `docs/switch-scripting.md` and `README.md` — sharpened the routing descriptions for
161
+ `api-job.md` (signatures) vs `api-job-patterns.md` (rules and gotchas), and for
162
+ `api-script-structure.md` vs `api-tooling.md`. Their triggers overlapped enough that an agent had
163
+ to load both files for any job-handling task.
164
+ - `init` no longer copies `docs/superpowers`, `docs/temp`, or `.DS_Store` into a consuming project.
165
+ The published tarball already excludes them, but `init` run from a git clone did not.
166
+
167
+ ## [25.11.0-beta.12] - 2026-09-08
168
+
169
+ ### Fixed
170
+ - `README.md` — linked the two `CHANGELOG.md` mentions to the jsdelivr-served copy of the file
171
+ instead of leaving them as unlinked plain text. A relative link would have npm rewrite it to a
172
+ GitHub blob URL that 404s on npmjs.com, since the source repo is private; jsdelivr serves the file
173
+ straight from the published tarball regardless of repo visibility.
174
+
175
+ ## [25.11.0-beta.11] - 2026-09-08
176
+
177
+ ### Added
178
+ - `api-entry-points.md` — documented that Switch's entry-point scanner is regex-based (not a real
179
+ parser) and can silently drop `function` declarations from certain source shapes: string literals
180
+ ending in a backslash, regex literals (especially ones containing an unescaped `/` inside a
181
+ character class), and division not in a plain `word / word` shape. Applies to every entry point,
182
+ not just the ones checked at load time; `calculateScriptExpression` is the one exception, since
183
+ it's dispatched directly rather than through this scanner. Verified against real
184
+ `SwitchScriptTool --pack` output for each failure mode.
185
+ - `api-tooling.md` — new "Verify entry points before packing" section with a Python/Node.js script
186
+ to check a built `main.js` for the expected entry points before relying on `--pack`, which doesn't
187
+ validate this itself.
188
+ - `api-script-structure.md` — cross-linked the entry-point scanner constraints from the "Agent
189
+ editing policy" callout.
190
+ - `api-app-guidelines.md` — new pre-publish checklist for scripts submitted to the Enfocus Appstore,
191
+ covering property naming/tooltip/editor/default requirements, entry point and `sendTo*()`
192
+ consistency with declared connections, logging quality, temp file/path handling, and app-only
193
+ packaging rules (no embedded Oracle JRE, universal signed macOS Mach-O binaries in extra files,
194
+ immutable extra files, translation completeness). Registered in the routing table, both `init.ts`
195
+ doc-file arrays, and the README's included-docs list.
196
+
197
+ ### Changed
198
+ - `switch-scripting.md` — broadened the `api-entry-points.md` routing-table trigger to any edit to
199
+ `main.ts`/`main.js`, not just adding a new entry point.
200
+ - `api-property-editors.md` — documented that the `nofiles`/`allfiles`/`allotherfiles` and
201
+ `nofolders`/`allfolders`/`allotherfolders` literal editors are specifically for connection
202
+ include/exclude filter mask properties, with the exact `Editor`/`Default`/`Subtype` chain verified
203
+ against Switch's own built-in connection filter declarations; added the matching rows to Common
204
+ practices. Noted that `next`/`current` have no confirmed script-facing use case. Noted that `none`
205
+ is the sanctioned way to allow an empty value under `Validation="Standard"`.
206
+ - `api-script-declaration.md` — cross-linked the `Validation` row to the `none` literal editor for
207
+ allowing empty values under `Standard` validation.
208
+ - `api-app-guidelines.md`, `api-script-declaration.md`, `api-property-editors.md`,
209
+ `api-entry-points.md`, `api-job-patterns.md`, `api-logging.md`, `api-script-structure.md` —
210
+ reclassified the Appstore submission rules added previously: most turned out to be universal
211
+ correctness rules (functional requirements or bugs if violated) rather than app-specific policy,
212
+ so their "App guideline" framing was removed and they're now stated as plain rules that apply to
213
+ every script. Only a handful remain "mandatory for apps, recommended for scripts" (property
214
+ naming/tooltip/default, non-module-editor requirement, log volume, platform-independent paths).
215
+ "No embedded Oracle JRE" moved out of the app-only section entirely, since it applies to any
216
+ script bundling extra files. `api-app-guidelines.md` is now organized into three explicit tiers
217
+ (Universal / Apps required-scripts recommended / Apps only) instead of one flat list.
218
+ - `api-script-declaration.md`, `api-property-editors.md`, `api-entry-points.md`, `api-job-patterns.md`,
219
+ `api-job.md`, `api-logging.md`, `api-script-structure.md` — wove the individual Appstore submission
220
+ rules (above) directly into the relevant existing sections (property attributes, editor tables,
221
+ entry point signatures, `sendTo*()`/`ConnectionType` rules, logging conventions, packaging), each
222
+ cross-linked to and from the new checklist, so they're followed from the start rather than caught
223
+ only at a pre-publish review.
224
+ - `api-script-declaration.md` — fixed the `Validation="Custom"` row, which named a nonexistent
225
+ `isPropertyValid` entry point; the actual entry point (per `api-entry-points.md`) is
226
+ `validateProperties`/`validateConnectionProperties`.
227
+ - `api-job-patterns.md` — clarified that the automatic executor-refresh cleanup only applies to
228
+ temp files created via `flowElement.createPathWithName()` (the recommended default); temp files
229
+ created any other way must be cleaned up explicitly by the script. Also notes that the `tmp` npm
230
+ package is not recommended, and if used anyway, its `setGracefulCleanup()` is not always reliable
231
+ in the Switch execution environment and `discardDescriptor: true` should be set.
232
+ - `api-flow-element.md`, `api-connection.md`, `api-script-declaration.md` — cross-linked and made
233
+ explicit that `getPropertyStringValue()`/`connection.getPropertyStringValue()` throws
234
+ `"Invalid tag: <tag>"` for a `Dependency` dependent property currently hidden by its master's
235
+ value, and that `hasProperty()`/`connection.hasProperty()` should be used to guard against this
236
+ (e.g. before fetching properties dependent on a drop-down/enum master). Also notes that the shown
237
+ set can vary per job if the master's value is dynamic, and that a hidden dependent's value cannot
238
+ be read at all — a script needing more than one dependency group's data at once must use a
239
+ different property structure, not `Dependency`-based hiding.
240
+
241
+ ## [25.11.0-beta.10] - 2026-09-03
242
+
243
+ ### Added
244
+ - `api-job-patterns.md` — documented a known ordering bug: creating a child job before writing a
245
+ pending dataset causes the child to inherit the stale dataset, leading to a destructive
246
+ file-move race at `sendTo*()`. `api-job.md`'s dataset/child-job entries now note which calls
247
+ are immediate vs. deferred.
248
+
249
+ ## [25.11.0-beta.9] - 2026-08-26
250
+
8
251
  ### Added
9
252
  - `package.json` now declares `"main": "dist/init.js"`. Deliberately no `"exports"` field, so
10
253
  `switch-scripting-context/package.json` also stays reachable for consumers that need to read the
11
254
  package's own version (e.g. to compare against a script's target Switch version).
12
255
 
256
+ ### Changed
257
+ - Package now publishes to the public npm registry instead of GitHub Packages.
258
+
13
259
  ## [25.11.0-beta.8] - 2026-08-25
14
260
 
15
261
  ### Removed
package/README.md CHANGED
@@ -4,21 +4,11 @@ AI coding assistant context for [Enfocus Switch](https://www.enfocus.com/en/swit
4
4
 
5
5
  Installs curated API reference docs and generates config files for 8 AI coding agents (Claude Code, GitHub Copilot, Cursor, Codex CLI/OpenCode, Gemini CLI, Windsurf, Zed, and Cline) so AI assistants understand the Switch scripting API out of the box.
6
6
 
7
- See [CHANGELOG.md](CHANGELOG.md) for what's changed between versions.
7
+ See [CHANGELOG.md](https://cdn.jsdelivr.net/npm/@enfocussw/switch-scripting-context@25.11.1-beta.0/CHANGELOG.md) (also included in this package) for what's changed between versions.
8
8
 
9
9
  ## Usage
10
10
 
11
- > **Private beta.** This package is not on npm yet. Beta testers install from a
12
- > tarball supplied directly; the npm commands below apply once it is published.
13
-
14
- Install the tarball you were given, then run `init` in any Switch scripting project:
15
-
16
- ```bash
17
- npm install --save-dev ./enfocussw-switch-scripting-context-25.11.0-beta.1.tgz
18
- npx switch-scripting-context init
19
- ```
20
-
21
- After publication, install straight from npm instead:
11
+ Run `init` in any Switch scripting project:
22
12
 
23
13
  ```bash
24
14
  npx @enfocussw/switch-scripting-context init
@@ -44,16 +34,14 @@ The package version tracks the Switch release its docs describe:
44
34
  └────── Switch version (25.11)
45
35
  ```
46
36
 
47
- - `25.11.x` — every release of this package documenting **Switch 25.11**. Patch increments are doc updates, fixes, and new features of the CLI itself.
48
- - The next Switch release moves the first two numbers (e.g. Switch 26.05 → `26.5.0`). Note that semver forbids leading zeros, so `26.05` is published as `26.5`.
37
+ - `25.11.x`: every release of this package documenting **Switch 25.11**. Patch increments are doc updates, fixes, and new features of the CLI itself.
38
+ - The next Switch release moves the first two numbers (e.g. Switch 27.07 → `27.7.0`). Note that semver forbids leading zeros, so `27.07` is published as `27.7`.
49
39
  - **Pin with `~`, not `^`.** `~25.11.0` stays on Switch 25.11; `^25.11.0` would happily install `25.12.0`, which targets a different Switch release.
50
40
 
51
41
  ### Prereleases
52
42
 
53
- Beta builds append a prerelease suffix — `25.11.0-beta.1`. These sort *below* `25.11.0`,
43
+ Beta builds append a prerelease suffix, for example `25.11.0-beta.1`. These sort *below* `25.11.0`,
54
44
  so the beta line precedes GA and leaves `25.11.0` free for the first published release.
55
- During the beta these are distributed as tarballs rather than published, so the suffix is
56
- purely a label telling testers which build they have.
57
45
 
58
46
  ## What it does
59
47
 
@@ -65,9 +53,9 @@ purely a label telling testers which build they have.
65
53
 
66
54
  | Tool | File | How context is loaded |
67
55
  |---|---|---|
68
- | Claude Code / ClawCode | `CLAUDE.md` | `@switch-docs/switch-scripting.md` import — hub file routes to specific API docs on demand |
56
+ | Claude Code / ClawCode | `CLAUDE.md` | `@switch-docs/switch-scripting.md` import; hub file routes to specific API docs on demand |
69
57
  | GitHub Copilot | `.github/copilot-instructions.md` | `#file:` reference to hub |
70
- | GitHub Copilot (scoped) | `.github/instructions/switch-scripting.instructions.md` | `applyTo: "**/*.ts"` — auto-attaches to every TypeScript file edit |
58
+ | GitHub Copilot (scoped) | `.github/instructions/switch-scripting.instructions.md` | `applyTo: "**/*.ts"`; auto-attaches to every TypeScript file edit |
71
59
  | Cursor | `.cursor/rules/switch-scripting.mdc` | Inline key rules + full API file path list |
72
60
  | Codex CLI / OpenCode | `AGENTS.md` | Inline key rules + full API file path list |
73
61
  | Gemini CLI | `GEMINI.md` | `@switch-docs/switch-scripting.md` import |
@@ -75,28 +63,28 @@ purely a label telling testers which build they have.
75
63
  | Zed | `.rules` | Inline key rules + full API file path list |
76
64
  | Cline | `.clinerules` | Inline key rules + full API file path list |
77
65
 
78
- All files use `<!-- switch-scripting-context begin -->` / `<!-- switch-scripting-context end -->` markers. Re-running `init` replaces only the Switch section in existing files — project-specific rules outside the markers are untouched.
66
+ All files use `<!-- switch-scripting-context begin -->` / `<!-- switch-scripting-context end -->` markers. Re-running `init` replaces only the Switch section in existing files. Project-specific rules outside the markers are untouched.
79
67
 
80
68
  ## Using this with your coding agent
81
69
 
82
- Once `init` has run, just work normally — describe what you want in plain terms and prompt as you
70
+ Once `init` has run, just work normally. Describe what you want in plain terms and prompt as you
83
71
  usually would. Your agent picks up the Switch context automatically (via `@import` for Claude
84
72
  Code/Gemini, or the inlined rules + file list for the others) whenever it's working in the project,
85
73
  and pulls in the specific API doc it needs for the task at hand on its own. You don't need to know
86
74
  the doc file names or tell it which one to read.
87
75
 
88
76
  A few things this gets you without asking for them by name:
89
- - Scaffolding a new entry point, handling a webhook, or reading/creating datasets and jobs — the
77
+ - Scaffolding a new entry point, handling a webhook, or reading/creating datasets and jobs. The
90
78
  agent consults the matching API reference before writing the code.
91
- - Diagnosing why a script isn't behaving as expected — the agent knows it can locate and query
79
+ - Diagnosing why a script isn't behaving as expected. The agent knows it can locate and query
92
80
  Switch's own log database (`ServerLogs.db3`) rather than only re-reasoning about the code.
93
- - Creating, packing, or deploying a script — the agent uses `SwitchScriptTool` with the documented
94
- flags and behavior, rather than hand-rolling the steps.
95
- - Editing the script's XML declaration — the agent follows the documented rules and knows which
96
- properties (app path/license) are off-limits and left to SwitchScripter's GUI instead.
81
+ - Creating, packing, or deploying a script. The agent uses `SwitchScriptTool` with the documented
82
+ flags and behaviour, rather than hand-rolling the steps.
83
+ - Editing the script's XML declaration. The agent follows the documented rules and knows which
84
+ properties (app path/licence) are off-limits and left to SwitchScripter's GUI instead.
97
85
 
98
- Re-run `init` after upgrading this package so the copied docs and generated config files catch up —
99
- see [CHANGELOG.md](CHANGELOG.md) for what changed.
86
+ Re-run `init` after upgrading this package so the copied docs and generated config files catch up.
87
+ See [CHANGELOG.md](https://cdn.jsdelivr.net/npm/@enfocussw/switch-scripting-context@25.11.1-beta.0/CHANGELOG.md) for what changed.
100
88
 
101
89
  ## Options
102
90
 
@@ -142,22 +130,31 @@ npm install --save-dev "https://github.com/enfocus-switch/types-switch-scripting
142
130
 
143
131
  The `switch-docs/` folder contains:
144
132
 
145
- - `switch-scripting.md` — master index with execution environment rules and "load when" routing table
146
- - `switch-api/api-entry-points.md` — all entry point signatures and when each is called
147
- - `switch-api/api-job.md` — `Job` class: routing, file access, child jobs, private data, datasets
148
- - `switch-api/api-flow-element.md` — `FlowElement`: properties, connections, job creation, logging
149
- - `switch-api/api-switch.md` — `Switch` global: global data, webhooks, abort, server utilities
150
- - `switch-api/api-connection.md` — `Connection`: type, properties, file count
151
- - `switch-api/api-http.md` — `HttpRequest` / `HttpResponse` and webhook pattern
152
- - `switch-api/api-enums.md` — all enums with string values (`LogLevel`, `AccessLevel`, `Scope`, etc.)
153
- - `switch-api/api-document-classes.md` — `PdfDocument`, `ImageDocument`, `XmlDocument`, `XmpDocument`
154
- - `switch-api/api-script-declaration.md` — XML declaration reference
155
- - `switch-api/api-script-structure.md` — script folder/package structure and manifest format
156
- - `switch-api/api-tooling.md` — SwitchScriptTool commands, script folder vs package, build and deployment
157
- - `switch-api/api-debugging.md` — enabling debug mode, debuggable entry points, VS Code attach
158
- - `switch-api/api-logging.md` — log levels, when/what to log, `console.log` limitation, common gotchas
159
- - `switch-api/api-logs-and-dataroot.md` — locating the application data root, querying `ServerLogs.db3` directly to diagnose a script
160
- - `switch-api/api-vscode.md` — type declarations, tsconfig for TypeScript 6, ESLint rules
161
- - `switch-api/api-property-editors.md` — property editor types and string return values
162
- - `switch-api/api-job-patterns.md` — file access semantics, routing rules, child jobs, executor limits
163
- - `switch-api/api-execution-environment.md` — process model, state persistence across jobs, error handling, npm/native module constraints
133
+ - `switch-scripting.md`: master index with execution environment rules and "load when" routing table
134
+ <!-- docs-index:readme begin -->
135
+ - `switch-project/project-planning.md`: Pre-scaffolding checklist: Script vs App, job-processing approach, target OS, Switch version baseline, concurrency, native/binary npm dependencies, Appstore competition risk
136
+ - `switch-api/entry-points.md`: All entry point signatures, constraints, and when each is called
137
+ - `switch-api/switch.md`: `Switch` (`s`): global data, webhooks, abort, server utilities
138
+ - `switch-api/flow-element.md`: `FlowElement`: properties, connections, job creation, logging
139
+ - `switch-api/job.md`: `Job` **signatures**: routing, file access, child jobs, private data, datasets
140
+ - `switch-api/connection.md`: `Connection`: type, properties, file count
141
+ - `switch-api/http.md`: `HttpRequest` / `HttpResponse` + webhook pattern
142
+ - `switch-api/enums.md`: All enums with string values (`LogLevel`, `AccessLevel`, `DatasetModel`, `Scope`, `Priority`, `Connection.Level`, etc.)
143
+ - `switch-api/document-classes.md`: `PdfDocument`, `PdfPage`, `ImageDocument`, `XmlDocument`, `XmpDocument`: read-only file introspection
144
+ - `switch-project/script-structure.md`: What files a script folder contains, `manifest.xml` format, how `SwitchVersion` selects the Node.js version and which tools overwrite it, Script vs App
145
+ - `switch-project/tooling.md`: SwitchScriptTool commands and install paths, folder vs `.sscript` trade-offs, deployment
146
+ - `switch-project/debugging.md`: Enabling debug mode in Switch Designer, debuggable entry points, VS Code attach
147
+ - `switch-project/vscode.md`: Type declarations, tsconfig for TypeScript 6, ESLint rules
148
+ - `switch-project/script-declaration.md`: XML declaration reference: properties, connections, execution config; agents may edit this file directly
149
+ - `switch-project/property-editors.md`: Property editor types, string return values, literal editors, dropdowns
150
+ - `switch-api/job-patterns.md`: `Job` **rules and gotchas**: file access semantics, temp cleanup, which `sendTo*()` suits which connection type, dataset/child ordering, executor limits
151
+ - `switch-api/execution-environment.md`: Execution modes (`Concurrent`/`Serialized`, `ExecutionGroup`, `NumberOfSlots`), process/concurrency model, state persistence across job invocations, unhandled-rejection behavior, npm/native module constraints
152
+ - `switch-api/logging.md`: Log level semantics, logging practice, `console.log` limitation, common gotchas
153
+ - `switch-project/logs-and-dataroot.md`: Locating the Application Data Root, querying `ServerLogs.db3` directly
154
+ - `switch-appstore/app-guidelines.md`: Pre-publish checklist for Appstore apps: property naming/tooltips/editors, entry point and sendTo consistency, logging quality, packaging, and the app-only submission rules (localization, signed universal macOS binaries)
155
+ - `switch-project/property-documentation.md`: Writing guidance for `Tooltip` and `DetailedInfo` content on properties/connections
156
+ - `switch-appstore/app-store-listing.md`: Writing guidance for the declaration's Appstore listing fields: `Description`, `Compatibility`, `SupportInfo`, `AppDiscovery`, `Connections`
157
+ - `switch-appstore/app-manual.md`: Writing guidance for the separate app manual document uploaded during Appstore review (`documentation-app_name.docx` template)
158
+ - `switch-appstore/app-store-submission.md`: Writing guidance for the Create Appstore App / Create Appstore App Version web forms: Short Description, What's new, Eula, icon specs, and which fields reuse content already written elsewhere
159
+ - `switch-api/api-versions.md`: Which Switch release added each scripting API class, method, and enum value; API availability follows the running Switch, not `manifest.xml`
160
+ <!-- docs-index:readme end -->
package/dist/init.d.ts CHANGED
@@ -9,6 +9,21 @@ export interface ToolDefinition {
9
9
  altIds?: string[];
10
10
  files: ToolFile[];
11
11
  }
12
+ export interface ApiDoc {
13
+ /** Path within docs/, e.g. "switch-api/job.md". */
14
+ file: string;
15
+ /** The routing table's "Load when" text, verbatim. */
16
+ loadWhen: string;
17
+ }
18
+ /**
19
+ * The routing table in docs/switch-scripting.md is the single source of truth for
20
+ * which API docs exist and when to load each one. Everything the CLI generates is
21
+ * derived from it, so a new doc file needs registering in exactly one place here
22
+ * (plus README.md, which init.test.ts checks).
23
+ */
24
+ export declare function parseRoutingTable(root?: string): ApiDoc[];
25
+ /** Filenames only, in routing-table order. */
26
+ export declare function apiFiles(root?: string): string[];
12
27
  export declare function generateAgentsMd(docsDir: string): string;
13
28
  export declare function generateGeminiMd(docsDir: string): string;
14
29
  export declare function generateWindsurfRules(docsDir: string): string;
package/dist/init.js CHANGED
@@ -33,6 +33,8 @@ var __importStar = (this && this.__importStar) || (function () {
33
33
  };
34
34
  })();
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.parseRoutingTable = parseRoutingTable;
37
+ exports.apiFiles = apiFiles;
36
38
  exports.generateAgentsMd = generateAgentsMd;
37
39
  exports.generateGeminiMd = generateGeminiMd;
38
40
  exports.generateWindsurfRules = generateWindsurfRules;
@@ -47,6 +49,46 @@ const readline = __importStar(require("readline"));
47
49
  // ─── Markers ─────────────────────────────────────────────────────────────────
48
50
  const MARKER_BEGIN = '<!-- switch-scripting-context begin -->';
49
51
  const MARKER_END = '<!-- switch-scripting-context end -->';
52
+ // ─── Shared content (single source of truth for all generated tool files) ────
53
+ /** Package root, whether running from src/ (ts-node) or dist/. */
54
+ function packageRoot() {
55
+ return path.resolve(__dirname, '..');
56
+ }
57
+ /**
58
+ * The routing table in docs/switch-scripting.md is the single source of truth for
59
+ * which API docs exist and when to load each one. Everything the CLI generates is
60
+ * derived from it, so a new doc file needs registering in exactly one place here
61
+ * (plus README.md, which init.test.ts checks).
62
+ */
63
+ function parseRoutingTable(root = packageRoot()) {
64
+ const hub = fs.readFileSync(path.join(root, 'docs', 'switch-scripting.md'), 'utf8');
65
+ const docs = [];
66
+ for (const line of hub.split('\n')) {
67
+ // | `<switch-api|switch-project|switch-appstore>/<file>.md` | <contents> | <load when> |
68
+ const m = /^\|\s*`(switch-api|switch-project|switch-appstore)\/([a-z0-9-]+\.md)`\s*\|(.*)\|(.*)\|\s*$/.exec(line);
69
+ if (m)
70
+ docs.push({ file: `${m[1]}/${m[2]}`, loadWhen: m[4].trim() });
71
+ }
72
+ if (docs.length === 0) {
73
+ throw new Error('No API docs found in docs/switch-scripting.md — the routing table format changed. ' +
74
+ 'Generated tool config would be empty; fix parseRoutingTable() before publishing.');
75
+ }
76
+ return docs;
77
+ }
78
+ /** Filenames only, in routing-table order. */
79
+ function apiFiles(root) {
80
+ return parseRoutingTable(root).map(d => d.file);
81
+ }
82
+ const INLINE_CORE_RULES = `## Core rules
83
+
84
+ - Entry point functions are top-level async functions — do NOT use \`export\`, arrow functions, or class methods; declare them with the literal \`function\` keyword.
85
+ - Switch finds entry points with a regex, not a parser. Never write a string literal whose content ends with a backslash, a regex literal, or division outside the plain \`word / word\` shape — each silently deletes a span of real code and the entry points inside it, with no error. Read \`entry-points.md\` § Entry-point scanner constraints before editing \`main.ts\`/\`main.js\`.
86
+ - Every \`jobArrived\` must end with exactly one \`job.sendTo*()\` or \`job.fail()\`.
87
+ - Use \`AccessLevel.ReadOnly\` for \`job.get()\` unless the file content will be modified.
88
+ - After \`createJob()\`, \`createChild()\`, or \`createDataset()\` with a file path, delete the source file after routing — Switch does not auto-remove it.
89
+ - The XML declaration (\`<ScriptID>.xml\`) can be edited directly — read \`script-declaration.md\` first and follow its rules exactly (nothing validates this format, so mistakes fail silently). Never change an existing script's \`Name\`; bump \`Version\` on every declaration edit. Leave \`manifest.xml\` to the user unless explicitly asked.
90
+ - After editing \`main.ts\`, transpile with \`SwitchScriptTool --transpile <folder>\` — do not use \`tsc\` directly.
91
+ - Never use a script folder in production — pack with \`SwitchScriptTool --pack\` first; folders are excluded from flow exports.`;
50
92
  // ─── Content generators ──────────────────────────────────────────────────────
51
93
  function generateClaudeMd(docsDir) {
52
94
  return `${MARKER_BEGIN}
@@ -76,27 +118,6 @@ You are working on an Enfocus Switch scripting project (Node.js/TypeScript).
76
118
  ${MARKER_END}`;
77
119
  }
78
120
  function generateCursorMdc(docsDir) {
79
- const apiFiles = [
80
- 'api-entry-points.md',
81
- 'api-job.md',
82
- 'api-flow-element.md',
83
- 'api-connection.md',
84
- 'api-http.md',
85
- 'api-enums.md',
86
- 'api-document-classes.md',
87
- 'api-script-declaration.md',
88
- 'api-script-structure.md',
89
- 'api-tooling.md',
90
- 'api-debugging.md',
91
- 'api-vscode.md',
92
- 'api-property-editors.md',
93
- 'api-job-patterns.md',
94
- 'api-switch.md',
95
- 'api-execution-environment.md',
96
- 'api-logging.md',
97
- 'api-logs-and-dataroot.md',
98
- ];
99
- const fileList = apiFiles.map(f => `- \`${docsDir}/switch-api/${f}\``).join('\n');
100
121
  return `---
101
122
  description: Enfocus Switch scripting rules and API reference for Node.js/TypeScript scripts
102
123
  globs: ["**/*.ts", "**/*.js"]
@@ -106,55 +127,21 @@ alwaysApply: false
106
127
  ${MARKER_BEGIN}
107
128
  You are working on an Enfocus Switch scripting project (Node.js/TypeScript).
108
129
 
109
- ## Core rules
110
-
111
- - Entry point functions are top-level async functions — do NOT use \`export\`.
112
- - Every \`jobArrived\` must end with exactly one \`job.sendTo*()\` or \`job.fail()\`.
113
- - Use \`AccessLevel.ReadOnly\` for \`job.get()\` unless the file content will be modified.
114
- - After \`createJob()\`, \`createChild()\`, or \`createDataset()\` with a file path, delete the source file after routing — Switch does not auto-remove it.
115
- - Never edit \`<ScriptID>.xml\` or \`manifest.xml\` directly. For property/connection changes, instruct the user to use SwitchScripter.
116
- - After editing \`main.ts\`, transpile with \`SwitchScriptTool --transpile <folder>\` — do not use \`tsc\` directly.
117
- - Never use a script folder in production — pack with \`SwitchScriptTool --pack\` first; folders are excluded from flow exports.
130
+ ${INLINE_CORE_RULES}
118
131
 
119
132
  ## API reference
120
133
 
121
- Read \`${docsDir}/switch-scripting.md\` for the full index, then consult the relevant file:
134
+ Load the file matching the task below. \`${docsDir}/switch-scripting.md\` has the same index plus
135
+ the project-wide key rules:
122
136
 
123
- ${fileList}
137
+ ${inlineApiFileList(docsDir)}
124
138
  ${MARKER_END}`;
125
139
  }
126
- // ─── Shared inline content (for tools without @file import support) ──────────
127
- const INLINE_CORE_RULES = `## Core rules
128
-
129
- - Entry point functions are top-level async functions — do NOT use \`export\`.
130
- - Every \`jobArrived\` must end with exactly one \`job.sendTo*()\` or \`job.fail()\`.
131
- - Use \`AccessLevel.ReadOnly\` for \`job.get()\` unless the file content will be modified.
132
- - After \`createJob()\`, \`createChild()\`, or \`createDataset()\` with a file path, delete the source file after routing — Switch does not auto-remove it.
133
- - Never edit \`<ScriptID>.xml\` or \`manifest.xml\` directly. For property/connection changes, instruct the user to use SwitchScripter.
134
- - After editing \`main.ts\`, transpile with \`SwitchScriptTool --transpile <folder>\` — do not use \`tsc\` directly.
135
- - Never use a script folder in production — pack with \`SwitchScriptTool --pack\` first; folders are excluded from flow exports.`;
136
- const API_FILES = [
137
- 'api-entry-points.md',
138
- 'api-job.md',
139
- 'api-flow-element.md',
140
- 'api-connection.md',
141
- 'api-http.md',
142
- 'api-enums.md',
143
- 'api-document-classes.md',
144
- 'api-script-declaration.md',
145
- 'api-script-structure.md',
146
- 'api-tooling.md',
147
- 'api-debugging.md',
148
- 'api-vscode.md',
149
- 'api-property-editors.md',
150
- 'api-job-patterns.md',
151
- 'api-switch.md',
152
- 'api-execution-environment.md',
153
- 'api-logging.md',
154
- 'api-logs-and-dataroot.md',
155
- ];
140
+ // ─── Inline block (for tools without @file import support) ──────────────────
156
141
  function inlineApiFileList(docsDir) {
157
- return API_FILES.map(f => `- \`${docsDir}/switch-api/${f}\``).join('\n');
142
+ return parseRoutingTable()
143
+ .map(d => `- \`${docsDir}/${d.file}\` — ${d.loadWhen}`)
144
+ .join('\n');
158
145
  }
159
146
  function generateInlineBlock(docsDir) {
160
147
  return `You are working on an Enfocus Switch scripting project (Node.js/TypeScript).
@@ -163,7 +150,8 @@ ${INLINE_CORE_RULES}
163
150
 
164
151
  ## API reference
165
152
 
166
- Read \`${docsDir}/switch-scripting.md\` for the full index, then consult the relevant file:
153
+ Load the file matching the task below. \`${docsDir}/switch-scripting.md\` has the same index plus
154
+ the project-wide key rules:
167
155
 
168
156
  ${inlineApiFileList(docsDir)}`;
169
157
  }
@@ -345,13 +333,36 @@ function applyFileAction(action, dryRun) {
345
333
  console.log(` ${rel} → ${label}`);
346
334
  }
347
335
  // ─── Docs copy ────────────────────────────────────────────────────────────────
336
+ /** Paths under docs/ that are never shipped to a consuming project. */
337
+ const DOCS_EXCLUDE = ['superpowers', 'temp'];
348
338
  function copyDocs(packageRoot, destDir, dryRun) {
349
339
  const src = path.join(packageRoot, 'docs');
340
+ const rel = path.relative(process.cwd(), destDir);
350
341
  if (dryRun) {
351
- console.log(` [dry-run] Copying docs/ → ${path.relative(process.cwd(), destDir)}/`);
342
+ if (fs.existsSync(destDir)) {
343
+ console.log(` [dry-run] ${rel}/ → wiped (removes files from a previous version, e.g. after a doc was renamed or moved)`);
344
+ }
345
+ console.log(` [dry-run] Copying docs/ → ${rel}/`);
352
346
  return;
353
347
  }
354
- fs.cpSync(src, destDir, { recursive: true });
348
+ // destDir is entirely owned by this tool (see the .gitignore comment it writes), so wiping
349
+ // it first is safe. Without this, a doc renamed or moved between versions (e.g. a docs/
350
+ // folder restructuring) would leave the old file behind forever: cpSync only adds/overwrites,
351
+ // it never removes, and destDir is gitignored so nothing would surface the staleness.
352
+ if (fs.existsSync(destDir)) {
353
+ fs.rmSync(destDir, { recursive: true, force: true });
354
+ }
355
+ // The published tarball already omits these, but init may run from a git clone.
356
+ fs.cpSync(src, destDir, {
357
+ recursive: true,
358
+ filter: (from) => {
359
+ const rel = path.relative(src, from);
360
+ if (!rel)
361
+ return true;
362
+ const [top] = rel.split(path.sep);
363
+ return !DOCS_EXCLUDE.includes(top) && path.basename(from) !== '.DS_Store';
364
+ },
365
+ });
355
366
  console.log(` docs → ${path.relative(process.cwd(), destDir)}/`);
356
367
  }
357
368
  // ─── .gitignore update ───────────────────────────────────────────────────────