@composable-os/cli 0.0.0-stage → 0.1.0-beta.10

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 (176) hide show
  1. package/LICENSE +109 -0
  2. package/README.md +24 -2
  3. package/dist/accounts-X4CKM3HL.js +46 -0
  4. package/dist/blocks-YWDHEBOK.js +233 -0
  5. package/dist/chunk-2ABSVMGB.js +13 -0
  6. package/dist/chunk-5KSXSK7Y.js +47 -0
  7. package/dist/chunk-6GDEDOV7.js +157 -0
  8. package/dist/chunk-6UPUF4ML.js +29998 -0
  9. package/dist/chunk-6UWRT4VM.js +220 -0
  10. package/dist/chunk-6VXHPKGG.js +1302 -0
  11. package/dist/chunk-7CQGMVDO.js +63 -0
  12. package/dist/chunk-A4NTSYWV.js +11092 -0
  13. package/dist/chunk-CP6BXI6F.js +25825 -0
  14. package/dist/chunk-DU6OIFOU.js +2358 -0
  15. package/dist/chunk-E4WCYTCT.js +347 -0
  16. package/dist/chunk-GYSGVT6R.js +284 -0
  17. package/dist/chunk-GYTEW66E.js +50 -0
  18. package/dist/chunk-HDIOVFAZ.js +544 -0
  19. package/dist/chunk-IFG4FRW5.js +504 -0
  20. package/dist/chunk-JJHHNV46.js +227 -0
  21. package/dist/chunk-K6T42YCH.js +704 -0
  22. package/dist/chunk-KGHA67HG.js +765 -0
  23. package/dist/chunk-LJFLENFC.js +88 -0
  24. package/dist/chunk-LLULPZAJ.js +365 -0
  25. package/dist/chunk-M7A6FR2Z.js +2586 -0
  26. package/dist/chunk-O2UIZHND.js +249 -0
  27. package/dist/chunk-Q4N55M2Z.js +552 -0
  28. package/dist/chunk-QGGJ2G6Z.js +349 -0
  29. package/dist/chunk-R4W5XAUD.js +837 -0
  30. package/dist/chunk-TQFGGSA4.js +748 -0
  31. package/dist/chunk-VY64DMQO.js +15302 -0
  32. package/dist/chunk-WC5LHBBA.js +426 -0
  33. package/dist/chunk-WO6D3XP3.js +9351 -0
  34. package/dist/chunk-Y7JZFSTQ.js +1425 -0
  35. package/dist/chunk-YJJHF65I.js +759 -0
  36. package/dist/chunk-Z3RMMB6S.js +668 -0
  37. package/dist/cli-2DFENR62.js +134 -0
  38. package/dist/cli-YIOVSKOD.js +24531 -0
  39. package/dist/cli.js +25 -0
  40. package/dist/client-repo-PRU3VCQQ.js +55 -0
  41. package/dist/create.js +25 -0
  42. package/dist/fields-2NC7LSYE.js +50 -0
  43. package/dist/grants-QXMKYMGB.js +32 -0
  44. package/dist/invoke-I3NNNXVL.js +39 -0
  45. package/dist/order-PUWD65BC.js +19 -0
  46. package/dist/person-WIQQ7ITU.js +68 -0
  47. package/dist/plan-on-sale-NB774CQL.js +26 -0
  48. package/dist/platform/migrations/0001_init.sql +59 -0
  49. package/dist/platform/migrations/0002_users_settings.sql +34 -0
  50. package/dist/platform/migrations/0003_people_organisations.sql +225 -0
  51. package/dist/platform/migrations/0004_activities_tasks.sql +88 -0
  52. package/dist/platform/migrations/0005_views_audit.sql +79 -0
  53. package/dist/platform/migrations/0006_search.sql +223 -0
  54. package/dist/platform/migrations/0007_crm_views.sql +141 -0
  55. package/dist/platform/migrations/0008_audit_redaction.sql +116 -0
  56. package/dist/platform/migrations/0010_approval_queue.sql +90 -0
  57. package/dist/platform/migrations/0011_connected_apps.sql +36 -0
  58. package/dist/platform/migrations/0020_extensions.sql +373 -0
  59. package/dist/platform/migrations/0030_extension_proposals.sql +29 -0
  60. package/dist/platform/migrations/0050_live_row_indexes.sql +32 -0
  61. package/dist/platform/migrations/0060_audit_read_counts.sql +31 -0
  62. package/dist/platform/migrations/0061_audit_retention.sql +95 -0
  63. package/dist/platform/migrations/0062_run_history_retention.sql +6 -0
  64. package/dist/platform/migrations/0063_pending_action_compaction.sql +18 -0
  65. package/dist/platform/migrations/0064_drop_rate_limit.sql +6 -0
  66. package/dist/platform/migrations/0065_storage_stats.sql +13 -0
  67. package/dist/platform/migrations/0070_drop_proposals_ext_idx.sql +9 -0
  68. package/dist/platform/migrations/0080_views_dashboards.sql +46 -0
  69. package/dist/platform/migrations/0100_stage_history.sql +54 -0
  70. package/dist/platform/migrations/0110_integrations.sql +103 -0
  71. package/dist/platform/migrations/0111_email_calendar_sync.sql +137 -0
  72. package/dist/platform/migrations/0112_sync_item_occurred_at.sql +8 -0
  73. package/dist/platform/migrations/0130_automations.sql +113 -0
  74. package/dist/platform/migrations/0131_notifications.sql +29 -0
  75. package/dist/platform/migrations/0132_automation_runtime.sql +14 -0
  76. package/dist/platform/migrations/0150_ai_summaries_embeddings.sql +48 -0
  77. package/dist/platform/migrations/0160_releases.sql +41 -0
  78. package/dist/platform/migrations/0161_setup_wizard.sql +30 -0
  79. package/dist/platform/migrations/0170_automation_connections.sql +32 -0
  80. package/dist/platform/migrations/0171_automation_outbox.sql +23 -0
  81. package/dist/platform/migrations/0172_notification_delivery.sql +46 -0
  82. package/dist/platform/migrations/0200_assistant_conversations.sql +25 -0
  83. package/dist/platform/migrations/0205_policy_adjudicator.sql +61 -0
  84. package/dist/platform/migrations/0210_daily_digest.sql +33 -0
  85. package/dist/platform/migrations/0220_entitlements.sql +13 -0
  86. package/dist/platform/migrations/0221_support_grants.sql +33 -0
  87. package/dist/platform/migrations/0250_judge.sql +11 -0
  88. package/dist/platform/migrations/0251_adjudication_judgement.sql +8 -0
  89. package/dist/platform/migrations/0252_judge_usage.sql +14 -0
  90. package/dist/platform/migrations/0255_summary_checks.sql +9 -0
  91. package/dist/platform/migrations/0256_outbound_check.sql +9 -0
  92. package/dist/platform/migrations/0260_ai_usage.sql +20 -0
  93. package/dist/platform/migrations/0270_assistant_conversation_refs.sql +29 -0
  94. package/dist/platform/migrations/0310_assignment_rules.sql +54 -0
  95. package/dist/platform/migrations/0320_duplicates.sql +41 -0
  96. package/dist/platform/migrations/0330_erase_completeness.sql +54 -0
  97. package/dist/platform/migrations/0350_assistant_thread.sql +38 -0
  98. package/dist/platform/migrations/0351_assistant_model_roles.sql +26 -0
  99. package/dist/platform/migrations/0352_assistant_memory.sql +74 -0
  100. package/dist/platform/migrations/0358_ai_cache_observation.sql +24 -0
  101. package/dist/platform/migrations/0359_ai_compaction_decision.sql +25 -0
  102. package/dist/platform/migrations/0360_ai_cache_estimate.sql +35 -0
  103. package/dist/platform/migrations/0361_voice_preferences.sql +27 -0
  104. package/dist/platform/migrations/0362_voice_usage.sql +17 -0
  105. package/dist/platform/migrations/0365_routines.sql +38 -0
  106. package/dist/platform/migrations/0370_approval_execution.sql +20 -0
  107. package/dist/platform/migrations/0371_agent_jobs.sql +65 -0
  108. package/dist/platform/migrations/0380_rec_views.sql +94 -0
  109. package/dist/platform/migrations/0400_customer_audit_actor.sql +142 -0
  110. package/dist/platform/migrations/0401_customer_accounts.sql +61 -0
  111. package/dist/platform/migrations/0402_erase_requests.sql +34 -0
  112. package/dist/platform/migrations/0410_idempotency_keys.sql +45 -0
  113. package/dist/platform/migrations/0411_device_sessions.sql +33 -0
  114. package/dist/platform/migrations/0420_transition_history.sql +100 -0
  115. package/dist/platform/migrations/0421_orders.sql +134 -0
  116. package/dist/platform/migrations/0422_order_payments.sql +109 -0
  117. package/dist/platform/migrations/0440_capacity.sql +100 -0
  118. package/dist/platform/migrations/0441_capacity_views.sql +40 -0
  119. package/dist/platform/migrations/0450_order_grants.sql +21 -0
  120. package/dist/platform/migrations/0451_pack_roles.sql +18 -0
  121. package/dist/platform/migrations/0460_content.sql +59 -0
  122. package/dist/platform/migrations/0461_media.sql +52 -0
  123. package/dist/platform/migrations/0470_publish_versions.sql +36 -0
  124. package/dist/platform/migrations/0471_permission_grants.sql +18 -0
  125. package/dist/platform/migrations/0490_staff_invites.sql +40 -0
  126. package/dist/platform/migrations/0491_sign_in_mail_kind.sql +10 -0
  127. package/dist/platform/migrations/0492_email_confirmation_and_sign_in_confirm.sql +30 -0
  128. package/dist/platform/migrations/0500_published_media_field.sql +25 -0
  129. package/dist/platform/migrations/0501_import_keys.sql +23 -0
  130. package/dist/platform/migrations/0510_video_and_file_media.sql +109 -0
  131. package/dist/platform/migrations/0516_order_tax.sql +63 -0
  132. package/dist/platform/migrations/0520_publish_requests.sql +20 -0
  133. package/dist/platform/migrations/0530_subscriptions.sql +173 -0
  134. package/dist/platform/migrations/0531_subscription_trials.sql +56 -0
  135. package/dist/platform/migrations/0532_subscription_offers.sql +80 -0
  136. package/dist/platform/migrations/0533_allowances.sql +262 -0
  137. package/dist/platform/migrations/0560_recurring.sql +75 -0
  138. package/dist/platform/migrations/0580_subscription_grants.sql +21 -0
  139. package/dist/platform/migrations/0581_once_per_person.sql +34 -0
  140. package/dist/platform/migrations/0600_tool_actions_ran_at_queue.sql +22 -0
  141. package/dist/platform/sdk/allowance.ts +522 -0
  142. package/dist/platform/sdk/automation-check.ts +534 -0
  143. package/dist/platform/sdk/automation.ts +743 -0
  144. package/dist/platform/sdk/behaviour.ts +215 -0
  145. package/dist/platform/sdk/capacity.ts +201 -0
  146. package/dist/platform/sdk/contract.ts +884 -0
  147. package/dist/platform/sdk/document.ts +935 -0
  148. package/dist/platform/sdk/field-types.ts +111 -0
  149. package/dist/platform/sdk/formula/ast.ts +72 -0
  150. package/dist/platform/sdk/formula/compile.ts +454 -0
  151. package/dist/platform/sdk/formula/index.ts +4 -0
  152. package/dist/platform/sdk/formula/parser.ts +417 -0
  153. package/dist/platform/sdk/index.ts +36 -0
  154. package/dist/platform/sdk/manifest.ts +1709 -0
  155. package/dist/platform/sdk/media.ts +108 -0
  156. package/dist/platform/sdk/permissions.ts +60 -0
  157. package/dist/platform/sdk/recurring.ts +321 -0
  158. package/dist/platform/sdk/renamed.ts +63 -0
  159. package/dist/platform/sdk/rich-text-fixture.ts +68 -0
  160. package/dist/platform/sdk/rich-text.ts +221 -0
  161. package/dist/platform/sdk/runtime.ts +410 -0
  162. package/dist/platform/sdk/sellable.ts +888 -0
  163. package/dist/platform/sdk/slug.ts +25 -0
  164. package/dist/platform/sdk/states.ts +484 -0
  165. package/dist/platform/sdk/testing.ts +847 -0
  166. package/dist/platform/sdk/unique.ts +81 -0
  167. package/dist/products-2H5DR232.js +11 -0
  168. package/dist/run-PZUCSDDL.js +508 -0
  169. package/dist/run-RT2HVWMK.js +648 -0
  170. package/dist/run-Y7T4TVOL.js +309 -0
  171. package/dist/src-GYS6NBQB.js +44 -0
  172. package/dist/src-XTOD7EXW.js +348 -0
  173. package/dist/token-MOJUA2U6.js +70 -0
  174. package/dist/token-util-TENRN4V7.js +6 -0
  175. package/dist/visibility-DLGHU4YN.js +33 -0
  176. 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
