@enfocussw/switch-scripting-context 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.
Files changed (33) hide show
  1. package/CHANGELOG.md +504 -0
  2. package/README.md +192 -0
  3. package/bin/cli.js +8 -0
  4. package/dist/init.d.ts +78 -0
  5. package/dist/init.js +894 -0
  6. package/docs/switch-api/api-versions.md +127 -0
  7. package/docs/switch-api/connection.md +82 -0
  8. package/docs/switch-api/document-classes.md +189 -0
  9. package/docs/switch-api/entry-points.md +185 -0
  10. package/docs/switch-api/enums.md +181 -0
  11. package/docs/switch-api/execution-environment.md +143 -0
  12. package/docs/switch-api/flow-element.md +143 -0
  13. package/docs/switch-api/http.md +96 -0
  14. package/docs/switch-api/job-patterns.md +238 -0
  15. package/docs/switch-api/job.md +187 -0
  16. package/docs/switch-api/logging.md +117 -0
  17. package/docs/switch-api/switch.md +210 -0
  18. package/docs/switch-appstore/app-guidelines.md +281 -0
  19. package/docs/switch-appstore/app-manual.md +84 -0
  20. package/docs/switch-appstore/app-store-listing.md +69 -0
  21. package/docs/switch-appstore/app-store-submission.md +83 -0
  22. package/docs/switch-project/debugging.md +61 -0
  23. package/docs/switch-project/logs-and-dataroot.md +80 -0
  24. package/docs/switch-project/node-versions.md +87 -0
  25. package/docs/switch-project/project-planning.md +149 -0
  26. package/docs/switch-project/property-documentation.md +75 -0
  27. package/docs/switch-project/property-editors.md +249 -0
  28. package/docs/switch-project/script-declaration.md +407 -0
  29. package/docs/switch-project/script-structure.md +157 -0
  30. package/docs/switch-project/tooling.md +165 -0
  31. package/docs/switch-project/vscode.md +90 -0
  32. package/docs/switch-scripting.md +70 -0
  33. package/package.json +65 -0
