@dual-os/cli 0.0.0-stage → 0.11.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 +4 -0
- package/README.md +15 -2
- package/dist/_virtual/_rolldown/runtime.js +13 -0
- package/dist/auth/credentials.d.ts +17 -0
- package/dist/auth/credentials.d.ts.map +1 -0
- package/dist/auth/credentials.js +57 -0
- package/dist/auth/credentials.js.map +1 -0
- package/dist/auth/destination.d.ts +22 -0
- package/dist/auth/destination.d.ts.map +1 -0
- package/dist/auth/destination.js +49 -0
- package/dist/auth/destination.js.map +1 -0
- package/dist/auth/http.d.ts +12 -0
- package/dist/auth/http.d.ts.map +1 -0
- package/dist/auth/http.js +34 -0
- package/dist/auth/http.js.map +1 -0
- package/dist/auth/login.d.ts +22 -0
- package/dist/auth/login.d.ts.map +1 -0
- package/dist/auth/login.js +98 -0
- package/dist/auth/login.js.map +1 -0
- package/dist/auth/protocol.d.ts +26 -0
- package/dist/auth/protocol.d.ts.map +1 -0
- package/dist/auth/protocol.js +31 -0
- package/dist/auth/protocol.js.map +1 -0
- package/dist/baseline.d.ts +18 -0
- package/dist/baseline.d.ts.map +1 -0
- package/dist/baseline.js +22 -0
- package/dist/baseline.js.map +1 -0
- package/dist/bin.d.ts +1 -0
- package/dist/bin.js +7 -0
- package/dist/bin.js.map +1 -0
- package/dist/cli.d.ts +19 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +492 -0
- package/dist/cli.js.map +1 -0
- package/dist/create/choices.d.ts +58 -0
- package/dist/create/choices.d.ts.map +1 -0
- package/dist/create/choices.js +121 -0
- package/dist/create/choices.js.map +1 -0
- package/dist/create/deployment.d.ts +48 -0
- package/dist/create/deployment.d.ts.map +1 -0
- package/dist/create/deployment.js +66 -0
- package/dist/create/deployment.js.map +1 -0
- package/dist/create/scaffold.d.ts +57 -0
- package/dist/create/scaffold.d.ts.map +1 -0
- package/dist/create/scaffold.js +198 -0
- package/dist/create/scaffold.js.map +1 -0
- package/dist/create/source-reference.d.ts +39 -0
- package/dist/create/source-reference.d.ts.map +1 -0
- package/dist/create/source-reference.js +185 -0
- package/dist/create/source-reference.js.map +1 -0
- package/dist/create/template.d.ts +116 -0
- package/dist/create/template.d.ts.map +1 -0
- package/dist/create/template.js +211 -0
- package/dist/create/template.js.map +1 -0
- package/dist/diagnostics.d.ts +6 -0
- package/dist/diagnostics.d.ts.map +1 -0
- package/dist/diagnostics.js +18 -0
- package/dist/diagnostics.js.map +1 -0
- package/dist/help.d.ts +16 -0
- package/dist/help.d.ts.map +1 -0
- package/dist/help.js +73 -0
- package/dist/help.js.map +1 -0
- package/dist/openapi/bundle.d.ts +18 -0
- package/dist/openapi/bundle.d.ts.map +1 -0
- package/dist/openapi/bundle.js +201 -0
- package/dist/openapi/bundle.js.map +1 -0
- package/dist/openapi/discovery.d.ts +30 -0
- package/dist/openapi/discovery.d.ts.map +1 -0
- package/dist/openapi/discovery.js +325 -0
- package/dist/openapi/discovery.js.map +1 -0
- package/dist/openapi/emit.d.ts +52 -0
- package/dist/openapi/emit.d.ts.map +1 -0
- package/dist/openapi/emit.js +596 -0
- package/dist/openapi/emit.js.map +1 -0
- package/dist/openapi/graphql.d.ts +102 -0
- package/dist/openapi/graphql.d.ts.map +1 -0
- package/dist/openapi/graphql.js +294 -0
- package/dist/openapi/graphql.js.map +1 -0
- package/dist/openapi/identity.d.ts +88 -0
- package/dist/openapi/identity.d.ts.map +1 -0
- package/dist/openapi/identity.js +98 -0
- package/dist/openapi/identity.js.map +1 -0
- package/dist/openapi/mcp.d.ts +21 -0
- package/dist/openapi/mcp.d.ts.map +1 -0
- package/dist/openapi/mcp.js +133 -0
- package/dist/openapi/mcp.js.map +1 -0
- package/dist/openapi/operations.d.ts +165 -0
- package/dist/openapi/operations.d.ts.map +1 -0
- package/dist/openapi/operations.js +361 -0
- package/dist/openapi/operations.js.map +1 -0
- package/dist/openapi/overlay.d.ts +23 -0
- package/dist/openapi/overlay.d.ts.map +1 -0
- package/dist/openapi/overlay.js +115 -0
- package/dist/openapi/overlay.js.map +1 -0
- package/dist/openapi/plugin.d.ts +83 -0
- package/dist/openapi/plugin.d.ts.map +1 -0
- package/dist/openapi/plugin.js +468 -0
- package/dist/openapi/plugin.js.map +1 -0
- package/dist/openapi/polymorphism.d.ts +21 -0
- package/dist/openapi/polymorphism.d.ts.map +1 -0
- package/dist/openapi/polymorphism.js +96 -0
- package/dist/openapi/polymorphism.js.map +1 -0
- package/dist/openapi/postman.d.ts +21 -0
- package/dist/openapi/postman.d.ts.map +1 -0
- package/dist/openapi/postman.js +286 -0
- package/dist/openapi/postman.js.map +1 -0
- package/dist/openapi/schema.d.ts +178 -0
- package/dist/openapi/schema.d.ts.map +1 -0
- package/dist/openapi/schema.js +1234 -0
- package/dist/openapi/schema.js.map +1 -0
- package/dist/openapi/select.d.ts +22 -0
- package/dist/openapi/select.d.ts.map +1 -0
- package/dist/openapi/select.js +79 -0
- package/dist/openapi/select.js.map +1 -0
- package/dist/openapi/spec.d.ts +147 -0
- package/dist/openapi/spec.d.ts.map +1 -0
- package/dist/openapi/spec.js +263 -0
- package/dist/openapi/spec.js.map +1 -0
- package/dist/openapi/swagger.d.ts +166 -0
- package/dist/openapi/swagger.d.ts.map +1 -0
- package/dist/openapi/swagger.js +298 -0
- package/dist/openapi/swagger.js.map +1 -0
- package/dist/openapi/versions.d.ts +52 -0
- package/dist/openapi/versions.d.ts.map +1 -0
- package/dist/openapi/versions.js +120 -0
- package/dist/openapi/versions.js.map +1 -0
- package/dist/plugin/archive.d.ts +27 -0
- package/dist/plugin/archive.d.ts.map +1 -0
- package/dist/plugin/archive.js +170 -0
- package/dist/plugin/archive.js.map +1 -0
- package/dist/plugin/bundle.d.ts +27 -0
- package/dist/plugin/bundle.d.ts.map +1 -0
- package/dist/plugin/bundle.js +328 -0
- package/dist/plugin/bundle.js.map +1 -0
- package/dist/plugin/init.d.ts +18 -0
- package/dist/plugin/init.d.ts.map +1 -0
- package/dist/plugin/init.js +121 -0
- package/dist/plugin/init.js.map +1 -0
- package/dist/plugin/inspection.d.ts +24 -0
- package/dist/plugin/inspection.d.ts.map +1 -0
- package/dist/plugin/inspection.js +24 -0
- package/dist/plugin/inspection.js.map +1 -0
- package/dist/plugin/package.d.ts +26 -0
- package/dist/plugin/package.d.ts.map +1 -0
- package/dist/plugin/package.js +73 -0
- package/dist/plugin/package.js.map +1 -0
- package/dist/plugin/publication.d.ts +29 -0
- package/dist/plugin/publication.d.ts.map +1 -0
- package/dist/plugin/publication.js +65 -0
- package/dist/plugin/publication.js.map +1 -0
- package/dist/plugin/validation.d.ts +15 -0
- package/dist/plugin/validation.d.ts.map +1 -0
- package/dist/plugin/validation.js +119 -0
- package/dist/plugin/validation.js.map +1 -0
- package/dist/release/archives.d.ts +33 -0
- package/dist/release/archives.d.ts.map +1 -0
- package/dist/release/archives.js +81 -0
- package/dist/release/archives.js.map +1 -0
- package/dist/release/release-manifest.d.ts +182 -0
- package/dist/release/release-manifest.d.ts.map +1 -0
- package/dist/release/release-manifest.js +79 -0
- package/dist/release/release-manifest.js.map +1 -0
- package/dist/release/releases.d.ts +36 -0
- package/dist/release/releases.d.ts.map +1 -0
- package/dist/release/releases.js +122 -0
- package/dist/release/releases.js.map +1 -0
- package/dist/skills.d.ts +35 -0
- package/dist/skills.d.ts.map +1 -0
- package/dist/skills.js +257 -0
- package/dist/skills.js.map +1 -0
- package/package.json +73 -4
- package/skills/dual-fde/SKILL.md +38 -0
- package/skills/dual-fde/references/access.md +62 -0
- package/skills/dual-fde/references/author-plugins.md +54 -0
- package/skills/dual-fde/references/cli.md +97 -0
- package/skills/dual-fde/references/manage-plugins.md +78 -0
- package/skills/dual-fde/references/migrations-deployment.md +84 -0
- package/skills/dual-fde/references/openapi-plugins.md +47 -0
- package/skills/dual-fde/references/sdk-docs.md +56 -0
- package/skills/dual-fde/references/upgrades.md +115 -0
- package/skills/dual-fde/references/working-context.md +69 -0
- package/src/auth/credentials.ts +84 -0
- package/src/auth/destination.ts +83 -0
- package/src/auth/http.ts +39 -0
- package/src/auth/login.ts +177 -0
- package/src/auth/protocol.ts +37 -0
- package/src/baseline.ts +15 -0
- package/src/bin.ts +4 -0
- package/src/cli.ts +969 -0
- package/src/create/choices.ts +177 -0
- package/src/create/deployment.ts +96 -0
- package/src/create/scaffold.ts +334 -0
- package/src/create/source-reference.ts +212 -0
- package/src/create/template.ts +300 -0
- package/src/diagnostics.ts +8 -0
- package/src/help.ts +142 -0
- package/src/openapi/bundle.ts +290 -0
- package/src/openapi/discovery.ts +438 -0
- package/src/openapi/emit.ts +1031 -0
- package/src/openapi/graphql.ts +375 -0
- package/src/openapi/identity.ts +153 -0
- package/src/openapi/mcp.ts +165 -0
- package/src/openapi/operations.ts +781 -0
- package/src/openapi/overlay.ts +195 -0
- package/src/openapi/plugin.ts +856 -0
- package/src/openapi/polymorphism.ts +207 -0
- package/src/openapi/postman.ts +403 -0
- package/src/openapi/schema.ts +2138 -0
- package/src/openapi/select.ts +113 -0
- package/src/openapi/spec.ts +401 -0
- package/src/openapi/swagger.ts +422 -0
- package/src/openapi/versions.ts +174 -0
- package/src/plugin/archive.ts +244 -0
- package/src/plugin/bundle.ts +572 -0
- package/src/plugin/init.ts +178 -0
- package/src/plugin/inspection.ts +19 -0
- package/src/plugin/package.ts +140 -0
- package/src/plugin/publication.ts +128 -0
- package/src/plugin/validation.ts +213 -0
- package/src/release/archives.ts +133 -0
- package/src/release/release-manifest.ts +79 -0
- package/src/release/releases.ts +210 -0
- package/src/skills.ts +434 -0
- package/templates/compose/.env.compose.example.hbs +3 -0
- package/templates/compose/.env.host.example.hbs +4 -0
- package/templates/compose/Dockerfile.hbs +12 -0
- package/templates/compose/OPERATIONS.md.hbs +159 -0
- package/templates/compose/_dockerignore +14 -0
- package/templates/compose/compose.external.yaml +7 -0
- package/templates/compose/compose.host-linux.yaml +5 -0
- package/templates/compose/compose.host.yaml.hbs +15 -0
- package/templates/compose/compose.yaml.hbs +85 -0
- package/templates/compose/release.env.hbs +2 -0
- package/templates/default/.env.example.hbs +79 -0
- package/templates/default/README.md.hbs +150 -0
- package/templates/default/_gitignore +11 -0
- package/templates/default/packages/customer-plugin/src/Customer.ts.hbs +17 -0
- package/templates/default/packages/customer-plugin/tsconfig.json +15 -0
- package/templates/default/packages/execution-layer/src/App.ts.hbs +7 -0
- package/templates/default/packages/execution-layer/src/Host.ts.hbs +31 -0
- package/templates/default/packages/execution-layer/src/Telemetry.ts.hbs +23 -0
- package/templates/default/packages/execution-layer/src/api.ts.hbs +21 -0
- package/templates/default/packages/execution-layer/src/bootstrap.ts +22 -0
- package/templates/default/packages/execution-layer/src/migrate.ts +11 -0
- package/templates/default/packages/execution-layer/src/registry-check.ts +29 -0
- package/templates/default/packages/execution-layer/src/registry-sync.ts +14 -0
- package/templates/default/packages/execution-layer/src/worker.ts.hbs +16 -0
- package/templates/default/packages/execution-layer/test/app.host-test.ts.hbs +58 -0
- package/templates/default/packages/execution-layer/test/app.test.ts.hbs +16 -0
- package/templates/default/tsconfig.json +5 -0
- package/templates/default/vitest.config.ts +5 -0
- package/templates/default/vitest.host.config.ts +6 -0
- package/templates/opensandbox/OPEN-SANDBOX.md +25 -0
- package/templates/opensandbox/docker/agent-sandbox.Dockerfile +41 -0
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
# Working context
|
|
2
|
+
|
|
3
|
+
## Establish the task
|
|
4
|
+
|
|
5
|
+
1. Inspect repository instructions, manifests, resolved native lockfile, generation
|
|
6
|
+
record, relevant scripts and dirty changes. Identify the customer workspace,
|
|
7
|
+
requested outcome and target environment from available evidence. Inspect
|
|
8
|
+
configuration names and redacted status rather than secret values.
|
|
9
|
+
**Done:** repository, affected files, known versions and unresolved choices are
|
|
10
|
+
identified; ask only questions that would change the requested work.
|
|
11
|
+
2. Resolve installed-version documentation and, for adoption, target-version
|
|
12
|
+
documentation using [SDK and host documentation](sdk-docs.md). Use actual
|
|
13
|
+
artifacts/help to establish availability. Jira decisions explain intent; an
|
|
14
|
+
unmerged implementation, workspace example or registry upload is not a completed
|
|
15
|
+
release. **Done:** each proposed command/API has a matching supported reference,
|
|
16
|
+
or the unsupported step is explicitly blocked while safe inspection continues.
|
|
17
|
+
3. Take the relevant task branch. Return task-appropriate changes, explanation or
|
|
18
|
+
diagnosis, with commands/check outcomes, skipped checks and remaining blockers.
|
|
19
|
+
**Done:** distinguish implemented, locally tested, integration-tested and
|
|
20
|
+
operationally verified results; generation alone proves none of the later stages.
|
|
21
|
+
|
|
22
|
+
## Version identity
|
|
23
|
+
|
|
24
|
+
Keep these identities separate in inspection and review:
|
|
25
|
+
|
|
26
|
+
| Identity | Meaning |
|
|
27
|
+
| ------------------------------------------ | -------------------------------------------------------------------------------------------------------------------------------- |
|
|
28
|
+
| npm package versions and SDK/Effect peers | Installed code and declared dependency compatibility; packages release independently |
|
|
29
|
+
| Logical plugin and action/trigger versions | Plugin selections and exact capability contracts; each plugin defines its own version order |
|
|
30
|
+
| Release selection | Complete manifest plus downloaded-archive integrity: exact pins, available plugins, CLI/template compatibility and accepted pair |
|
|
31
|
+
| Core/web pair | Exact runtime core plus an independently released, tested immutable frontend image; may be reused by a compatible later manifest |
|
|
32
|
+
| CLI/template and skill version | Tooling and instruction snapshot, not proof of installed or target runtime versions |
|
|
33
|
+
| Source/reference pins | Documentation/source snapshots which can differ from all installed artifacts |
|
|
34
|
+
|
|
35
|
+
For plugin selection consult [manage plugins](manage-plugins.md); for release
|
|
36
|
+
selection and pairing consult [upgrades](upgrades.md).
|
|
37
|
+
|
|
38
|
+
## Authorization and preservation
|
|
39
|
+
|
|
40
|
+
- Proactively perform local read-only inspection and safe, credential-suppressed
|
|
41
|
+
access checks. Requested local work permits scoped edits and isolated tests;
|
|
42
|
+
upgrades require the target/plan approval in [upgrades](upgrades.md) first.
|
|
43
|
+
- Inspect install lifecycle hooks, scripts, environment loading and test targets
|
|
44
|
+
before execution. A `test` label or new repository does not establish isolation.
|
|
45
|
+
Use synthetic inputs and verified disposable resources with an owner and cleanup
|
|
46
|
+
plan. Obtain explicit approval before starting services or provisioning a test
|
|
47
|
+
database; local edits never silently imply Compose or database startup.
|
|
48
|
+
- Require explicit authorization naming the **environment and operation** for
|
|
49
|
+
shared/customer database access (including read-only registry plan/check), SQL
|
|
50
|
+
migrations, registry writes, bootstrap, provisioning, deployment or credential
|
|
51
|
+
changes. A staging approval is not production approval. Access is not consent;
|
|
52
|
+
consent does not remove compatibility blockers. Reuse an existing authorization
|
|
53
|
+
while its named target and operations remain in scope; ask again when they change.
|
|
54
|
+
- Inspect the full Compose dependency graph: startup can run migrate, registry-sync
|
|
55
|
+
and bootstrap jobs. Present those effects before seeking approval. Continue local
|
|
56
|
+
diagnosis when operational approval is absent; use supplied redacted reports.
|
|
57
|
+
- Preserve dirty customer work, host customizations and identities. Make targeted
|
|
58
|
+
edits; use CLI generation only in an absent/empty destination. Escalate conflicts
|
|
59
|
+
whose ownership is unclear. Peer widening, force synchronization, identity
|
|
60
|
+
changes and credential transitions require separately reviewed decisions, not
|
|
61
|
+
silent installation or compatibility fixes.
|
|
62
|
+
- Keep secrets outside chat, Git, replay records and images. Use the approved
|
|
63
|
+
external setup/handoff rather than collecting credentials. Customer-data
|
|
64
|
+
migration and publication are separately scoped work, never upgrade side effects.
|
|
65
|
+
- Follow the host's browser/computer-test delegation policy. Where it requires a
|
|
66
|
+
Codex subagent, delegate rather than bypass it. If that capability is unavailable,
|
|
67
|
+
report browser verification as pending and provide a scoped handoff; installing
|
|
68
|
+
another agent is not implicit. A status icon, screenshot or unit test cannot
|
|
69
|
+
certify deployment.
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { homedir } from "node:os";
|
|
2
|
+
|
|
3
|
+
import { Config, Context, Effect, FileSystem, Layer, Path, Redacted, Schema, pipe } from "effect";
|
|
4
|
+
|
|
5
|
+
import { Digest } from "effect/crypto";
|
|
6
|
+
import { Base64Url } from "effect/encoding";
|
|
7
|
+
|
|
8
|
+
import { AuthProtocol } from "./protocol.ts";
|
|
9
|
+
|
|
10
|
+
export type Interface = {
|
|
11
|
+
readonly get: (
|
|
12
|
+
deployment: string,
|
|
13
|
+
) => Effect.Effect<Redacted.Redacted<AuthProtocol.Credential>, AuthProtocol.AuthError>;
|
|
14
|
+
readonly set: (
|
|
15
|
+
deployment: string,
|
|
16
|
+
credential: Redacted.Redacted<AuthProtocol.Credential>,
|
|
17
|
+
) => Effect.Effect<void, AuthProtocol.AuthError>;
|
|
18
|
+
readonly remove: (deployment: string) => Effect.Effect<void, AuthProtocol.AuthError>;
|
|
19
|
+
};
|
|
20
|
+
export class Service extends Context.Service<Service, Interface>()(
|
|
21
|
+
"@dual-os/cli/auth/credentials/Service",
|
|
22
|
+
) {}
|
|
23
|
+
export const layer = Layer.effect(
|
|
24
|
+
Service,
|
|
25
|
+
Effect.gen(function* () {
|
|
26
|
+
const fs = yield* FileSystem.FileSystem;
|
|
27
|
+
const path = yield* Path.Path;
|
|
28
|
+
const crypto = yield* Digest.Digest;
|
|
29
|
+
const directory = path.join(
|
|
30
|
+
yield* pipe(Config.String("HOME"), Config.withDefault(homedir())),
|
|
31
|
+
".config",
|
|
32
|
+
"dual",
|
|
33
|
+
"credentials",
|
|
34
|
+
);
|
|
35
|
+
const location = Effect.fnUntraced(function* (deployment: string) {
|
|
36
|
+
const origin = new URL(yield* Schema.decodeEffect(AuthProtocol.DeploymentUrl)(deployment))
|
|
37
|
+
.origin;
|
|
38
|
+
return path.join(
|
|
39
|
+
directory,
|
|
40
|
+
`${Base64Url.encode(yield* crypto.digest(Digest.sha256, new TextEncoder().encode(origin)))}.json`,
|
|
41
|
+
);
|
|
42
|
+
});
|
|
43
|
+
const mapError = Effect.mapError(cause =>
|
|
44
|
+
AuthProtocol.AuthError.make({
|
|
45
|
+
cause: Redacted.make(cause),
|
|
46
|
+
message:
|
|
47
|
+
"Cannot access the saved CLI credential. Check file permissions or run dual login --web again.",
|
|
48
|
+
}),
|
|
49
|
+
);
|
|
50
|
+
return Service.of({
|
|
51
|
+
get: Effect.fn("CliCredentials.get")(function* (deployment) {
|
|
52
|
+
return Redacted.make(
|
|
53
|
+
yield* Schema.decodeEffect(Schema.fromJsonString(AuthProtocol.Credential))(
|
|
54
|
+
yield* fs.readFileString(yield* location(deployment)),
|
|
55
|
+
),
|
|
56
|
+
);
|
|
57
|
+
}, mapError),
|
|
58
|
+
remove: Effect.fn("CliCredentials.remove")(function* (deployment) {
|
|
59
|
+
yield* fs.remove(yield* location(deployment));
|
|
60
|
+
}, mapError),
|
|
61
|
+
set: Effect.fn("CliCredentials.set")(
|
|
62
|
+
function* (deployment, credential) {
|
|
63
|
+
const file = yield* location(deployment);
|
|
64
|
+
const value = yield* Schema.encodeEffect(
|
|
65
|
+
Schema.fromJsonString(AuthProtocol.Credential, { space: 2 }),
|
|
66
|
+
)(Redacted.value(credential));
|
|
67
|
+
yield* fs.makeDirectory(directory, { mode: 0o700, recursive: true });
|
|
68
|
+
yield* fs.chmod(directory, 0o700);
|
|
69
|
+
// A private sibling keeps interrupted writes from corrupting an existing login.
|
|
70
|
+
const temporary = path.join(
|
|
71
|
+
yield* fs.makeTempDirectoryScoped({ directory, prefix: ".login-" }),
|
|
72
|
+
"credential.json",
|
|
73
|
+
);
|
|
74
|
+
yield* fs.writeFileString(temporary, `${value}\n`, { flag: "wx", mode: 0o600 });
|
|
75
|
+
yield* fs.rename(temporary, file);
|
|
76
|
+
},
|
|
77
|
+
Effect.uninterruptible,
|
|
78
|
+
Effect.scoped,
|
|
79
|
+
mapError,
|
|
80
|
+
),
|
|
81
|
+
});
|
|
82
|
+
}),
|
|
83
|
+
);
|
|
84
|
+
export * as CliCredentials from "./credentials.ts";
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { homedir } from "node:os";
|
|
2
|
+
|
|
3
|
+
import { Config, Context, Effect, FileSystem, Layer, Option, Path, Schema, pipe } from "effect";
|
|
4
|
+
|
|
5
|
+
import { AuthProtocol } from "./protocol.ts";
|
|
6
|
+
|
|
7
|
+
export type Target = typeof Target.Type;
|
|
8
|
+
export const Target = Schema.Struct({
|
|
9
|
+
deployment: AuthProtocol.DeploymentUrl,
|
|
10
|
+
organizationId: Schema.NonEmptyString,
|
|
11
|
+
});
|
|
12
|
+
export type Interface = {
|
|
13
|
+
readonly defaultDeployment: Effect.Effect<Option.Option<string>, AuthProtocol.AuthError>;
|
|
14
|
+
readonly saveDefault: (deployment: string) => Effect.Effect<void, AuthProtocol.AuthError>;
|
|
15
|
+
readonly read: (
|
|
16
|
+
directory: string,
|
|
17
|
+
) => Effect.Effect<Option.Option<Target>, AuthProtocol.AuthError>;
|
|
18
|
+
readonly save: (directory: string, target: Target) => Effect.Effect<void, AuthProtocol.AuthError>;
|
|
19
|
+
};
|
|
20
|
+
export class Service extends Context.Service<Service, Interface>()(
|
|
21
|
+
"@dual-os/cli/auth/destination/Service",
|
|
22
|
+
) {}
|
|
23
|
+
export const layer = Layer.effect(
|
|
24
|
+
Service,
|
|
25
|
+
Effect.gen(function* () {
|
|
26
|
+
const fs = yield* FileSystem.FileSystem;
|
|
27
|
+
const path = yield* Path.Path;
|
|
28
|
+
const file = path.join(
|
|
29
|
+
yield* pipe(Config.String("HOME"), Config.withDefault(homedir())),
|
|
30
|
+
".config",
|
|
31
|
+
"dual",
|
|
32
|
+
"cli.json",
|
|
33
|
+
);
|
|
34
|
+
function projectFile(directory: string) {
|
|
35
|
+
return path.join(path.resolve(directory), ".dual", "publication.json");
|
|
36
|
+
}
|
|
37
|
+
const mapError = Effect.mapError(() =>
|
|
38
|
+
AuthProtocol.AuthError.make({
|
|
39
|
+
message: "Cannot read or save the CLI destination. Check its JSON and file permissions.",
|
|
40
|
+
}),
|
|
41
|
+
);
|
|
42
|
+
return Service.of({
|
|
43
|
+
defaultDeployment: pipe(
|
|
44
|
+
Effect.gen(function* () {
|
|
45
|
+
if (!(yield* fs.exists(file))) return Option.none();
|
|
46
|
+
return Option.some(
|
|
47
|
+
(yield* Schema.decodeEffect(
|
|
48
|
+
Schema.fromJsonString(Schema.Struct({ deployment: AuthProtocol.DeploymentUrl })),
|
|
49
|
+
)(yield* fs.readFileString(file))).deployment,
|
|
50
|
+
);
|
|
51
|
+
}),
|
|
52
|
+
mapError,
|
|
53
|
+
),
|
|
54
|
+
read: Effect.fn("CliDestination.read")(function* (directory) {
|
|
55
|
+
const location = projectFile(directory);
|
|
56
|
+
if (!(yield* fs.exists(location))) return Option.none();
|
|
57
|
+
return Option.some(
|
|
58
|
+
yield* Schema.decodeEffect(Schema.fromJsonString(Target))(
|
|
59
|
+
yield* fs.readFileString(location),
|
|
60
|
+
),
|
|
61
|
+
);
|
|
62
|
+
}, mapError),
|
|
63
|
+
save: Effect.fn("CliDestination.save")(function* (directory, target) {
|
|
64
|
+
const location = projectFile(directory);
|
|
65
|
+
yield* fs.makeDirectory(path.dirname(location), { recursive: true });
|
|
66
|
+
yield* fs.writeFileString(
|
|
67
|
+
location,
|
|
68
|
+
yield* Schema.encodeEffect(Schema.fromJsonString(Target))(target),
|
|
69
|
+
);
|
|
70
|
+
}, mapError),
|
|
71
|
+
saveDefault: Effect.fn("CliDestination.saveDefault")(function* (deployment) {
|
|
72
|
+
yield* fs.makeDirectory(path.dirname(file), { recursive: true });
|
|
73
|
+
yield* fs.writeFileString(
|
|
74
|
+
file,
|
|
75
|
+
yield* Schema.encodeEffect(
|
|
76
|
+
Schema.fromJsonString(Schema.Struct({ deployment: AuthProtocol.DeploymentUrl })),
|
|
77
|
+
)({ deployment }),
|
|
78
|
+
);
|
|
79
|
+
}, mapError),
|
|
80
|
+
});
|
|
81
|
+
}),
|
|
82
|
+
);
|
|
83
|
+
export * as CliDestination from "./destination.ts";
|
package/src/auth/http.ts
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { Array, Effect, Option, Redacted, String, pipe } from "effect";
|
|
2
|
+
|
|
3
|
+
import { HttpClient } from "effect/http";
|
|
4
|
+
import type { HttpClientError, HttpClientResponse } from "effect/http";
|
|
5
|
+
|
|
6
|
+
import { Diagnostics } from "#diagnostics";
|
|
7
|
+
|
|
8
|
+
import { AuthProtocol } from "./protocol.ts";
|
|
9
|
+
|
|
10
|
+
export function fromCause(error: HttpClientError.HttpClientError) {
|
|
11
|
+
return AuthProtocol.AuthError.make({
|
|
12
|
+
cause: Redacted.make(error),
|
|
13
|
+
message: Diagnostics.format({ cause: error.cause, message: error.message }),
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function withErrors(client: HttpClient.HttpClient) {
|
|
18
|
+
return HttpClient.transformResponse(client, Effect.mapError(fromCause));
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export const requireStatus = Effect.fn("CliHttp.requireStatus")(function* (
|
|
22
|
+
response: HttpClientResponse.HttpClientResponse,
|
|
23
|
+
accepted: number[],
|
|
24
|
+
) {
|
|
25
|
+
if (Array.contains(accepted, response.status)) return;
|
|
26
|
+
const body = yield* pipe(
|
|
27
|
+
response.text,
|
|
28
|
+
Effect.orElseSucceed(() => ""),
|
|
29
|
+
);
|
|
30
|
+
const details = pipe(
|
|
31
|
+
body,
|
|
32
|
+
String.trim,
|
|
33
|
+
Option.liftPredicate(String.isNonEmpty),
|
|
34
|
+
Option.getOrElse(() => "No error details returned by Dual."),
|
|
35
|
+
);
|
|
36
|
+
return yield* AuthProtocol.AuthError.make({ message: `HTTP ${response.status}: ${details}` });
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
export * as CliHttp from "./http.ts";
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
import { createServer } from "node:http";
|
|
2
|
+
|
|
3
|
+
import * as NodeHttpServer from "@effect/platform-node/NodeHttpServer";
|
|
4
|
+
|
|
5
|
+
import { Context, Deferred, Effect, Layer, Match, Redacted, Schema, pipe } from "effect";
|
|
6
|
+
|
|
7
|
+
import { Digest, SecureRandom } from "effect/crypto";
|
|
8
|
+
import { Base64Url } from "effect/encoding";
|
|
9
|
+
import {
|
|
10
|
+
HttpClient,
|
|
11
|
+
HttpClientRequest,
|
|
12
|
+
HttpRouter,
|
|
13
|
+
HttpServer,
|
|
14
|
+
HttpServerRequest,
|
|
15
|
+
HttpServerResponse,
|
|
16
|
+
} from "effect/http";
|
|
17
|
+
import { ChildProcess, ChildProcessSpawner } from "effect/process";
|
|
18
|
+
|
|
19
|
+
import { CliCredentials } from "./credentials.ts";
|
|
20
|
+
import { CliHttp } from "./http.ts";
|
|
21
|
+
import { AuthProtocol } from "./protocol.ts";
|
|
22
|
+
|
|
23
|
+
export type Interface = {
|
|
24
|
+
readonly login: (
|
|
25
|
+
deployment: string,
|
|
26
|
+
) => Effect.Effect<{ deployment: string; expiresAt: string }, AuthProtocol.AuthError>;
|
|
27
|
+
readonly logout: (deployment: string) => Effect.Effect<void, AuthProtocol.AuthError>;
|
|
28
|
+
};
|
|
29
|
+
export class Service extends Context.Service<Service, Interface>()(
|
|
30
|
+
"@dual-os/cli/auth/login/Service",
|
|
31
|
+
) {}
|
|
32
|
+
export const layer = Layer.effect(
|
|
33
|
+
Service,
|
|
34
|
+
Effect.gen(function* () {
|
|
35
|
+
const random = yield* SecureRandom.SecureRandom;
|
|
36
|
+
const digest = yield* Digest.Digest;
|
|
37
|
+
const client = CliHttp.withErrors(yield* HttpClient.HttpClient);
|
|
38
|
+
const spawner = yield* ChildProcessSpawner.ChildProcessSpawner;
|
|
39
|
+
const credentials = yield* CliCredentials.Service;
|
|
40
|
+
return Service.of({
|
|
41
|
+
login: Effect.fn("CliLogin.login")(
|
|
42
|
+
function* (deployment: string) {
|
|
43
|
+
const url = new URL(yield* Schema.decodeEffect(AuthProtocol.DeploymentUrl)(deployment))
|
|
44
|
+
.origin;
|
|
45
|
+
const verifier = Base64Url.encode(yield* random.randomBytes(32));
|
|
46
|
+
const state = Base64Url.encode(yield* random.randomBytes(32));
|
|
47
|
+
const codeChallenge = Base64Url.encode(
|
|
48
|
+
yield* digest.digest(Digest.sha256, new TextEncoder().encode(verifier)),
|
|
49
|
+
);
|
|
50
|
+
const callback = yield* Deferred.make<string, AuthProtocol.AuthError>();
|
|
51
|
+
const server = yield* NodeHttpServer.make(() => createServer(), {
|
|
52
|
+
host: "127.0.0.1",
|
|
53
|
+
port: 0,
|
|
54
|
+
});
|
|
55
|
+
const redirectUri = `${HttpServer.formatAddress(server.address)}/callback`;
|
|
56
|
+
yield* Layer.build(
|
|
57
|
+
pipe(
|
|
58
|
+
HttpRouter.add(
|
|
59
|
+
"GET",
|
|
60
|
+
"/callback",
|
|
61
|
+
Effect.gen(function* () {
|
|
62
|
+
const search = new URL(
|
|
63
|
+
(yield* HttpServerRequest.HttpServerRequest).url,
|
|
64
|
+
redirectUri,
|
|
65
|
+
).searchParams;
|
|
66
|
+
if (search.get("state") !== state) {
|
|
67
|
+
return HttpServerResponse.text("Invalid login state.", { status: 400 });
|
|
68
|
+
}
|
|
69
|
+
if (search.get("error") === "access_denied") {
|
|
70
|
+
yield* Deferred.fail(
|
|
71
|
+
callback,
|
|
72
|
+
AuthProtocol.AuthError.make({ message: "CLI login was declined." }),
|
|
73
|
+
);
|
|
74
|
+
return HttpServerResponse.text(
|
|
75
|
+
"CLI access was declined. Return to your terminal.",
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
const code = search.get("code");
|
|
79
|
+
if (!Schema.is(Schema.NonEmptyString)(code)) {
|
|
80
|
+
return HttpServerResponse.text("Invalid authorization code.", { status: 400 });
|
|
81
|
+
}
|
|
82
|
+
yield* Deferred.succeed(callback, code);
|
|
83
|
+
return HttpServerResponse.text(
|
|
84
|
+
"CLI approval received. Return to your terminal to confirm login.",
|
|
85
|
+
{ headers: { "cache-control": "no-store", "referrer-policy": "no-referrer" } },
|
|
86
|
+
);
|
|
87
|
+
}),
|
|
88
|
+
),
|
|
89
|
+
routes => HttpRouter.serve(routes, { disableListenLog: true, disableLogger: true }),
|
|
90
|
+
Layer.provide(Layer.succeed(HttpServer.HttpServer, server)),
|
|
91
|
+
Layer.provide(NodeHttpServer.layerHttpServices),
|
|
92
|
+
),
|
|
93
|
+
);
|
|
94
|
+
const browser = new URL("/api/cli-auth/authorize", url);
|
|
95
|
+
browser.search = new URLSearchParams({ codeChallenge, redirectUri, state }).toString();
|
|
96
|
+
const opened = yield* spawner.exitCode(
|
|
97
|
+
ChildProcess.make(
|
|
98
|
+
pipe(
|
|
99
|
+
Match.value(process.platform),
|
|
100
|
+
Match.when("darwin", () => "/usr/bin/open"),
|
|
101
|
+
Match.when("win32", () => "rundll32.exe"),
|
|
102
|
+
Match.orElse(() => "xdg-open"),
|
|
103
|
+
),
|
|
104
|
+
process.platform === "win32"
|
|
105
|
+
? ["url.dll,FileProtocolHandler", browser.href]
|
|
106
|
+
: [browser.href],
|
|
107
|
+
{ stderr: "ignore", stdin: "ignore", stdout: "ignore" },
|
|
108
|
+
),
|
|
109
|
+
);
|
|
110
|
+
if (opened !== 0) {
|
|
111
|
+
return yield* AuthProtocol.AuthError.make({
|
|
112
|
+
message: "Cannot open the browser for CLI login.",
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
const code = yield* Deferred.await(callback);
|
|
116
|
+
const response = yield* client.execute(
|
|
117
|
+
yield* HttpClientRequest.bodyJson(
|
|
118
|
+
HttpClientRequest.post(new URL("/api/cli-auth/token", url).href),
|
|
119
|
+
{ code, redirectUri, verifier },
|
|
120
|
+
),
|
|
121
|
+
);
|
|
122
|
+
yield* CliHttp.requireStatus(response, [200]);
|
|
123
|
+
const credential = yield* Schema.decodeUnknownEffect(AuthProtocol.Credential)(
|
|
124
|
+
yield* pipe(response.json, Effect.mapError(CliHttp.fromCause)),
|
|
125
|
+
);
|
|
126
|
+
yield* pipe(
|
|
127
|
+
credentials.set(url, Redacted.make(credential)),
|
|
128
|
+
Effect.tapError(() =>
|
|
129
|
+
client.execute(
|
|
130
|
+
pipe(
|
|
131
|
+
HttpClientRequest.delete(new URL("/api/cli-auth/session", url).href),
|
|
132
|
+
HttpClientRequest.bearerToken(credential.token),
|
|
133
|
+
),
|
|
134
|
+
),
|
|
135
|
+
),
|
|
136
|
+
);
|
|
137
|
+
return { deployment: url, expiresAt: credential.expiresAt };
|
|
138
|
+
},
|
|
139
|
+
Effect.timeout("5 minutes"),
|
|
140
|
+
Effect.scoped,
|
|
141
|
+
Effect.mapError(cause =>
|
|
142
|
+
Schema.is(AuthProtocol.AuthError)(cause)
|
|
143
|
+
? cause
|
|
144
|
+
: AuthProtocol.AuthError.make({
|
|
145
|
+
cause: Redacted.make(cause),
|
|
146
|
+
message: "CLI login failed or timed out. Run dual login --web again.",
|
|
147
|
+
}),
|
|
148
|
+
),
|
|
149
|
+
),
|
|
150
|
+
logout: Effect.fn("CliLogin.logout")(
|
|
151
|
+
function* (deployment: string) {
|
|
152
|
+
const url = new URL(yield* Schema.decodeEffect(AuthProtocol.DeploymentUrl)(deployment))
|
|
153
|
+
.origin;
|
|
154
|
+
const credential = Redacted.value(yield* credentials.get(url));
|
|
155
|
+
const response = yield* client.execute(
|
|
156
|
+
pipe(
|
|
157
|
+
HttpClientRequest.delete(new URL("/api/cli-auth/session", url).href),
|
|
158
|
+
HttpClientRequest.bearerToken(credential.token),
|
|
159
|
+
),
|
|
160
|
+
);
|
|
161
|
+
yield* CliHttp.requireStatus(response, [200]);
|
|
162
|
+
yield* credentials.remove(url);
|
|
163
|
+
},
|
|
164
|
+
Effect.scoped,
|
|
165
|
+
Effect.mapError(cause =>
|
|
166
|
+
Schema.is(AuthProtocol.AuthError)(cause)
|
|
167
|
+
? cause
|
|
168
|
+
: AuthProtocol.AuthError.make({
|
|
169
|
+
cause: Redacted.make(cause),
|
|
170
|
+
message: "CLI logout failed. Retry to revoke and remove the credential.",
|
|
171
|
+
}),
|
|
172
|
+
),
|
|
173
|
+
),
|
|
174
|
+
});
|
|
175
|
+
}),
|
|
176
|
+
);
|
|
177
|
+
export * as CliLogin from "./login.ts";
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { Schema, String } from "effect";
|
|
2
|
+
|
|
3
|
+
export type DeploymentUrl = typeof DeploymentUrl.Type;
|
|
4
|
+
export const DeploymentUrl = Schema.String.check(
|
|
5
|
+
Schema.makeFilter(value => {
|
|
6
|
+
if (!URL.canParse(value)) return false;
|
|
7
|
+
const url = new URL(value);
|
|
8
|
+
return (
|
|
9
|
+
!String.includes("'")(url.origin) &&
|
|
10
|
+
url.username === "" &&
|
|
11
|
+
url.password === "" &&
|
|
12
|
+
url.search === "" &&
|
|
13
|
+
url.hash === "" &&
|
|
14
|
+
(url.pathname === "/" || url.pathname === "") &&
|
|
15
|
+
(url.protocol === "https:" ||
|
|
16
|
+
(url.protocol === "http:" &&
|
|
17
|
+
(url.hostname === "localhost" || url.hostname === "127.0.0.1")))
|
|
18
|
+
);
|
|
19
|
+
}),
|
|
20
|
+
);
|
|
21
|
+
export type Credential = typeof Credential.Type;
|
|
22
|
+
export const Credential = Schema.Struct({
|
|
23
|
+
expiresAt: Schema.String.check(
|
|
24
|
+
Schema.isPattern(/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z$/u),
|
|
25
|
+
),
|
|
26
|
+
token: Schema.String.check(Schema.isPattern(/^[A-Za-z0-9_-]{32,256}$/u)),
|
|
27
|
+
});
|
|
28
|
+
export type Organizations = typeof Organizations.Type;
|
|
29
|
+
export const Organizations = Schema.Struct({
|
|
30
|
+
organizations: Schema.Array(Schema.Struct({ id: Schema.NonEmptyString, name: Schema.String })),
|
|
31
|
+
});
|
|
32
|
+
export class AuthError extends Schema.TaggedError<AuthError>()("CliAuthError", {
|
|
33
|
+
cause: Schema.optionalKey(Schema.Redacted(Schema.Defect())),
|
|
34
|
+
message: Schema.String,
|
|
35
|
+
}) {}
|
|
36
|
+
|
|
37
|
+
export * as AuthProtocol from "./protocol.ts";
|
package/src/baseline.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/** Explicit legacy/offline inspection fallback only; never an approved online release. */
|
|
2
|
+
export const versions = {
|
|
3
|
+
"@deslop/coding-standards": "0.1.1222",
|
|
4
|
+
"@dual/core": "0.0.1",
|
|
5
|
+
"@dual/dualspec": "0.0.0",
|
|
6
|
+
"@dual-os/sdk": "0.0.0",
|
|
7
|
+
"@effect/platform-node": "4.1.2",
|
|
8
|
+
"@effect/vitest": "4.1.2",
|
|
9
|
+
"bun-types": "1.4.2",
|
|
10
|
+
effect: "4.1.2",
|
|
11
|
+
typescript: "7.0.2",
|
|
12
|
+
vitest: "5.0.3",
|
|
13
|
+
} as const;
|
|
14
|
+
|
|
15
|
+
export * as Baseline from "./baseline.ts";
|
package/src/bin.ts
ADDED