@zdreamer/forge 0.0.0-stage → 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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 ZDreamer
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,71 @@
1
- # Temporary Holding Version
1
+ # @zdreamer/forge
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
+ Provisional prototype of the Forge workspace application: a policy-loading
4
+ diagnostic, not a server or review UI. Executable: `forge`; public authoring
5
+ types: `@zdreamer/forge/workspace`. Licensed under [MIT](LICENSE).
6
+
7
+ The `0.x` policy contract is provisional. Breaking authoring or semantic changes
8
+ use a minor release with migration notes; exact-pin the application and use its
9
+ own policy types from the same installation. No separate policy-version field or
10
+ compatibility layer is provided. See [release operations](https://github.com/ZDreamer2/forge/blob/master/docs/releasing.md).
11
+
12
+ ## Develop
13
+
14
+ Use Node 24.21.0 (`.nvmrc`) and Corepack pnpm 11.15.1:
15
+
16
+ ```sh
17
+ corepack pnpm install --frozen-lockfile
18
+ corepack pnpm --config.verify-deps-before-run=error run check
19
+ corepack pnpm --config.verify-deps-before-run=error run build
20
+ corepack pnpm --config.verify-deps-before-run=error run test:workspace
21
+ ```
22
+
23
+ The independent installation uses published `@zdreamer/forge-ts-service@0.1.1`
24
+ presets, their exact-pinned tool peers, the seven-day third-party release-age
25
+ floor, and explicit SWC script permission. `.cache/pnpm` is the portable default;
26
+ a hosting checkout can override the store during installation.
27
+
28
+ `test:workspace` checks public types and the installed executable through an
29
+ isolated tarball consumer, without publishing or running install scripts. An
30
+ optional `workspace.ts` argument also checks a consuming project's policy.
31
+
32
+ ## Workspace authoring contract (provisional)
33
+
34
+ Projects can exact-pin Forge as a local development dependency:
35
+
36
+ ```sh
37
+ pnpm add --save-dev --save-exact @zdreamer/forge@0.1.0
38
+ ```
39
+
40
+ ```ts
41
+ import type { WorkspacePolicy } from '@zdreamer/forge/workspace';
42
+
43
+ export default {
44
+ repositories: [{ path: '.' }, { path: 'tools/optional-checkout' }],
45
+ codebasesForChange: () => [{ id: 'application', guidance: 'docs/code' }],
46
+ } satisfies WorkspacePolicy;
47
+ ```
48
+
49
+ Module lookup follows the workspace file's ancestors, not the executable's
50
+ installation. A global executable alone does not supply editor/typechecker
51
+ resolution. Keep the dependency in an installation above the workspace module;
52
+ an isolated installation beside that module is also sufficient.
53
+
54
+ The current diagnostic command loads a selected trusted module explicitly:
55
+
56
+ ```sh
57
+ forge inspect-workspace /absolute/path/workspace.ts . src/example.ts
58
+ # Optional last argument: previous path of a rename.
59
+ ```
60
+
61
+ Repository IDs use `.` for the main repo and normalized workspace-relative POSIX
62
+ paths for nested repos. Change paths are workspace-relative; legacy CLI changes
63
+ can include `../` paths when the main Git root lies above the workspace.
64
+ `codebasesForChange` resolves membership lexically, without requiring files to
65
+ exist, and includes both rename/copy sides. Several concrete codebases can share
66
+ guidance; membership does not imply verification.
67
+
68
+ Policy modules are trusted executable code, not sandboxed; installation does not
69
+ load them. Types do not validate callback results at runtime. See
70
+ [architecture](https://github.com/ZDreamer2/forge/blob/master/docs/architecture.md) for loading limits and repository resolution,
71
+ which the diagnostic does not invoke.
@@ -0,0 +1,5 @@
1
+ /** A lexical policy diagnostic; repository probes are explicit startup/reload work. */
2
+ export declare function inspect(modulePath: string, repo: string, path: string, from?: string): Promise<{
3
+ included: boolean;
4
+ codebases: readonly import("../components/workspace-policy/index.ts").CodebaseContext[];
5
+ }>;
@@ -0,0 +1,15 @@
1
+ import { resolve } from "node:path";
2
+ import { loadWorkspacePolicy } from "../components/workspace-policy/index.js";
3
+ /** A lexical policy diagnostic; repository probes are explicit startup/reload work. */
4
+ export async function inspect(modulePath, repo, path, from) {
5
+ const policy = await loadWorkspacePolicy(resolve(modulePath));
6
+ return {
7
+ included: policy.repositories.some((repository) => repository.path === repo),
8
+ codebases: policy.codebasesForChange({
9
+ repo,
10
+ path,
11
+ kind: from === undefined ? "modified" : "renamed",
12
+ ...(from === undefined ? {} : { from }),
13
+ }),
14
+ };
15
+ }
@@ -0,0 +1,3 @@
1
+ export { loadWorkspacePolicy } from "./internal/load.ts";
2
+ export { resolveRepositories } from "./internal/repositories.ts";
3
+ export type { CodebaseContext, RepositoryDeclaration, WorkspaceChange, WorkspacePolicy, } from "./internal/types.ts";
@@ -0,0 +1,2 @@
1
+ export { loadWorkspacePolicy } from "./internal/load.js";
2
+ export { resolveRepositories } from "./internal/repositories.js";
@@ -0,0 +1,3 @@
1
+ import type { WorkspacePolicy } from "./types.ts";
2
+ /** Imports execute trusted workspace code; this is not a sandbox or hot loader. */
3
+ export declare function loadWorkspacePolicy(absolutePath: string): Promise<WorkspacePolicy>;
@@ -0,0 +1,35 @@
1
+ var __rewriteRelativeImportExtension = (this && this.__rewriteRelativeImportExtension) || function (path, preserveJsx) {
2
+ if (typeof path === "string" && /^\.\.?\//.test(path)) {
3
+ return path.replace(/\.(tsx)$|((?:\.d)?)((?:\.[^./]+?)?)\.([cm]?)ts$/i, function (m, tsx, d, ext, cm) {
4
+ return tsx ? preserveJsx ? ".jsx" : ".js" : d && (!ext || !cm) ? m : (d + ext + "." + cm.toLowerCase() + "js");
5
+ });
6
+ }
7
+ return path;
8
+ };
9
+ import { pathToFileURL } from "node:url";
10
+ import { validRepositoryPath } from "./repositories.js";
11
+ /** Imports execute trusted workspace code; this is not a sandbox or hot loader. */
12
+ export async function loadWorkspacePolicy(absolutePath) {
13
+ const module = await import(__rewriteRelativeImportExtension(pathToFileURL(absolutePath).href));
14
+ const policy = module.default;
15
+ if (typeof policy !== "object" ||
16
+ policy === null ||
17
+ !("repositories" in policy) ||
18
+ !Array.isArray(policy.repositories) ||
19
+ !("codebasesForChange" in policy) ||
20
+ typeof policy.codebasesForChange !== "function") {
21
+ throw new TypeError("Workspace module must default-export a WorkspacePolicy");
22
+ }
23
+ const paths = new Set();
24
+ for (const repository of policy.repositories) {
25
+ if (typeof repository !== "object" ||
26
+ repository === null ||
27
+ typeof repository.path !== "string" ||
28
+ !validRepositoryPath(repository.path) ||
29
+ paths.has(repository.path)) {
30
+ throw new TypeError("Repository declarations need unique normalized workspace-relative paths");
31
+ }
32
+ paths.add(repository.path);
33
+ }
34
+ return policy;
35
+ }
@@ -0,0 +1,12 @@
1
+ import type { RepositoryDeclaration } from "./types.ts";
2
+ export declare function validRepositoryPath(path: string): boolean;
3
+ export type RepositoryResolution = {
4
+ readonly path: string;
5
+ readonly status: "available";
6
+ readonly gitRoot: string;
7
+ } | {
8
+ readonly path: string;
9
+ readonly status: "missing";
10
+ };
11
+ /** Explicit startup/reload probe, never a recursive scan or change-list poll. */
12
+ export declare function resolveRepositories(workspaceRoot: string, declarations: readonly RepositoryDeclaration[]): Promise<readonly RepositoryResolution[]>;
@@ -0,0 +1,52 @@
1
+ import { execFile } from "node:child_process";
2
+ import { realpath, stat } from "node:fs/promises";
3
+ import { isAbsolute, relative, resolve, sep } from "node:path";
4
+ import { promisify } from "node:util";
5
+ const execute = promisify(execFile);
6
+ export function validRepositoryPath(path) {
7
+ return (path === "." ||
8
+ (path.length > 0 &&
9
+ !path.includes("\\") &&
10
+ !path.includes(":") &&
11
+ !path.includes("\0") &&
12
+ path.split("/").every((part) => part !== "" && part !== "." && part !== "..")));
13
+ }
14
+ /** Explicit startup/reload probe, never a recursive scan or change-list poll. */
15
+ export async function resolveRepositories(workspaceRoot, declarations) {
16
+ const root = await realpath(workspaceRoot);
17
+ const results = [];
18
+ const seen = new Set();
19
+ for (const declaration of declarations) {
20
+ const path = declaration.path;
21
+ if (!validRepositoryPath(path) || seen.has(path)) {
22
+ throw new TypeError("Repository declarations need unique normalized workspace-relative paths");
23
+ }
24
+ seen.add(path);
25
+ const location = resolve(root, path);
26
+ try {
27
+ if (!(await stat(location)).isDirectory()) {
28
+ throw new Error(`Declared repository is not a directory: ${path}`);
29
+ }
30
+ }
31
+ catch (error) {
32
+ if (error instanceof Error && "code" in error && error.code === "ENOENT") {
33
+ results.push({ path, status: "missing" });
34
+ continue;
35
+ }
36
+ throw error;
37
+ }
38
+ const directory = await realpath(location);
39
+ const within = relative(root, directory);
40
+ if (isAbsolute(within) || within === ".." || within.startsWith(`..${sep}`)) {
41
+ throw new Error(`Declared repository escapes workspace root: ${path}`);
42
+ }
43
+ const { stdout } = await execute("git", ["-C", directory, "rev-parse", "--show-toplevel"]);
44
+ const gitRoot = await realpath(stdout.trim());
45
+ // '.' intentionally permits a Git root above the selected workspace.
46
+ if (path !== "." && gitRoot !== directory) {
47
+ throw new Error(`Declared nested repository resolves to another Git root: ${path}`);
48
+ }
49
+ results.push({ path, status: "available", gitRoot });
50
+ }
51
+ return results;
52
+ }
@@ -0,0 +1,25 @@
1
+ /** Paths use '/' and are workspace-relative; '.' identifies the main repository. */
2
+ export interface RepositoryDeclaration {
3
+ readonly path: string;
4
+ }
5
+ export interface WorkspaceChange {
6
+ readonly repo: string;
7
+ readonly path: string;
8
+ readonly kind: "added" | "modified" | "deleted" | "renamed" | "copied" | "type_changed";
9
+ readonly from?: string;
10
+ }
11
+ /** Identity is concrete; several codebases may share the same guidance folder. */
12
+ export interface CodebaseContext {
13
+ readonly id: string;
14
+ readonly guidance: string;
15
+ }
16
+ /**
17
+ * Trusted project code, called explicitly after loading. Forge probes only
18
+ * declared repositories; missing locations are skipped, not configuration errors.
19
+ * Routing is synchronous, side-effect-free and must handle absent
20
+ * files lexically. Rename/copy membership includes both old and new paths.
21
+ */
22
+ export interface WorkspacePolicy {
23
+ readonly repositories: readonly RepositoryDeclaration[];
24
+ codebasesForChange(change: WorkspaceChange): readonly CodebaseContext[];
25
+ }
@@ -0,0 +1 @@
1
+ export {};
package/dist/main.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
package/dist/main.js ADDED
@@ -0,0 +1,23 @@
1
+ #!/usr/bin/env node
2
+ import { inspect } from "./app/inspect.js";
3
+ const [command, modulePath, repo, path, from, ...extra] = process.argv.slice(2);
4
+ if (command === "--help" || command === undefined) {
5
+ console.log("forge inspect-workspace <workspace.ts> <repository> <path> [previous-path]");
6
+ }
7
+ else if (command !== "inspect-workspace" ||
8
+ modulePath === undefined ||
9
+ repo === undefined ||
10
+ path === undefined ||
11
+ extra.length > 0) {
12
+ console.error("Usage: forge inspect-workspace <workspace.ts> <repository> <path> [previous-path]");
13
+ process.exitCode = 1;
14
+ }
15
+ else {
16
+ try {
17
+ console.log(JSON.stringify(await inspect(modulePath, repo, path, from)));
18
+ }
19
+ catch (error) {
20
+ console.error(error instanceof Error ? error.message : String(error));
21
+ process.exitCode = 1;
22
+ }
23
+ }
@@ -0,0 +1 @@
1
+ export type { CodebaseContext, RepositoryDeclaration, WorkspaceChange, WorkspacePolicy, } from "./components/workspace-policy/index.ts";
@@ -0,0 +1 @@
1
+ export {};
package/package.json CHANGED
@@ -1,6 +1,45 @@
1
1
  {
2
- "name": "@zdreamer/forge",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
2
+ "name": "@zdreamer/forge",
3
+ "version": "0.1.0",
4
+ "description": "Forge workspace application and typed workspace policy contract",
5
+ "license": "MIT",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/ZDreamer2/forge.git"
9
+ },
10
+ "homepage": "https://github.com/ZDreamer2/forge#readme",
11
+ "bugs": "https://github.com/ZDreamer2/forge/issues",
12
+ "type": "module",
13
+ "publishConfig": {
14
+ "access": "public"
15
+ },
16
+ "files": [
17
+ "dist/"
18
+ ],
19
+ "bin": {
20
+ "forge": "./dist/main.js"
21
+ },
22
+ "exports": {
23
+ "./workspace": {
24
+ "types": "./dist/workspace.d.ts",
25
+ "default": "./dist/workspace.js"
26
+ }
27
+ },
28
+ "engines": {
29
+ "node": ">=24.18.1 <25"
30
+ },
31
+ "packageManager": "pnpm@11.15.1",
32
+ "scripts": {
33
+ "build": "node --input-type=module -e \"import { rmSync } from 'node:fs'; rmSync('dist', { recursive: true, force: true })\" && tsc -p tsconfig.build.json",
34
+ "check": "tsc --noEmit && biome check . && depcruise --config .dependency-cruiser.mjs 'src/**/*.ts' && node --test",
35
+ "test:workspace": "node tools/workspace-consumer.ts"
36
+ },
37
+ "devDependencies": {
38
+ "@biomejs/biome": "2.5.7",
39
+ "@swc/core": "1.16.1",
40
+ "@types/node": "24.13.3",
41
+ "@zdreamer/forge-ts-service": "0.1.1",
42
+ "dependency-cruiser": "18.2.0",
43
+ "typescript": "7.0.2"
44
+ }
45
+ }