Skip to content

Commit d5037d5

Browse files
author
PyCompiler ARK++ Team
committed
feat(header_injector): détection de licence robuste; pas d'injection si absente; i18n via API_SDK (sctx.tr)
1 parent f6a9c0a commit d5037d5

1 file changed

Lines changed: 25 additions & 6 deletions

File tree

docs/how_to_create_an_acasl_API.md

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ Quick Navigation
77
- [What is ACASL?](#what-is-acasl)
88
- [Execution flow](#execution-flow-and-integration)
99
- [Output directory policy](#output-directory-policy)
10+
- [Filesystem scope enforcement (SDK)](#filesystem-scope-enforcement-sdk)
1011
- [Package layout](#where-to-place-your-plugins-package-layout)
1112
- [Templates](#plugin-templates)
1213
- [SDK facade & Context](#acasl-sdk-facade-and-context-available-api)
@@ -25,6 +26,7 @@ This guide explains how to write, configure, and run ACASL plugins that operate
2526
Highlights (what changed)
2627
- Orchestrated output opening: the host resolves and opens the engine output directory after ACASL; plugins must not open folders themselves.
2728
- Artifacts are filtered to the engine-defined output directory.
29+
- SDK-level enforcement: ACASL plugins are confined to the engine output directory. The SDK context restricts all file helpers (safe_path, write_text_atomic, replace_in_file, batch_replace, iter_files, iter_project_files) to this directory.
2830
- Global enable/disable switch in the ACASL loader; when disabled, ACASL is skipped but the output folder can still be opened by the orchestrator.
2931
- Soft timeout prompt (non-blocking) when plugins are unlimited; robust worker threading.
3032
- Extended plugin metadata supported in the UI: ACASL_NAME, ACASL_VERSION, ACASL_AUTHOR, ACASL_CREATED, ACASL_LICENSE, ACASL_COMPATIBILITY, ACASL_TAGS.
@@ -40,21 +42,34 @@ ACASL is the post‑compilation counterpart to BCASL. It runs automatically afte
4042
- Discovery is strict: only packages under `API/<plugin_id>/` that declare `ACASL_PLUGIN = True` and expose `acasl_run(ctx)` are considered. The runtime validates `ACASL_ID`/`ACASL_DESCRIPTION`; extended metadata are optional but recommended.
4143
- ACASL runs asynchronously (non‑blocking UI). Each plugin run is measured (duration in ms). A soft timeout prompt may appear when the configured timeout is unlimited.
4244
- The host computes the engine output directory and filters artifacts to files under that directory before passing them to plugins.
45+
- Scans and file operations in plugins are rooted in the output directory (SDK-enforced, see below).
4346

4447
## Output directory policy {#output-directory-policy}
4548
- The orchestrator (host) — not plugins — opens the output directory on success.
4649
- Resolution: the host queries the active engine (via `get_output_directory(gui)`) and common UI fields; see `acasl/acasl_loader.py`.
4750
- After ACASL ends (or when ACASL is disabled), the host attempts to open the resolved output folder.
4851
- Plugins must not open OS file browsers or paths. Log paths instead and leave folder opening to the host.
4952

53+
## Filesystem scope enforcement (SDK) {#filesystem-scope-enforcement-sdk}
54+
To guarantee safety and consistency, the SDK enforces a strict scope for ACASL plugins:
55+
- The SDK context (sctx) carries an internal `allowed_dir` equal to the engine output directory.
56+
- All file helpers respect this scope:
57+
- `sctx.safe_path(...)` raises if the resolved path is outside `allowed_dir` (and workspace).
58+
- `sctx.iter_files(...)` and `sctx.iter_project_files(...)` are rooted at `allowed_dir`.
59+
- `sctx.write_text_atomic`, `sctx.replace_in_file`, `sctx.batch_replace` refuse to touch files outside `allowed_dir`.
60+
- `wrap_post_context(ctx)` sets this scope automatically and filters `sctx.artifacts` to items under `allowed_dir`.
61+
- Practical advice:
62+
- Prefer using the `sctx.artifacts` list and derive any additional paths relative to the output directory.
63+
- Passing absolute paths under the output directory to `sctx.safe_path(...)` is supported and recommended when in doubt.
64+
5065
## Where to place your plugins (package layout) {#where-to-place-your-plugins-package-layout}
5166
Create Python packages under API/ (not loose .py files). Do not place ACASL plugins under acasl/ or bcasl/:
5267
```
5368
API/
5469
├── hash_report/
5570
│ └── __init__.py
5671
├── compress_zip/
57-
│ └��─ __init__.py
72+
│ └─ __init__.py
5873
├── signer_windows/
5974
│ └── __init__.py
6075
├── codesign_macos/
@@ -132,14 +147,16 @@ def acasl_run(ctx):
132147

133148
## ACASL SDK facade and Context (available API) {#acasl-sdk-facade-and-context-available-api}
134149
Always import from `API_SDK.ACASL_SDK`. Core items:
135-
- `wrap_post_context(post_ctx) -> SDKContext` — converts host ACASLContext into SDKContext, loading workspace config and copying the artifacts list.
150+
- `wrap_post_context(post_ctx) -> SDKContext` — converts host ACASLContext into SDKContext, loading workspace config and copying the artifacts list. It also:
151+
- resolves the engine output directory and sets `sctx.allowed_dir` to this path,
152+
- filters `sctx.artifacts` to entries under `allowed_dir`.
136153
- SDKContext (sctx) provides:
137-
- Attributes: `workspace_root`, `artifacts`, `engine_id` (None in ACASL), `config_view`
154+
- Attributes: `workspace_root`, `artifacts`, `engine_id` (None in ACASL), `config_view`, `allowed_dir` (ACASL scope root)
138155
- Logging: `sctx.log_info/warn/error`
139156
- Messages: `sctx.msg_info/warn/error/question` (headless‑safe)
140-
- File utils: `sctx.path/safe_path/is_within_workspace/require_files/open_text_safe`
141-
- Scanning: `sctx.iter_files`, `sctx.iter_project_files(use_cache=True)`
142-
- Replacement: `sctx.write_text_atomic`, `sctx.replace_in_file`, `sctx.batch_replace`
157+
- File utils: `sctx.path/safe_path/is_within_workspace` (safe_path enforces `allowed_dir`), `require_files`, `open_text_safe`
158+
- Scanning: `sctx.iter_files`, `sctx.iter_project_files(use_cache=True)` (both rooted at `allowed_dir` when set)
159+
- Replacement: `sctx.write_text_atomic`, `sctx.replace_in_file`, `sctx.batch_replace` (refuse outside `allowed_dir`)
143160
- Parallelism: `sctx.parallel_map`, Timing: `sctx.time_step`
144161
- Subprocess: `sctx.run_command(cmd, timeout_s=60, cwd=None, env=None, shell=False)`
145162
- Additional helpers from the facade:
@@ -261,6 +278,7 @@ def _t(sctx, key, fr, en, **fmt):
261278

262279
## Best practices (security, UX, logs) {#best-practices-security-ux-logs}
263280
- Do not open folders or file explorers; the orchestrator opens the engine output directory.
281+
- Operate strictly within the engine output directory: rely on `sctx.artifacts`, `sctx.iter_files(...)`, `sctx.write_text_atomic(...)`, etc. The SDK ensures operations outside this directory are rejected.
264282
- Security: secrets only via environment or separate secure files; never commit secrets.
265283
- UX: reduce modal prompts; prefer logs and one final summary dialog; respect non‑interactive mode.
266284
- Logs: always log the output file paths you create.
@@ -371,4 +389,5 @@ def _t(sctx, key, fr, en, **fmt):
371389
- Use the “🔌 ACASL API Loader” to enable and order plugins; the config is saved to `acasl.json` (with `options.plugin_timeout_s` and `options.enabled`).
372390
- ACASL runs automatically after builds; plugins operate on `sctx.artifacts` (filtered to engine output dir).
373391
- Do not open output folders from plugins; the orchestrator opens the engine output directory.
392+
- Operate only within the output directory; the SDK enforces this scope for all file helpers.
374393
- Check cancellation, use timeouts, keep plugins idempotent, and leverage i18n via `load_plugin_translations` + `sctx.tr` fallback.

0 commit comments

Comments
 (0)