@composable-os/cli 0.0.0-stage → 0.1.0-beta.7
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 +109 -0
- package/README.md +24 -2
- package/dist/blocks-HVTAQ5W2.js +233 -0
- package/dist/chunk-2ABSVMGB.js +13 -0
- package/dist/chunk-2P4AZTFL.js +358 -0
- package/dist/chunk-2S7375SC.js +802 -0
- package/dist/chunk-5KSXSK7Y.js +47 -0
- package/dist/chunk-6UWRT4VM.js +220 -0
- package/dist/chunk-BEKL3CA2.js +28975 -0
- package/dist/chunk-E5JLTLRM.js +50 -0
- package/dist/chunk-HDIOVFAZ.js +544 -0
- package/dist/chunk-KGHA67HG.js +765 -0
- package/dist/chunk-MAXLUQKB.js +1287 -0
- package/dist/chunk-MINQ46RU.js +16485 -0
- package/dist/chunk-STJZJIRA.js +11378 -0
- package/dist/chunk-VL62IMBN.js +1423 -0
- package/dist/chunk-X6I2LWB3.js +24319 -0
- package/dist/chunk-Y7PQ7NIL.js +1178 -0
- package/dist/chunk-ZRWF6QZS.js +2357 -0
- package/dist/cli-BRSACHSG.js +31393 -0
- package/dist/cli-XHC6QBQW.js +121 -0
- package/dist/cli.js +25 -0
- package/dist/client-repo-G55G4OLV.js +55 -0
- package/dist/create.js +25 -0
- package/dist/fields-64BQJA62.js +48 -0
- package/dist/invoke-5SR5ZWW7.js +26 -0
- package/dist/person-AZFEPZOE.js +58 -0
- package/dist/platform/migrations/0001_init.sql +59 -0
- package/dist/platform/migrations/0002_users_settings.sql +34 -0
- package/dist/platform/migrations/0003_people_organisations.sql +225 -0
- package/dist/platform/migrations/0004_activities_tasks.sql +88 -0
- package/dist/platform/migrations/0005_views_audit.sql +79 -0
- package/dist/platform/migrations/0006_search.sql +223 -0
- package/dist/platform/migrations/0007_crm_views.sql +141 -0
- package/dist/platform/migrations/0008_audit_redaction.sql +116 -0
- package/dist/platform/migrations/0010_approval_queue.sql +90 -0
- package/dist/platform/migrations/0011_connected_apps.sql +36 -0
- package/dist/platform/migrations/0020_extensions.sql +373 -0
- package/dist/platform/migrations/0030_extension_proposals.sql +29 -0
- package/dist/platform/migrations/0050_live_row_indexes.sql +32 -0
- package/dist/platform/migrations/0060_audit_read_counts.sql +31 -0
- package/dist/platform/migrations/0061_audit_retention.sql +95 -0
- package/dist/platform/migrations/0062_run_history_retention.sql +6 -0
- package/dist/platform/migrations/0063_pending_action_compaction.sql +18 -0
- package/dist/platform/migrations/0064_drop_rate_limit.sql +6 -0
- package/dist/platform/migrations/0065_storage_stats.sql +13 -0
- package/dist/platform/migrations/0070_drop_proposals_ext_idx.sql +9 -0
- package/dist/platform/migrations/0080_views_dashboards.sql +46 -0
- package/dist/platform/migrations/0100_stage_history.sql +54 -0
- package/dist/platform/migrations/0110_integrations.sql +103 -0
- package/dist/platform/migrations/0111_email_calendar_sync.sql +137 -0
- package/dist/platform/migrations/0112_sync_item_occurred_at.sql +8 -0
- package/dist/platform/migrations/0130_automations.sql +113 -0
- package/dist/platform/migrations/0131_notifications.sql +29 -0
- package/dist/platform/migrations/0132_automation_runtime.sql +14 -0
- package/dist/platform/migrations/0150_ai_summaries_embeddings.sql +48 -0
- package/dist/platform/migrations/0160_releases.sql +41 -0
- package/dist/platform/migrations/0161_setup_wizard.sql +30 -0
- package/dist/platform/migrations/0170_automation_connections.sql +32 -0
- package/dist/platform/migrations/0171_automation_outbox.sql +23 -0
- package/dist/platform/migrations/0172_notification_delivery.sql +46 -0
- package/dist/platform/migrations/0200_assistant_conversations.sql +25 -0
- package/dist/platform/migrations/0205_policy_adjudicator.sql +61 -0
- package/dist/platform/migrations/0210_daily_digest.sql +33 -0
- package/dist/platform/migrations/0220_entitlements.sql +13 -0
- package/dist/platform/migrations/0221_support_grants.sql +33 -0
- package/dist/platform/migrations/0250_judge.sql +11 -0
- package/dist/platform/migrations/0251_adjudication_judgement.sql +8 -0
- package/dist/platform/migrations/0252_judge_usage.sql +14 -0
- package/dist/platform/migrations/0255_summary_checks.sql +9 -0
- package/dist/platform/migrations/0256_outbound_check.sql +9 -0
- package/dist/platform/migrations/0260_ai_usage.sql +20 -0
- package/dist/platform/migrations/0270_assistant_conversation_refs.sql +29 -0
- package/dist/platform/migrations/0310_assignment_rules.sql +54 -0
- package/dist/platform/migrations/0320_duplicates.sql +41 -0
- package/dist/platform/migrations/0330_erase_completeness.sql +54 -0
- package/dist/platform/migrations/0350_assistant_thread.sql +38 -0
- package/dist/platform/migrations/0351_assistant_model_roles.sql +26 -0
- package/dist/platform/migrations/0352_assistant_memory.sql +74 -0
- package/dist/platform/migrations/0358_ai_cache_observation.sql +24 -0
- package/dist/platform/migrations/0359_ai_compaction_decision.sql +25 -0
- package/dist/platform/migrations/0360_ai_cache_estimate.sql +35 -0
- package/dist/platform/migrations/0361_voice_preferences.sql +27 -0
- package/dist/platform/migrations/0362_voice_usage.sql +17 -0
- package/dist/platform/migrations/0365_routines.sql +38 -0
- package/dist/platform/migrations/0370_approval_execution.sql +20 -0
- package/dist/platform/migrations/0371_agent_jobs.sql +65 -0
- package/dist/platform/migrations/0380_rec_views.sql +94 -0
- package/dist/platform/migrations/0400_customer_audit_actor.sql +142 -0
- package/dist/platform/migrations/0401_customer_accounts.sql +61 -0
- package/dist/platform/migrations/0402_erase_requests.sql +34 -0
- package/dist/platform/migrations/0410_idempotency_keys.sql +45 -0
- package/dist/platform/migrations/0411_device_sessions.sql +33 -0
- package/dist/platform/migrations/0420_transition_history.sql +100 -0
- package/dist/platform/migrations/0421_orders.sql +134 -0
- package/dist/platform/migrations/0422_order_payments.sql +109 -0
- package/dist/platform/migrations/0440_capacity.sql +100 -0
- package/dist/platform/migrations/0441_capacity_views.sql +40 -0
- package/dist/platform/migrations/0450_order_grants.sql +21 -0
- package/dist/platform/migrations/0451_pack_roles.sql +18 -0
- package/dist/platform/migrations/0460_content.sql +59 -0
- package/dist/platform/migrations/0461_media.sql +52 -0
- package/dist/platform/migrations/0470_publish_versions.sql +36 -0
- package/dist/platform/migrations/0471_permission_grants.sql +18 -0
- package/dist/platform/migrations/0490_staff_invites.sql +40 -0
- package/dist/platform/migrations/0491_sign_in_mail_kind.sql +10 -0
- package/dist/platform/migrations/0492_email_confirmation_and_sign_in_confirm.sql +30 -0
- package/dist/platform/migrations/0500_published_media_field.sql +25 -0
- package/dist/platform/migrations/0501_import_keys.sql +23 -0
- package/dist/platform/sdk/automation-check.ts +534 -0
- package/dist/platform/sdk/automation.ts +743 -0
- package/dist/platform/sdk/behaviour.ts +215 -0
- package/dist/platform/sdk/capacity.ts +112 -0
- package/dist/platform/sdk/contract.ts +766 -0
- package/dist/platform/sdk/document.ts +788 -0
- package/dist/platform/sdk/field-types.ts +106 -0
- package/dist/platform/sdk/formula/ast.ts +72 -0
- package/dist/platform/sdk/formula/compile.ts +454 -0
- package/dist/platform/sdk/formula/index.ts +4 -0
- package/dist/platform/sdk/formula/parser.ts +417 -0
- package/dist/platform/sdk/index.ts +33 -0
- package/dist/platform/sdk/manifest.ts +1484 -0
- package/dist/platform/sdk/media.ts +46 -0
- package/dist/platform/sdk/permissions.ts +60 -0
- package/dist/platform/sdk/renamed.ts +63 -0
- package/dist/platform/sdk/rich-text-fixture.ts +68 -0
- package/dist/platform/sdk/rich-text.ts +173 -0
- package/dist/platform/sdk/runtime.ts +410 -0
- package/dist/platform/sdk/sellable.ts +396 -0
- package/dist/platform/sdk/slug.ts +25 -0
- package/dist/platform/sdk/states.ts +162 -0
- package/dist/platform/sdk/testing.ts +836 -0
- package/dist/products-2H5DR232.js +11 -0
- package/dist/run-4JNFLYXV.js +847 -0
- package/dist/src-J27WXNLY.js +270 -0
- package/dist/src-SSVOBH6L.js +31 -0
- package/dist/token-MOJUA2U6.js +70 -0
- package/dist/token-util-TENRN4V7.js +6 -0
- package/package.json +33 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
# Functional Source License, Version 1.1, ALv2 Future License
|
|
2
|
+
|
|
3
|
+
> This licence covers the repository except the directories listed in NOTICE. In particular, the
|
|
4
|
+
> assistant packages `packages/agent-*` (agent-core, agent-a2ui, agent-voice, agent-plugins) are
|
|
5
|
+
> licensed under the MIT License; see the LICENSE file in each of those directories (ADR 0350).
|
|
6
|
+
|
|
7
|
+
## Abbreviation
|
|
8
|
+
|
|
9
|
+
FSL-1.1-ALv2
|
|
10
|
+
|
|
11
|
+
## Notice
|
|
12
|
+
|
|
13
|
+
Copyright 2026 Tim O'Connell
|
|
14
|
+
|
|
15
|
+
## Terms and Conditions
|
|
16
|
+
|
|
17
|
+
### Licensor ("We")
|
|
18
|
+
|
|
19
|
+
The party offering the Software under these Terms and Conditions.
|
|
20
|
+
|
|
21
|
+
### The Software
|
|
22
|
+
|
|
23
|
+
The "Software" is each version of the software that we make available under
|
|
24
|
+
these Terms and Conditions, as indicated by our inclusion of these Terms and
|
|
25
|
+
Conditions with the Software.
|
|
26
|
+
|
|
27
|
+
### License Grant
|
|
28
|
+
|
|
29
|
+
Subject to your compliance with this License Grant and the Patents,
|
|
30
|
+
Redistribution and Trademark clauses below, we hereby grant you the right to
|
|
31
|
+
use, copy, modify, create derivative works, publicly perform, publicly display
|
|
32
|
+
and redistribute the Software for any Permitted Purpose identified below.
|
|
33
|
+
|
|
34
|
+
### Permitted Purpose
|
|
35
|
+
|
|
36
|
+
A Permitted Purpose is any purpose other than a Competing Use. A Competing Use
|
|
37
|
+
means making the Software available to others in a commercial product or
|
|
38
|
+
service that:
|
|
39
|
+
|
|
40
|
+
1. substitutes for the Software;
|
|
41
|
+
|
|
42
|
+
2. substitutes for any other product or service we offer using the Software
|
|
43
|
+
that exists as of the date we make the Software available; or
|
|
44
|
+
|
|
45
|
+
3. offers the same or substantially similar functionality as the Software.
|
|
46
|
+
|
|
47
|
+
Permitted Purposes specifically include using the Software:
|
|
48
|
+
|
|
49
|
+
1. for your internal use and access;
|
|
50
|
+
|
|
51
|
+
2. for non-commercial education;
|
|
52
|
+
|
|
53
|
+
3. for non-commercial research; and
|
|
54
|
+
|
|
55
|
+
4. in connection with professional services that you provide to a licensee
|
|
56
|
+
using the Software in accordance with these Terms and Conditions.
|
|
57
|
+
|
|
58
|
+
### Patents
|
|
59
|
+
|
|
60
|
+
To the extent your use for a Permitted Purpose would necessarily infringe our
|
|
61
|
+
patents, the license grant above includes a license under our patents. If you
|
|
62
|
+
make a claim against any party that the Software infringes or contributes to
|
|
63
|
+
the infringement of any patent, then your patent license to the Software ends
|
|
64
|
+
immediately.
|
|
65
|
+
|
|
66
|
+
### Redistribution
|
|
67
|
+
|
|
68
|
+
The Terms and Conditions apply to all copies, modifications and derivatives of
|
|
69
|
+
the Software.
|
|
70
|
+
|
|
71
|
+
If you redistribute any copies, modifications or derivatives of the Software,
|
|
72
|
+
you must include a copy of or a link to these Terms and Conditions and not
|
|
73
|
+
remove any copyright notices provided in or with the Software.
|
|
74
|
+
|
|
75
|
+
### Disclaimer
|
|
76
|
+
|
|
77
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND WITHOUT WARRANTIES OF ANY KIND, EXPRESS OR
|
|
78
|
+
IMPLIED, INCLUDING WITHOUT LIMITATION WARRANTIES OF FITNESS FOR A PARTICULAR
|
|
79
|
+
PURPOSE, MERCHANTABILITY, TITLE OR NON-INFRINGEMENT.
|
|
80
|
+
|
|
81
|
+
IN NO EVENT WILL WE HAVE ANY LIABILITY TO YOU ARISING OUT OF OR RELATED TO THE
|
|
82
|
+
SOFTWARE, INCLUDING INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES,
|
|
83
|
+
EVEN IF WE HAVE BEEN INFORMED OF THEIR POSSIBILITY IN ADVANCE.
|
|
84
|
+
|
|
85
|
+
### Trademarks
|
|
86
|
+
|
|
87
|
+
Except for displaying the License Details and identifying us as the origin of
|
|
88
|
+
the Software, you have no right under these Terms and Conditions to use our
|
|
89
|
+
trademarks, trade names, service marks or product names.
|
|
90
|
+
|
|
91
|
+
## Grant of Future License
|
|
92
|
+
|
|
93
|
+
We hereby irrevocably grant you an additional license to use the Software under
|
|
94
|
+
the Apache License, Version 2.0 that is effective on the second anniversary of
|
|
95
|
+
the date we make the Software available. On or after that date, you may use the
|
|
96
|
+
Software under the Apache License, Version 2.0, in which case the following
|
|
97
|
+
will apply:
|
|
98
|
+
|
|
99
|
+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
|
|
100
|
+
this file except in compliance with the License.
|
|
101
|
+
|
|
102
|
+
You may obtain a copy of the License at
|
|
103
|
+
|
|
104
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
105
|
+
|
|
106
|
+
Unless required by applicable law or agreed to in writing, software distributed
|
|
107
|
+
under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
|
108
|
+
CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
|
109
|
+
specific language governing permissions and limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,3 +1,25 @@
|
|
|
1
|
-
#
|
|
1
|
+
# create-composable-os
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Install a Composable OS product (github.com/timoconnellaus/composable-os) into your own Cloudflare
|
|
4
|
+
account, then upgrade and roll it back. `--product` chooses it; the default, `crm`, is the CRM.
|
|
5
|
+
It downloads a release from GitHub Releases, verifies its sha256 and its GitHub build attestation, and talks to the Cloudflare API with your token. No wrangler, no service
|
|
6
|
+
of ours, no telemetry.
|
|
7
|
+
|
|
8
|
+
Not published to npm yet: build it from a checkout (`pnpm --filter create-composable-os build`) and run
|
|
9
|
+
`node packages/create-composable-os/dist/cli.js install` wherever this says `npx @composable-os/cli install`.
|
|
10
|
+
|
|
11
|
+
```sh
|
|
12
|
+
npx @composable-os/cli install # install (or repair an install)
|
|
13
|
+
npx @composable-os/cli upgrade # update to the newest release on your channel
|
|
14
|
+
npx @composable-os/cli rollback # undo the last update (redeploy + restore the database bookmark)
|
|
15
|
+
npx @composable-os/cli status
|
|
16
|
+
npx @composable-os/cli install --help # every option, and the API token permissions
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
The token needs, on the account: Workers Scripts Edit, D1 Edit, Workers R2 Storage Edit, Workers KV
|
|
20
|
+
Storage Edit, Queues Edit, Vectorize Edit and Account Settings Read; with in-app AI (the default)
|
|
21
|
+
also AI Gateway Edit and Account API Tokens Edit (the install creates an AI Gateway and its token),
|
|
22
|
+
plus Secrets Store Edit for `--provider-key`; for a custom hostname also Zone Read and Workers
|
|
23
|
+
Routes Edit on its zone. The CLI never prints secret values.
|
|
24
|
+
|
|
25
|
+
Full guide: [docs/deploying.md](https://github.com/timoconnellaus/composable-os/blob/main/docs/deploying.md).
|
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import {
|
|
3
|
+
fetchKit,
|
|
4
|
+
lineDiff,
|
|
5
|
+
loadClientProduct
|
|
6
|
+
} from "./chunk-VL62IMBN.js";
|
|
7
|
+
import {
|
|
8
|
+
CliError,
|
|
9
|
+
str
|
|
10
|
+
} from "./chunk-Y7PQ7NIL.js";
|
|
11
|
+
import "./chunk-ZRWF6QZS.js";
|
|
12
|
+
import "./chunk-2ABSVMGB.js";
|
|
13
|
+
import "./chunk-6UWRT4VM.js";
|
|
14
|
+
import "./chunk-KGHA67HG.js";
|
|
15
|
+
import "./chunk-5KSXSK7Y.js";
|
|
16
|
+
|
|
17
|
+
// src/blocks.ts
|
|
18
|
+
import { createHash } from "node:crypto";
|
|
19
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
20
|
+
import { dirname, join, resolve } from "node:path";
|
|
21
|
+
var LOCK = "blocks.lock.json";
|
|
22
|
+
var decode = (bytes) => new TextDecoder().decode(bytes);
|
|
23
|
+
var sha = (text) => createHash("sha256").update(text).digest("hex");
|
|
24
|
+
function readLock(root) {
|
|
25
|
+
const path = join(root, LOCK);
|
|
26
|
+
return existsSync(path) ? JSON.parse(readFileSync(path, "utf8")) : {};
|
|
27
|
+
}
|
|
28
|
+
function writeLock(root, lock) {
|
|
29
|
+
const sorted = Object.fromEntries(Object.entries(lock).sort(([a], [b]) => a.localeCompare(b)));
|
|
30
|
+
writeFileSync(join(root, LOCK), `${JSON.stringify(sorted, null, 2)}
|
|
31
|
+
`);
|
|
32
|
+
}
|
|
33
|
+
function listBlocks(kit) {
|
|
34
|
+
const lines = [...kit.keys()].filter((p) => /^blocks\/[^/]+\/block\.json$/.test(p)).sort().map((p) => {
|
|
35
|
+
const b = JSON.parse(decode(kit.get(p)));
|
|
36
|
+
const parts = [
|
|
37
|
+
`${b.skin}`,
|
|
38
|
+
b.pack ? `pack ${b.pack}` : "base",
|
|
39
|
+
b.operations.length ? `calls ${b.operations.join(", ")}` : "",
|
|
40
|
+
b.dependsOn.length ? `with ${b.dependsOn.join(", ")}` : ""
|
|
41
|
+
].filter(Boolean);
|
|
42
|
+
return ` ${b.name.padEnd(16)} ${parts.join("; ")}`;
|
|
43
|
+
});
|
|
44
|
+
return `Blocks (cos add <name>):
|
|
45
|
+
${lines.join("\n")}`;
|
|
46
|
+
}
|
|
47
|
+
function blockManifest(kit, name) {
|
|
48
|
+
const bytes = kit.get(`blocks/${name}/block.json`);
|
|
49
|
+
if (!bytes) throw new CliError(`No block ${name} in this release.
|
|
50
|
+
${listBlocks(kit)}`);
|
|
51
|
+
return JSON.parse(decode(bytes));
|
|
52
|
+
}
|
|
53
|
+
function installCommand(root, app, packages) {
|
|
54
|
+
const cd = app && app !== "." ? `cd ${app} && ` : "";
|
|
55
|
+
const appJson = join(root, app, "app.json");
|
|
56
|
+
if (existsSync(appJson) && /"expo"\s*:/.test(readFileSync(appJson, "utf8"))) {
|
|
57
|
+
return `${cd}npx expo install ${packages.join(" ")}`;
|
|
58
|
+
}
|
|
59
|
+
const at = (file) => existsSync(join(root, file)) || existsSync(join(root, app, file));
|
|
60
|
+
const manager = at("pnpm-lock.yaml") ? "pnpm add" : at("yarn.lock") ? "yarn add" : at("bun.lock") || at("bun.lockb") ? "bun add" : at("package-lock.json") ? "npm install" : "pnpm add";
|
|
61
|
+
return `${cd}${manager} ${packages.join(" ")}`;
|
|
62
|
+
}
|
|
63
|
+
var blockDir = (app, name) => join(app, "src", "blocks", name);
|
|
64
|
+
async function add(argv, flags, deps) {
|
|
65
|
+
const name = argv[0];
|
|
66
|
+
const root = resolve(str(flags, "dir") ?? process.cwd());
|
|
67
|
+
const product = await loadClientProduct(root);
|
|
68
|
+
const { kit, version } = await fetchKit(
|
|
69
|
+
flags,
|
|
70
|
+
deps,
|
|
71
|
+
product.platform.release,
|
|
72
|
+
product.platform.repository,
|
|
73
|
+
product.platform.version
|
|
74
|
+
);
|
|
75
|
+
if (!name) {
|
|
76
|
+
deps.io.out(listBlocks(kit));
|
|
77
|
+
return 0;
|
|
78
|
+
}
|
|
79
|
+
const lock = readLock(root);
|
|
80
|
+
const added = [];
|
|
81
|
+
const needs = /* @__PURE__ */ new Map();
|
|
82
|
+
const visit = (block, trail) => {
|
|
83
|
+
if (lock[block] || added.includes(block)) return;
|
|
84
|
+
if (trail.includes(block))
|
|
85
|
+
throw new CliError(`Blocks depend on each other: ${trail.join(" > ")}`);
|
|
86
|
+
const manifest = blockManifest(kit, block);
|
|
87
|
+
const app = manifest.skin === "web" ? product.web?.dir : product.mobile?.dir;
|
|
88
|
+
if (!app) {
|
|
89
|
+
throw new CliError(
|
|
90
|
+
`${block} is a ${manifest.skin} block and this repo has no ${manifest.skin === "web" ? "web" : "mobile"} app in product.ts.`
|
|
91
|
+
);
|
|
92
|
+
}
|
|
93
|
+
if (manifest.pack && !product.packs.includes(manifest.pack)) {
|
|
94
|
+
throw new CliError(
|
|
95
|
+
`${block} is a block of the ${manifest.pack} pack, which product.ts does not list.`
|
|
96
|
+
);
|
|
97
|
+
}
|
|
98
|
+
for (const dep of manifest.dependsOn) visit(dep, [...trail, block]);
|
|
99
|
+
const files = {};
|
|
100
|
+
for (const file of manifest.files) {
|
|
101
|
+
const bytes = kit.get(`blocks/${block}/${file}`);
|
|
102
|
+
if (!bytes) throw new CliError(`The release's ${block} has no ${file}.`);
|
|
103
|
+
const target = join(root, blockDir(app, block), file);
|
|
104
|
+
if (existsSync(target)) throw new CliError(`${target} exists and is not a copied block.`);
|
|
105
|
+
mkdirSync(dirname(target), { recursive: true });
|
|
106
|
+
writeFileSync(target, bytes);
|
|
107
|
+
files[file] = sha(bytes);
|
|
108
|
+
}
|
|
109
|
+
lock[block] = { version, app, files };
|
|
110
|
+
added.push(block);
|
|
111
|
+
for (const [pkg, range] of Object.entries(manifest.packages ?? {})) {
|
|
112
|
+
needs.set(pkg, pkg.startsWith("@composable-os/") ? version : range);
|
|
113
|
+
}
|
|
114
|
+
if (!apps.includes(app)) apps.push(app);
|
|
115
|
+
};
|
|
116
|
+
const apps = [];
|
|
117
|
+
visit(name, []);
|
|
118
|
+
writeLock(root, lock);
|
|
119
|
+
if (needs.size) {
|
|
120
|
+
const app = apps[0];
|
|
121
|
+
deps.io.out(
|
|
122
|
+
`They import ${[...needs.keys()].join(", ")}. Install them in ${app}:
|
|
123
|
+
${installCommand(
|
|
124
|
+
root,
|
|
125
|
+
app,
|
|
126
|
+
[...needs].map(([p, v]) => `${p}@${v}`)
|
|
127
|
+
)}`
|
|
128
|
+
);
|
|
129
|
+
}
|
|
130
|
+
deps.io.out(
|
|
131
|
+
added.length ? `Copied ${added.join(", ")} (${version}) into ${added.map((b) => blockDir(lock[b]?.app ?? "", b)).join(", ")}. The files are yours now; ${LOCK} records where they came from.` : `${name} is already copied (${LOCK}).`
|
|
132
|
+
);
|
|
133
|
+
return 0;
|
|
134
|
+
}
|
|
135
|
+
async function diff(argv, flags, deps) {
|
|
136
|
+
const name = argv[0];
|
|
137
|
+
if (!name) throw new CliError("Usage: cos diff <block>");
|
|
138
|
+
const root = resolve(str(flags, "dir") ?? process.cwd());
|
|
139
|
+
const product = await loadClientProduct(root);
|
|
140
|
+
const entry = readLock(root)[name];
|
|
141
|
+
if (!entry) throw new CliError(`${name} was not copied with cos add (${LOCK}).`);
|
|
142
|
+
const { io } = deps;
|
|
143
|
+
const target = str(flags, "version") ?? product.platform.version;
|
|
144
|
+
const accept = Boolean(flags.accept);
|
|
145
|
+
if (accept && target !== product.platform.version) {
|
|
146
|
+
throw new CliError(
|
|
147
|
+
`cos diff --accept records a block as merged up to the version product.ts is on (${product.platform.version}), not ${target}. Run cos upgrade first, or leave out --version.`
|
|
148
|
+
);
|
|
149
|
+
}
|
|
150
|
+
const accepted = (kit) => {
|
|
151
|
+
if (!accept) return;
|
|
152
|
+
const manifest = blockManifest(kit, name);
|
|
153
|
+
const files = {};
|
|
154
|
+
for (const file of manifest.files) {
|
|
155
|
+
const bytes = kit.get(`blocks/${name}/${file}`);
|
|
156
|
+
if (bytes) files[file] = sha(bytes);
|
|
157
|
+
}
|
|
158
|
+
const lock = readLock(root);
|
|
159
|
+
lock[name] = { ...entry, version: target, files };
|
|
160
|
+
writeLock(root, lock);
|
|
161
|
+
io.out(
|
|
162
|
+
`
|
|
163
|
+
Accepted: ${name} is recorded as merged up to ${target} (${LOCK}). Your files are not changed; a later cos diff shows only what changes after this.`
|
|
164
|
+
);
|
|
165
|
+
};
|
|
166
|
+
for (const [file, hash] of Object.entries(entry.files)) {
|
|
167
|
+
const path = join(root, blockDir(entry.app, name), file);
|
|
168
|
+
if (!existsSync(path)) io.out(`${file}: removed here`);
|
|
169
|
+
else if (sha(readFileSync(path)) !== hash) io.out(`${file}: edited here since it was copied`);
|
|
170
|
+
}
|
|
171
|
+
const fetch = (version) => fetchKit(flags, deps, product.platform.release, product.platform.repository, version, {
|
|
172
|
+
bundleOnly: true
|
|
173
|
+
});
|
|
174
|
+
if (target === entry.version) {
|
|
175
|
+
const { kit } = await fetch(target);
|
|
176
|
+
const now = blockManifest(kit, name);
|
|
177
|
+
let changed2 = false;
|
|
178
|
+
for (const file of [.../* @__PURE__ */ new Set([...Object.keys(entry.files), ...now.files])].sort()) {
|
|
179
|
+
const bytes = kit.get(`blocks/${name}/${file}`);
|
|
180
|
+
const upstream = bytes ? decode(bytes) : "";
|
|
181
|
+
if (bytes && sha(bytes) === entry.files[file]) continue;
|
|
182
|
+
changed2 = true;
|
|
183
|
+
const path = join(root, blockDir(entry.app, name), file);
|
|
184
|
+
const here = existsSync(path) ? readFileSync(path, "utf8") : "";
|
|
185
|
+
const unedited = existsSync(path) && sha(readFileSync(path)) === entry.files[file];
|
|
186
|
+
io.out(
|
|
187
|
+
`
|
|
188
|
+
--- ${file} (${unedited ? `as copied from ${entry.version}` : "here, edited"})
|
|
189
|
+
+++ ${file} (${target} as the release has it now${bytes ? "" : ", absent"})`
|
|
190
|
+
);
|
|
191
|
+
for (const line of lineDiff(here, upstream)) io.out(line);
|
|
192
|
+
}
|
|
193
|
+
io.out(
|
|
194
|
+
changed2 ? `${name}'s files in ${target} changed since it was copied (the release was rebuilt at the same version). Apply by hand; nothing is changed.` : `No upstream change: ${name} was copied from ${entry.version}, the version product.ts is on.`
|
|
195
|
+
);
|
|
196
|
+
if (changed2) accepted(kit);
|
|
197
|
+
return 0;
|
|
198
|
+
}
|
|
199
|
+
const [from, to] = [await fetch(entry.version), await fetch(target)];
|
|
200
|
+
const before = blockManifest(from.kit, name);
|
|
201
|
+
const after = blockManifest(to.kit, name);
|
|
202
|
+
io.out(
|
|
203
|
+
`Upstream changes to ${name}, ${entry.version} \u2192 ${target} (apply by hand; nothing is changed):`
|
|
204
|
+
);
|
|
205
|
+
let changed = false;
|
|
206
|
+
for (const file of [.../* @__PURE__ */ new Set([...before.files, ...after.files])].sort()) {
|
|
207
|
+
const a = from.kit.get(`blocks/${name}/${file}`);
|
|
208
|
+
const b = to.kit.get(`blocks/${name}/${file}`);
|
|
209
|
+
const textA = a ? decode(a) : "";
|
|
210
|
+
const textB = b ? decode(b) : "";
|
|
211
|
+
if (textA === textB) continue;
|
|
212
|
+
changed = true;
|
|
213
|
+
io.out(
|
|
214
|
+
`
|
|
215
|
+
--- ${file} (${entry.version}${a ? "" : ", absent"})
|
|
216
|
+
+++ ${file} (${target}${b ? "" : ", absent"})`
|
|
217
|
+
);
|
|
218
|
+
for (const line of lineDiff(textA, textB)) io.out(line);
|
|
219
|
+
}
|
|
220
|
+
if (!changed) io.out(" none");
|
|
221
|
+
for (const dep of after.dependsOn.filter((d) => !before.dependsOn.includes(d))) {
|
|
222
|
+
io.out(`It now depends on ${dep}: cos add ${dep}`);
|
|
223
|
+
}
|
|
224
|
+
accepted(to.kit);
|
|
225
|
+
return 0;
|
|
226
|
+
}
|
|
227
|
+
export {
|
|
228
|
+
add,
|
|
229
|
+
blockManifest,
|
|
230
|
+
diff,
|
|
231
|
+
installCommand,
|
|
232
|
+
listBlocks
|
|
233
|
+
};
|