- # Temporary Holding Version
1
+ # create-composable-os
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
+ 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,46 @@
1
+ #!/usr/bin/env node
2
+ import {
3
+ CUSTOMER_LINK_AUDIT,
4
+ creatorFor,
5
+ customerCodeReason,
6
+ customerMayGetCode,
7
+ customerSignedInStatement,
8
+ hasBought,
9
+ inviteCustomer,
10
+ inviteCustomerStatement,
11
+ linkCustomer,
12
+ loadCustomer,
13
+ loadCustomerByEmail,
14
+ loadCustomerSignIn,
15
+ normaliseCustomerEmail,
16
+ sameEmailPeople
17
+ } from "./chunk-GYSGVT6R.js";
18
+ import "./chunk-VY64DMQO.js";
19
+ import "./chunk-Z3RMMB6S.js";
20
+ import "./chunk-6GDEDOV7.js";
21
+ import "./chunk-QGGJ2G6Z.js";
22
+ import "./chunk-K6T42YCH.js";
23
+ import "./chunk-TQFGGSA4.js";
24
+ import "./chunk-KGHA67HG.js";
25
+ import "./chunk-6UWRT4VM.js";
26
+ import "./chunk-A4NTSYWV.js";
27
+ import "./chunk-IFG4FRW5.js";
28
+ import "./chunk-Q4N55M2Z.js";
29
+ import "./chunk-CP6BXI6F.js";
30
+ import "./chunk-5KSXSK7Y.js";
31
+ export {
32
+ CUSTOMER_LINK_AUDIT,
33
+ creatorFor,
34
+ customerCodeReason,
35
+ customerMayGetCode,
36
+ customerSignedInStatement,
37
+ hasBought,
38
+ inviteCustomer,
39
+ inviteCustomerStatement,
40
+ linkCustomer,
41
+ loadCustomer,
42
+ loadCustomerByEmail,
43
+ loadCustomerSignIn,
44
+ normaliseCustomerEmail,
45
+ sameEmailPeople
46
+ };
@@ -0,0 +1,233 @@
1
+ #!/usr/bin/env node
2
+ import {
3
+ fetchKit,
4
+ lineDiff,
5
+ loadClientProduct
6
+ } from "./chunk-Y7JZFSTQ.js";
7
+ import {
8
+ CliError,
9
+ str
10
+ } from "./chunk-6VXHPKGG.js";
11
+ import "./chunk-DU6OIFOU.js";
12
+ import "./chunk-KGHA67HG.js";
13
+ import "./chunk-2ABSVMGB.js";
14
+ import "./chunk-6UWRT4VM.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
+ };
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env node
2
+ import {
3
+ product
4
+ } from "./chunk-6UWRT4VM.js";
5
+
6
+ // ../../products/index.ts
7
+ var products = { [product.id]: product };
8
+ var DEFAULT_PRODUCT = product.id;
9
+
10
+ export {
11
+ products,
12
+ DEFAULT_PRODUCT
13
+ };
@@ -0,0 +1,47 @@
1
+ #!/usr/bin/env node
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
9
+ get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
10
+ }) : x)(function(x) {
11
+ if (typeof require !== "undefined") return require.apply(this, arguments);
12
+ throw Error('Dynamic require of "' + x + '" is not supported');
13
+ });
14
+ var __commonJS = (cb, mod) => function __require2() {
15
+ try {
16
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
17
+ } catch (e) {
18
+ throw mod = 0, e;
19
+ }
20
+ };
21
+ var __export = (target, all) => {
22
+ for (var name in all)
23
+ __defProp(target, name, { get: all[name], enumerable: true });
24
+ };
25
+ var __copyProps = (to, from, except, desc) => {
26
+ if (from && typeof from === "object" || typeof from === "function") {
27
+ for (let key of __getOwnPropNames(from))
28
+ if (!__hasOwnProp.call(to, key) && key !== except)
29
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
30
+ }
31
+ return to;
32
+ };
33
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
34
+ // If the importer is in node compatibility mode or this is not an ESM
35
+ // file that has been converted to a CommonJS file using a Babel-
36
+ // compatible transform (i.e. "__esModule" has not been set), then set
37
+ // "default" to the CommonJS "module.exports" for node compatibility.
38
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
39
+ mod
40
+ ));
41
+
42
+ export {
43
+ __require,
44
+ __commonJS,
45
+ __export,
46
+ __toESM
47
+ };
@@ -0,0 +1,157 @@
1
+ #!/usr/bin/env node
2
+ import {
3
+ ACTORS,
4
+ PERMISSIONS,
5
+ RISK_CLASSES
6
+ } from "./chunk-A4NTSYWV.js";
7
+
8
+ // ../core/src/audiences.ts
9
+ var AUDIENCES = ["staff", "customer", "public"];
10
+ var DEFAULT_AUDIENCES = Object.freeze(["staff"]);
11
+ var OUTSIDE_RISK_CLASSES = Object.freeze(["read", "write"]);
12
+ function audiencesOf(op) {
13
+ return op.audiences ?? DEFAULT_AUDIENCES;
14
+ }
15
+ function isOpenOutside(op) {
16
+ return audiencesOf(op).some((audience) => audience !== "staff");
17
+ }
18
+ function audienceOf(principal) {
19
+ return principal.kind;
20
+ }
21
+ function allowsAudience(op, principal) {
22
+ return audiencesOf(op).includes(audienceOf(principal));
23
+ }
24
+ function audienceProblems(op) {
25
+ const problems = [];
26
+ const declared = op.audiences;
27
+ if (declared !== void 0) {
28
+ if (!Array.isArray(declared) || declared.length === 0) {
29
+ problems.push("audiences must list at least one of staff, customer, public");
30
+ return problems;
31
+ }
32
+ if (declared.some((a) => !AUDIENCES.includes(a))) {
33
+ problems.push("audiences must be a subset of staff, customer, public");
34
+ return problems;
35
+ }
36
+ if (new Set(declared).size !== declared.length) problems.push("audiences lists one twice");
37
+ }
38
+ if (isOpenOutside(op) && !OUTSIDE_RISK_CLASSES.includes(op.risk)) {
39
+ const who = audiencesOf(op).filter((a) => a !== "staff");
40
+ problems.push(
41
+ `an operation open to ${who.join(" and ")} callers must have risk class read or write, not ${op.risk} (ADR 0402)`
42
+ );
43
+ }
44
+ return problems;
45
+ }
46
+ function packOf(name) {
47
+ const [first, id] = name.split(".");
48
+ return first === "x" && id ? id : void 0;
49
+ }
50
+ function forPacks(file, installed) {
51
+ return {
52
+ ...file,
53
+ operations: file.operations.filter((op) => {
54
+ const pack = op.pack ?? packOf(op.name);
55
+ return pack === void 0 || installed.includes(pack);
56
+ }).map(({ pack: _pack, ...op }) => op)
57
+ };
58
+ }
59
+
60
+ // ../core/src/operation.ts
61
+ var AFTER_COMMIT = /* @__PURE__ */ Symbol("afterCommit");
62
+ function afterCommit(read) {
63
+ return { [AFTER_COMMIT]: read };
64
+ }
65
+ function isAfterCommit(value) {
66
+ return typeof value === "object" && value !== null && AFTER_COMMIT in value;
67
+ }
68
+ function runAfterCommit(value) {
69
+ return value[AFTER_COMMIT]();
70
+ }
71
+ function recordHostChange(ctx, change) {
72
+ (ctx.recordHostChange ?? ctx.recordChange)(change);
73
+ }
74
+ function personsTool(ctx, extensionId) {
75
+ const caller = ctx.extension;
76
+ if (!caller || !extensionId || caller.id !== extensionId) return null;
77
+ const tool = caller.tool;
78
+ return tool?.humanOnly && tool.permission ? tool.name : null;
79
+ }
80
+ var HOST_TOOLS = /* @__PURE__ */ new WeakSet();
81
+ function markHostTool(op) {
82
+ HOST_TOOLS.add(op);
83
+ }
84
+ function isHostTool(op) {
85
+ return HOST_TOOLS.has(op);
86
+ }
87
+ var OPERATION_NAME_RE = /^[a-z][a-zA-Z0-9]*(\.[a-z][a-zA-Z0-9]*)+$/;
88
+ function defineOperation(definition) {
89
+ const problems = operationProblems(definition);
90
+ if (problems.length) {
91
+ throw new Error(`Operation ${definition.name}: ${problems.join("; ")}`);
92
+ }
93
+ return Object.freeze({ ...definition });
94
+ }
95
+ function operationProblems(op) {
96
+ const problems = [];
97
+ if (!OPERATION_NAME_RE.test(op.name ?? "")) problems.push("name must be <object>.<verb>");
98
+ if (typeof op.description !== "string" || op.description.trim().length < 20) {
99
+ problems.push("description must explain what it does, when to use it and side effects");
100
+ }
101
+ if (!op.input || typeof op.input.safeParse !== "function") problems.push("input schema missing");
102
+ if (!op.output || typeof op.output.safeParse !== "function") {
103
+ problems.push("output schema missing");
104
+ }
105
+ if (!PERMISSIONS.includes(op.permission)) problems.push("permission missing or unknown");
106
+ if (op.packPermission !== void 0) {
107
+ const extension = /^x\.([a-z][a-z0-9]{1,29})\./.exec(op.name ?? "")?.[1];
108
+ if (!extension) problems.push("packPermission is for extension tools only");
109
+ else if (!op.packPermission.startsWith(`${extension}:`)) {
110
+ problems.push(`packPermission is named ${extension}:<word>`);
111
+ }
112
+ }
113
+ if (!RISK_CLASSES.includes(op.risk)) problems.push("risk class missing or unknown");
114
+ if (op.actors && (op.actors.length === 0 || op.actors.some((a) => !ACTORS.includes(a)))) {
115
+ problems.push("actors must list known actor types");
116
+ }
117
+ if (typeof op.handler !== "function") problems.push("handler missing");
118
+ problems.push(...audienceProblems(op));
119
+ if (op.hostInternal !== void 0) {
120
+ if (op.hostInternal !== true) problems.push("hostInternal is true or left out");
121
+ if (op.name?.startsWith("x.")) problems.push("an extension tool can never be hostInternal");
122
+ if (!isOpenOutside(op)) {
123
+ problems.push("hostInternal is only for an operation open to customer or public callers");
124
+ }
125
+ }
126
+ if (op.toolOnly !== void 0) {
127
+ if (op.toolOnly !== true) problems.push("toolOnly is true or left out");
128
+ if (op.name?.startsWith("x.")) problems.push("an extension tool cannot be toolOnly");
129
+ if (!audiencesOf(op).includes("customer")) {
130
+ problems.push("toolOnly is only for an operation open to customer callers");
131
+ }
132
+ }
133
+ if (isOpenOutside(op) && op.alwaysReview) {
134
+ problems.push("an operation open to customer or public callers is never queued for review");
135
+ }
136
+ if ((op.risk === "bulk-write" || op.risk === "destructive") && op.name.endsWith("Many")) {
137
+ if (typeof op.bulkSize !== "function") problems.push("batch operations need bulkSize");
138
+ }
139
+ return problems;
140
+ }
141
+
142
+ export {
143
+ AUDIENCES,
144
+ OUTSIDE_RISK_CLASSES,
145
+ audiencesOf,
146
+ allowsAudience,
147
+ forPacks,
148
+ afterCommit,
149
+ isAfterCommit,
150
+ runAfterCommit,
151
+ recordHostChange,
152
+ personsTool,
153
+ markHostTool,
154
+ isHostTool,
155
+ defineOperation,
156
+ operationProblems
157
+ };