package/README.md ADDED
@@ -0,0 +1,192 @@
1
+ # switch-scripting-context
2
+
3
+ AI coding assistant context for [Enfocus Switch](https://www.enfocus.com/en/switch) scripting projects (Node.js/TypeScript).
4
+
5
+ Installs curated API reference docs and generates config files for 10 AI coding agents (Claude Code, GitHub Copilot, Cursor, Codex CLI/OpenCode/Pi, Gemini CLI, Windsurf, Zed, Cline, Continue, and Aider) so AI assistants understand the Switch scripting API out of the box.
6
+
7
+ See [CHANGELOG.md](https://cdn.jsdelivr.net/npm/@enfocussw/switch-scripting-context@0.1.0/CHANGELOG.md) (also included in this package) for what's changed between versions.
8
+
9
+ ## Usage
10
+
11
+ Run `init` in any Switch scripting project:
12
+
13
+ ```bash
14
+ npx @enfocussw/switch-scripting-context init
15
+ ```
16
+
17
+ Or as a dev dependency, to pin the docs version:
18
+
19
+ ```bash
20
+ npm install --save-dev "@enfocussw/switch-scripting-context@^0.1.0"
21
+ npx switch-scripting-context init
22
+ ```
23
+
24
+ Re-run after upgrading the package to refresh docs and AI config files.
25
+
26
+ ## TypeScript types
27
+
28
+ This package does not bundle `@types/switch-scripting`. Add the type declarations to your project manually:
29
+
30
+ ```bash
31
+ npm install --save-dev "https://github.com/enfocus-switch/types-switch-scripting/archive/refs/tags/v24.1.1-final.tar.gz"
32
+ ```
33
+
34
+ ## Using this with your coding agent
35
+
36
+ Once `init` has run, just work normally. Describe what you want in plain terms and prompt as you
37
+ usually would. Your agent picks up the Switch context automatically (via `@import` for Claude
38
+ Code/Gemini, or the inlined rules + file list for the others) whenever it's working in the project,
39
+ and pulls in the specific API doc it needs for the task at hand on its own. You don't need to know
40
+ the doc file names or tell it which one to read.
41
+
42
+ A few things this gets you without asking for them by name:
43
+ - Scaffolding a new entry point, handling a webhook, or reading/creating datasets and jobs. The
44
+ agent consults the matching API reference before writing the code.
45
+ - Diagnosing why a script isn't behaving as expected. The agent knows it can locate and query
46
+ Switch's own log database (`ServerLogs.db3`) rather than only re-reasoning about the code.
47
+ - Creating, packing, or deploying a script. The agent uses `SwitchScriptTool` with the documented
48
+ flags and behaviour, rather than hand-rolling the steps.
49
+ - Editing the script's XML declaration. The agent follows the documented rules and knows which
50
+ properties (app path/licence) are off-limits and left to SwitchScripter's GUI instead.
51
+
52
+ Re-run `init` after upgrading this package so the copied docs and generated config files catch up.
53
+ See [CHANGELOG.md](https://cdn.jsdelivr.net/npm/@enfocussw/switch-scripting-context@0.1.0/CHANGELOG.md) for what changed.
54
+
55
+ ## What it does
56
+
57
+ 1. Copies the Switch API reference docs to `docs-for-agents/` in your project
58
+ 2. Generates AI config files for each tool (see below)
59
+ 3. Appends `docs-for-agents/` to `.gitignore`
60
+
61
+ ### Generated files
62
+
63
+ | Tool | File | How context is loaded |
64
+ |---|---|---|
65
+ | Claude Code / ClawCode | `CLAUDE.md` | `@docs-for-agents/switch-scripting.md` import; hub file routes to specific API docs on demand |
66
+ | GitHub Copilot | `.github/copilot-instructions.md` | `#file:` reference to hub |
67
+ | GitHub Copilot (scoped) | `.github/instructions/switch-scripting.instructions.md` | `applyTo: "**/*.ts"`; auto-attaches to every TypeScript file edit |
68
+ | Cursor | `.cursor/rules/switch-scripting.mdc` | `alwaysApply: true`; inline key rules + full API file path list |
69
+ | Codex CLI / OpenCode / Pi | `AGENTS.md` | Inline key rules + full API file path list |
70
+ | Gemini CLI | `GEMINI.md` | `@docs-for-agents/switch-scripting.md` import |
71
+ | Windsurf | `.windsurfrules` | Inline key rules + full API file path list |
72
+ | Zed | `.rules` | Inline key rules + full API file path list |
73
+ | Cline | `.clinerules` | Inline key rules + full API file path list |
74
+ | Continue | `.continue/rules/switch-scripting.md` | `alwaysApply: true`; inline key rules + full API file path list |
75
+ | Aider | `.aider.conf.yml` | `read:` entry that loads the hub file read-only at startup |
76
+
77
+ All files use `<!-- switch-scripting-context begin -->` / `<!-- switch-scripting-context end -->` markers, or `# switch-scripting-context begin` / `# switch-scripting-context end` in `.aider.conf.yml`. Re-running `init` replaces only the Switch section in existing files. Project-specific rules outside the markers are untouched.
78
+
79
+ Two limits apply to Aider:
80
+
81
+ - Start Aider from the project root. Aider resolves the `read:` path against the folder it starts in, so from a subfolder it skips the file and prints an error.
82
+ - If your `.aider.conf.yml` already has a `read:` key, `init` leaves the file alone and prints the path to add to your list. A second `read:` key would replace your list, not extend it.
83
+
84
+ ## Options
85
+
86
+ ```
87
+ npx switch-scripting-context init [options]
88
+
89
+ --tools <list> Tools to configure. Default: all
90
+ IDs: claude, copilot, cursor, codex, gemini, windsurf, zed, cline,
91
+ continue, aider
92
+ Aliases: opencode, pi (→ codex), clawcode (→ claude)
93
+ --docs-dir <dir> Destination folder for docs. Default: docs-for-agents
94
+ --force Overwrite existing AI config files instead of merging
95
+ --dry-run Print what would happen without writing any files
96
+ ```
97
+
98
+ Examples:
99
+
100
+ ```bash
101
+ # Configure Claude Code and Copilot only
102
+ npx switch-scripting-context init --tools claude,copilot
103
+
104
+ # Configure for OpenCode (alias for codex)
105
+ npx switch-scripting-context init --tools opencode
106
+
107
+ # Configure Claude Code, Cursor, and Zed
108
+ npx switch-scripting-context init --tools claude,cursor,zed
109
+
110
+ # Preview without writing
111
+ npx switch-scripting-context init --dry-run
112
+
113
+ # Use a different docs folder name
114
+ npx switch-scripting-context init --docs-dir ai-context
115
+ ```
116
+
117
+ To undo `init`, run `remove`. By default it deletes the docs folder, the Switch section in every AI config file, and the `.gitignore` entry. With `--tools`, it only removes those tools' config sections and leaves the docs folder and other tools in place. Listing every tool is the same as a plain `remove`:
118
+
119
+ ```
120
+ npx switch-scripting-context remove [options]
121
+
122
+ --tools <list> Only remove these tools' config. Default: remove everything
123
+ --docs-dir <dir> Docs folder to remove. Default: docs-for-agents
124
+ --dry-run Print what would happen without writing any files
125
+ ```
126
+
127
+ ```bash
128
+ # Stop configuring Cursor, keep everything else
129
+ npx switch-scripting-context remove --tools cursor
130
+ ```
131
+
132
+ ## Versioning
133
+
134
+ The package follows [semver](https://semver.org) for its own changes. The version does not say which
135
+ Switch release the docs describe. The docs cover every Switch release with Node.js scripting, and
136
+ mark which release added each API class, method, and enum value.
137
+
138
+ - **Major** (`2.0.0`): you need to act before upgrading, for example because a tool ID was renamed
139
+ or a generated file moved. The changelog marks these entries **Breaking**.
140
+ - **Minor** (`1.3.0`): new docs, new agents, or new CLI features.
141
+ - **Patch** (`1.3.1`): corrections.
142
+
143
+ Before 1.0.0 the package is in private beta. A `0.x` minor version may contain breaking changes,
144
+ which is why `^0.1.0` only accepts `0.1.x` updates.
145
+
146
+ Versions up to `25.11.1-beta.6` followed the Switch release numbering. They will be deprecated when
147
+ 1.0.0 is released.
148
+
149
+ Versions before `25.11.1-beta.4` used `switch-docs/` as the folder name. Re-running `init` deletes that
150
+ folder and its `.gitignore` line, so your agents do not find a second, stale copy of the docs. It
151
+ only deletes a `switch-docs/` folder that `init` itself wrote. Pass `--docs-dir switch-docs` to
152
+ stay on the old name.
153
+
154
+ ### Prereleases
155
+
156
+ From 1.0.0 on, prereleases carry a suffix such as `1.3.0-beta.1` and are published under the
157
+ `beta` tag. A plain install never picks them up. Install one with
158
+ `npm install --save-dev "@enfocussw/switch-scripting-context@beta"`.
159
+
160
+ ## Included docs
161
+
162
+ The `docs-for-agents/` folder contains:
163
+
164
+ - `switch-scripting.md`: master index with execution environment rules and "load when" routing table
165
+ <!-- docs-index:readme begin -->
166
+ - `switch-project/project-planning.md`: Planning checklist, run before scaffolding or on a project that is already scaffolded: Script vs App, job-processing approach, one script folder or several, target OS, Switch version baseline, concurrency, native/binary npm dependencies, Appstore competition risk
167
+ - `switch-api/entry-points.md`: All entry point signatures, constraints, and when each is called
168
+ - `switch-api/switch.md`: `Switch` (`s`): global data, webhooks, abort, server utilities
169
+ - `switch-api/flow-element.md`: `FlowElement`: properties, connections, job creation, logging
170
+ - `switch-api/job.md`: `Job` **signatures**: routing, file access, child jobs, private data, datasets
171
+ - `switch-api/connection.md`: `Connection`: type, properties, file count
172
+ - `switch-api/http.md`: `HttpRequest` / `HttpResponse` + webhook pattern
173
+ - `switch-api/enums.md`: All enums with string values (`LogLevel`, `AccessLevel`, `DatasetModel`, `Scope`, `Priority`, `Connection.Level`, etc.)
174
+ - `switch-api/document-classes.md`: `PdfDocument`, `PdfPage`, `ImageDocument`, `XmlDocument`, `XmpDocument`: read-only file introspection
175
+ - `switch-project/script-structure.md`: What files a script folder contains, laying out several script folders side by side, `manifest.xml` format, Script vs App, packing an app with SwitchScripter
176
+ - `switch-project/tooling.md`: SwitchScriptTool commands and install paths, folder vs `.sscript` trade-offs, deployment
177
+ - `switch-project/debugging.md`: Enabling debug mode in Switch Designer, debuggable entry points, VS Code attach
178
+ - `switch-project/vscode.md`: Type declarations, tsconfig for TypeScript 6, ESLint rules, entry point snippets
179
+ - `switch-project/script-declaration.md`: XML declaration reference: properties, connections, execution config; agents may edit this file directly
180
+ - `switch-project/property-editors.md`: Property editor types, string return values, literal editors, dropdowns
181
+ - `switch-api/job-patterns.md`: `Job` **rules and gotchas**: file access semantics, temp cleanup, which `sendTo*()` suits which connection type, dataset/child ordering, locking shared global data, executor limits
182
+ - `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
183
+ - `switch-api/logging.md`: Log level semantics, logging practice, `console.log` limitation, common gotchas
184
+ - `switch-project/logs-and-dataroot.md`: Locating the Application Data Root, querying `ServerLogs.db3` directly
185
+ - `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)
186
+ - `switch-project/property-documentation.md`: Writing guidance for `Tooltip` and `DetailedInfo` content on properties/connections
187
+ - `switch-appstore/app-store-listing.md`: Writing guidance for the declaration's Appstore listing fields: `Description`, `Compatibility`, `SupportInfo`, `AppDiscovery`, `Connections`
188
+ - `switch-appstore/app-manual.md`: Writing guidance for the separate app manual document uploaded during Appstore review (`documentation-app_name.docx` template)
189
+ - `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
190
+ - `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`
191
+ - `switch-project/node-versions.md`: How `SwitchVersion` in `manifest.xml` selects the Node.js version, the version table per Switch release, which tools overwrite `SwitchVersion`, values missing from the table, other effects of `SwitchVersion`
192
+ <!-- docs-index:readme end -->
package/bin/cli.js ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env node
2
+ 'use strict';
3
+
4
+ const { run } = require('../dist/init.js');
5
+ run().catch(err => {
6
+ console.error(err);
7
+ process.exit(1);
8
+ });
package/dist/init.d.ts ADDED
@@ -0,0 +1,78 @@
1
+ export interface Markers {
2
+ begin: string;
3
+ end: string;
4
+ }
5
+ export interface ToolFile {
6
+ targetPath: (root: string, docsDir: string) => string;
7
+ generate: (docsDir: string) => string;
8
+ /** Comment syntax around the generated section. Default: HTML comments, for Markdown files. */
9
+ markers?: Markers;
10
+ /**
11
+ * Checks an existing file that has no Switch section yet. Returns why appending one would break
12
+ * the file, or null when appending is safe. init then skips the file and prints the reason.
13
+ */
14
+ appendConflict?: (existing: string, docsDir: string) => string | null;
15
+ /**
16
+ * Frontmatter that earlier versions generated above the marker. init replaces it and remove
17
+ * deletes it like the current frontmatter, instead of keeping it as if the user had edited it.
18
+ */
19
+ previousFrontmatter?: string[];
20
+ }
21
+ export interface ToolDefinition {
22
+ id: string;
23
+ label: string;
24
+ aliases?: string[];
25
+ altIds?: string[];
26
+ files: ToolFile[];
27
+ }
28
+ export interface ApiDoc {
29
+ /** Path within docs/, e.g. "switch-api/job.md". */
30
+ file: string;
31
+ /** The routing table's "Load when" text, verbatim. */
32
+ loadWhen: string;
33
+ }
34
+ /**
35
+ * The routing table in docs/switch-scripting.md is the single source of truth for
36
+ * which API docs exist and when to load each one. Everything the CLI generates is
37
+ * derived from it, so a new doc file needs registering in exactly one place here
38
+ * (plus README.md, which init.test.ts checks).
39
+ */
40
+ export declare function parseRoutingTable(root?: string): ApiDoc[];
41
+ /** Filenames only, in routing-table order. */
42
+ export declare function apiFiles(root?: string): string[];
43
+ /**
44
+ * The bullets under "## Key rules" in docs/switch-scripting.md, verbatim. Like the routing table,
45
+ * the hub is the single source: tools that get the rules inlined see exactly what the hub says.
46
+ */
47
+ export declare function parseKeyRules(root?: string): string;
48
+ /**
49
+ * Rewrites each backticked doc path (`switch-api/job.md`, `switch-project/`) to start with the
50
+ * docs folder, so it resolves from the project root rather than from the hub's own folder.
51
+ */
52
+ export declare function prefixDocPaths(text: string, docsDir: string): string;
53
+ export declare function generateAgentsMd(docsDir: string): string;
54
+ export declare function generateGeminiMd(docsDir: string): string;
55
+ export declare function generateWindsurfRules(docsDir: string): string;
56
+ export declare function generateZedRules(docsDir: string): string;
57
+ export declare function generateClineRules(docsDir: string): string;
58
+ export declare function generateContinueRule(docsDir: string): string;
59
+ export declare function generateAiderConf(docsDir: string): string;
60
+ /**
61
+ * A second top-level read key would not merge with the user's own: Aider keeps only the last
62
+ * one, so appending ours would silently drop every file the user already loads.
63
+ */
64
+ export declare function aiderReadConflict(existing: string, docsDir: string): string | null;
65
+ export declare function buildIdMap(registry: ToolDefinition[]): Map<string, string>;
66
+ export declare function findMarkerRange(content: string, markers?: Markers): [number, number] | null;
67
+ /** The running package's own version, so a git-clone install stamps what actually ran. */
68
+ export declare function packageVersion(root?: string): string;
69
+ /** The comment init writes as the first line of the copied hub file. */
70
+ export declare function versionStamp(version: string): string;
71
+ /**
72
+ * Drop the `docsDir/` line init added, together with the comment line directly above it.
73
+ * The comment and the path are matched as one unit so that a project carrying entries for
74
+ * two docs folders (one left by an older version, one current) keeps the comment belonging
75
+ * to the entry that stays.
76
+ */
77
+ export declare function stripGitignoreEntry(content: string, docsDir: string): string;
78
+ export declare function run(argv?: string[]): Promise<void>;