opkg 0.5.0 → 0.6.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/README.md +49 -8
- package/dist/commands/add.js +11 -276
- package/dist/commands/add.js.map +1 -1
- package/dist/commands/init.js +73 -145
- package/dist/commands/init.js.map +1 -1
- package/dist/commands/install.js +26 -668
- package/dist/commands/install.js.map +1 -1
- package/dist/commands/pack.js +10 -137
- package/dist/commands/pack.js.map +1 -1
- package/dist/commands/push.js +14 -8
- package/dist/commands/push.js.map +1 -1
- package/dist/commands/save.js +12 -167
- package/dist/commands/save.js.map +1 -1
- package/dist/commands/status.js +2 -2
- package/dist/commands/status.js.map +1 -1
- package/dist/commands/uninstall.js +5 -5
- package/dist/commands/uninstall.js.map +1 -1
- package/dist/constants/index.js +18 -45
- package/dist/constants/index.js.map +1 -1
- package/dist/constants/workspace.js +9 -0
- package/dist/constants/workspace.js.map +1 -0
- package/dist/core/add/add-conflict-handler.js +68 -0
- package/dist/core/add/add-conflict-handler.js.map +1 -0
- package/dist/core/add/add-pipeline.js +137 -0
- package/dist/core/add/add-pipeline.js.map +1 -0
- package/dist/core/add/package-index-updater.js +62 -33
- package/dist/core/add/package-index-updater.js.map +1 -1
- package/dist/core/add/platform-path-transformer.js +47 -0
- package/dist/core/add/platform-path-transformer.js.map +1 -0
- package/dist/core/add/source-collector.js +57 -0
- package/dist/core/add/source-collector.js.map +1 -0
- package/dist/core/dependency-resolver.js +3 -1
- package/dist/core/dependency-resolver.js.map +1 -1
- package/dist/core/directory.js +2 -2
- package/dist/core/directory.js.map +1 -1
- package/dist/core/discovery/file-discovery.js +55 -54
- package/dist/core/discovery/file-discovery.js.map +1 -1
- package/dist/core/discovery/platform-files-discovery.js +32 -17
- package/dist/core/discovery/platform-files-discovery.js.map +1 -1
- package/dist/core/install/bulk-install-pipeline.js +199 -0
- package/dist/core/install/bulk-install-pipeline.js.map +1 -0
- package/dist/core/install/canonical-plan.js +123 -0
- package/dist/core/install/canonical-plan.js.map +1 -0
- package/dist/core/install/dry-run.js +2 -2
- package/dist/core/install/dry-run.js.map +1 -1
- package/dist/core/install/index.js +3 -0
- package/dist/core/install/index.js.map +1 -0
- package/dist/core/install/install-errors.js +41 -0
- package/dist/core/install/install-errors.js.map +1 -0
- package/dist/core/install/install-flow.js +2 -5
- package/dist/core/install/install-flow.js.map +1 -1
- package/dist/core/install/install-pipeline.js +228 -0
- package/dist/core/install/install-pipeline.js.map +1 -0
- package/dist/core/install/install-reporting.js +99 -0
- package/dist/core/install/install-reporting.js.map +1 -0
- package/dist/core/install/platform-resolution.js +6 -6
- package/dist/core/install/platform-resolution.js.map +1 -1
- package/dist/core/install/remote-flow.js +67 -1
- package/dist/core/install/remote-flow.js.map +1 -1
- package/dist/core/openpackage.js +16 -8
- package/dist/core/openpackage.js.map +1 -1
- package/dist/core/package-context.js +246 -0
- package/dist/core/package-context.js.map +1 -0
- package/dist/core/package.js +3 -2
- package/dist/core/package.js.map +1 -1
- package/dist/core/platforms.js +126 -217
- package/dist/core/platforms.js.map +1 -1
- package/dist/core/registry/registry-rename.js +2 -1
- package/dist/core/registry/registry-rename.js.map +1 -1
- package/dist/core/registry.js +10 -3
- package/dist/core/registry.js.map +1 -1
- package/dist/core/remote-pull.js +2 -1
- package/dist/core/remote-pull.js.map +1 -1
- package/dist/core/save/constants.js +4 -0
- package/dist/core/save/constants.js.map +1 -1
- package/dist/core/save/name-resolution.js +31 -0
- package/dist/core/save/name-resolution.js.map +1 -0
- package/dist/core/save/package-detection.js +147 -0
- package/dist/core/save/package-detection.js.map +1 -0
- package/dist/core/save/package-saver.js +46 -43
- package/dist/core/save/package-saver.js.map +1 -1
- package/dist/core/save/package-yml-generator.js +50 -71
- package/dist/core/save/package-yml-generator.js.map +1 -1
- package/dist/core/save/root-save-candidates.js.map +1 -1
- package/dist/core/save/save-candidate-loader.js +89 -0
- package/dist/core/save/save-candidate-loader.js.map +1 -0
- package/dist/core/save/save-conflict-resolution.js +72 -410
- package/dist/core/save/save-conflict-resolution.js.map +1 -1
- package/dist/core/save/save-conflict-resolver.js +277 -0
- package/dist/core/save/save-conflict-resolver.js.map +1 -0
- package/dist/core/save/save-pipeline.js +151 -0
- package/dist/core/save/save-pipeline.js.map +1 -0
- package/dist/core/save/save-types.js +2 -0
- package/dist/core/save/save-types.js.map +1 -0
- package/dist/core/save/save-yml-resolution.js +77 -39
- package/dist/core/save/save-yml-resolution.js.map +1 -1
- package/dist/core/save/workspace-rename.js +6 -6
- package/dist/core/save/workspace-rename.js.map +1 -1
- package/dist/core/scoping/package-scoping.js +13 -1
- package/dist/core/scoping/package-scoping.js.map +1 -1
- package/dist/core/status/status-file-discovery.js +12 -30
- package/dist/core/status/status-file-discovery.js.map +1 -1
- package/dist/core/sync/platform-sync.js +7 -4
- package/dist/core/sync/platform-sync.js.map +1 -1
- package/dist/core/sync/root-files-sync.js +59 -1
- package/dist/core/sync/root-files-sync.js.map +1 -1
- package/dist/core/uninstall/uninstall-file-discovery.js +1 -2
- package/dist/core/uninstall/uninstall-file-discovery.js.map +1 -1
- package/dist/types/index.js.map +1 -1
- package/dist/utils/file-processing.js +5 -58
- package/dist/utils/file-processing.js.map +1 -1
- package/dist/utils/index-based-installer.js +15 -33
- package/dist/utils/index-based-installer.js.map +1 -1
- package/dist/utils/install-file-discovery.js +3 -3
- package/dist/utils/install-file-discovery.js.map +1 -1
- package/dist/utils/install-orchestrator.js +21 -21
- package/dist/utils/install-orchestrator.js.map +1 -1
- package/dist/utils/jsonc.js +44 -0
- package/dist/utils/jsonc.js.map +1 -0
- package/dist/utils/package-copy.js +199 -0
- package/dist/utils/package-copy.js.map +1 -0
- package/dist/utils/package-filters.js +125 -0
- package/dist/utils/package-filters.js.map +1 -0
- package/dist/utils/package-index-yml.js +15 -10
- package/dist/utils/package-index-yml.js.map +1 -1
- package/dist/utils/package-installation.js +4 -113
- package/dist/utils/package-installation.js.map +1 -1
- package/dist/utils/package-local-files.js +2 -35
- package/dist/utils/package-local-files.js.map +1 -1
- package/dist/utils/package-management.js +59 -37
- package/dist/utils/package-management.js.map +1 -1
- package/dist/utils/package-yml.js +24 -0
- package/dist/utils/package-yml.js.map +1 -1
- package/dist/utils/path-normalization.js +8 -53
- package/dist/utils/path-normalization.js.map +1 -1
- package/dist/utils/paths.js +17 -9
- package/dist/utils/paths.js.map +1 -1
- package/dist/utils/platform-file.js +16 -59
- package/dist/utils/platform-file.js.map +1 -1
- package/dist/utils/platform-mapper.js +29 -41
- package/dist/utils/platform-mapper.js.map +1 -1
- package/dist/utils/platform-specific-paths.js.map +1 -1
- package/dist/utils/platform-utils.js +28 -139
- package/dist/utils/platform-utils.js.map +1 -1
- package/dist/utils/platform-yaml-merge.js +13 -6
- package/dist/utils/platform-yaml-merge.js.map +1 -1
- package/dist/utils/registry-entry-filter.js +38 -24
- package/dist/utils/registry-entry-filter.js.map +1 -1
- package/dist/utils/registry-paths.js +10 -0
- package/dist/utils/registry-paths.js.map +1 -0
- package/dist/utils/root-file-installer.js +19 -0
- package/dist/utils/root-file-installer.js.map +1 -1
- package/dist/utils/root-file-registry.js.map +1 -1
- package/package.json +3 -2
- package/platforms.jsonc +178 -0
- package/specs/package/README.md +60 -0
- package/specs/package/nested-packages-and-parent-packages.md +79 -0
- package/specs/package/package-index-yml.md +171 -0
- package/specs/package/package-root-layout.md +78 -0
- package/specs/package/registry-payload-and-copy.md +77 -0
- package/specs/package/universal-content.md +144 -0
- package/specs/platforms.md +193 -0
- package/specs/save/README.md +40 -0
- package/specs/save/save-conflict-resolution.md +146 -0
- package/specs/save/save-file-discovery.md +101 -0
- package/specs/save/save-frontmatter-overrides.md +81 -0
- package/specs/save/save-modes-inputs.md +53 -0
- package/specs/save/save-naming-scoping.md +93 -0
- package/specs/save/save-package-detection.md +60 -0
- package/specs/save/save-registry-sync.md +126 -0
- package/dist/commands/release.js +0 -33
- package/dist/commands/release.js.map +0 -1
- package/dist/commands/tag.js +0 -311
- package/dist/commands/tag.js.map +0 -1
- package/dist/commands/update.js +0 -30
- package/dist/commands/update.js.map +0 -1
- package/dist/core/add/formula-index-updater.js +0 -290
- package/dist/core/add/formula-index-updater.js.map +0 -1
- package/dist/core/discovery/ai-files-discovery.js +0 -2
- package/dist/core/discovery/ai-files-discovery.js.map +0 -1
- package/dist/core/discovery/formula-files-discovery.js +0 -14
- package/dist/core/discovery/formula-files-discovery.js.map +0 -1
- package/dist/core/discovery/index-files-discovery.js +0 -91
- package/dist/core/discovery/index-files-discovery.js.map +0 -1
- package/dist/core/discovery/md-files-discovery.js +0 -82
- package/dist/core/discovery/md-files-discovery.js.map +0 -1
- package/dist/core/discovery/package-files-discovery.js +0 -14
- package/dist/core/discovery/package-files-discovery.js.map +0 -1
- package/dist/core/discovery/platform-discovery.js +0 -84
- package/dist/core/discovery/platform-discovery.js.map +0 -1
- package/dist/core/discovery/root-files-discovery.js +0 -2
- package/dist/core/discovery/root-files-discovery.js.map +0 -1
- package/dist/core/formula.js +0 -170
- package/dist/core/formula.js.map +0 -1
- package/dist/core/git-registry.js +0 -46
- package/dist/core/git-registry.js.map +0 -1
- package/dist/core/groundzero.js +0 -277
- package/dist/core/groundzero.js.map +0 -1
- package/dist/core/install/scenario.js +0 -11
- package/dist/core/install/scenario.js.map +0 -1
- package/dist/core/package-sync.js +0 -219
- package/dist/core/package-sync.js.map +0 -1
- package/dist/core/save/formula-file-generator.js +0 -167
- package/dist/core/save/formula-file-generator.js.map +0 -1
- package/dist/core/save/formula-saver.js +0 -52
- package/dist/core/save/formula-saver.js.map +0 -1
- package/dist/core/save/formula-yml-generator.js +0 -89
- package/dist/core/save/formula-yml-generator.js.map +0 -1
- package/dist/core/save/formula-yml-versioning.js +0 -108
- package/dist/core/save/formula-yml-versioning.js.map +0 -1
- package/dist/core/save/generic-file-sync.js +0 -38
- package/dist/core/save/generic-file-sync.js.map +0 -1
- package/dist/core/save/md-files-sync.js +0 -33
- package/dist/core/save/md-files-sync.js.map +0 -1
- package/dist/core/save/package-yml-versioning.js +0 -108
- package/dist/core/save/package-yml-versioning.js.map +0 -1
- package/dist/core/save/platform-sync.js +0 -95
- package/dist/core/save/platform-sync.js.map +0 -1
- package/dist/core/save/root-files-sync.js +0 -140
- package/dist/core/save/root-files-sync.js.map +0 -1
- package/dist/core/save/save-candidate-types.js +0 -2
- package/dist/core/save/save-candidate-types.js.map +0 -1
- package/dist/core/save/save-conflict-types.js +0 -2
- package/dist/core/save/save-conflict-types.js.map +0 -1
- package/dist/core/save/save-file-discovery.js +0 -5
- package/dist/core/save/save-file-discovery.js.map +0 -1
- package/dist/core/status-file-discovery.js +0 -175
- package/dist/core/status-file-discovery.js.map +0 -1
- package/dist/utils/discovery/file-processing.js +0 -156
- package/dist/utils/discovery/file-processing.js.map +0 -1
- package/dist/utils/discovery/formula-discovery.js +0 -211
- package/dist/utils/discovery/formula-discovery.js.map +0 -1
- package/dist/utils/discovery/platform-discovery.js +0 -2
- package/dist/utils/discovery/platform-discovery.js.map +0 -1
- package/dist/utils/formula-discovery.js +0 -102
- package/dist/utils/formula-discovery.js.map +0 -1
- package/dist/utils/formula-index-yml.js +0 -122
- package/dist/utils/formula-index-yml.js.map +0 -1
- package/dist/utils/formula-installation.js +0 -110
- package/dist/utils/formula-installation.js.map +0 -1
- package/dist/utils/formula-local-files.js +0 -38
- package/dist/utils/formula-local-files.js.map +0 -1
- package/dist/utils/formula-management.js +0 -191
- package/dist/utils/formula-management.js.map +0 -1
- package/dist/utils/formula-name.js +0 -97
- package/dist/utils/formula-name.js.map +0 -1
- package/dist/utils/formula-versioning.js +0 -109
- package/dist/utils/formula-versioning.js.map +0 -1
- package/dist/utils/formula-yml.js +0 -82
- package/dist/utils/formula-yml.js.map +0 -1
- package/dist/utils/git.js +0 -54
- package/dist/utils/git.js.map +0 -1
- package/dist/utils/id-based-discovery.js +0 -126
- package/dist/utils/id-based-discovery.js.map +0 -1
- package/dist/utils/id-based-installer.js +0 -249
- package/dist/utils/id-based-installer.js.map +0 -1
- package/dist/utils/index-yml-based-installer.js +0 -375
- package/dist/utils/index-yml-based-installer.js.map +0 -1
- package/dist/utils/index-yml.js +0 -124
- package/dist/utils/index-yml.js.map +0 -1
- package/dist/utils/md-frontmatter.js +0 -3
- package/dist/utils/md-frontmatter.js.map +0 -1
- package/dist/utils/package-link-yml.js +0 -92
- package/dist/utils/package-link-yml.js.map +0 -1
- package/dist/utils/platform-discovery.js +0 -2
- package/dist/utils/platform-discovery.js.map +0 -1
- package/dist/utils/platform-frontmatter-split.js +0 -15
- package/dist/utils/platform-frontmatter-split.js.map +0 -1
- package/dist/utils/timestamp-encoder.js +0 -13
- package/dist/utils/timestamp-encoder.js.map +0 -1
- package/dist/utils/wip-versioning.js +0 -24
- package/dist/utils/wip-versioning.js.map +0 -1
package/README.md
CHANGED
|
@@ -90,23 +90,38 @@ opkg install mongodb
|
|
|
90
90
|
## Usage
|
|
91
91
|
|
|
92
92
|
> [!TIP]
|
|
93
|
-
>
|
|
93
|
+
> We highly recommend reading [the packages doc](https://openpackage.dev/docs/packages) to understand how packages work.
|
|
94
94
|
|
|
95
|
-
###
|
|
95
|
+
### Create a package
|
|
96
|
+
|
|
97
|
+
#### In a project/workspace
|
|
98
|
+
```bash title="Terminal"
|
|
99
|
+
opkg init <package>
|
|
100
|
+
```
|
|
101
|
+
Initializes a package at `.openpackage/packages/<package>/` and generates the package's `package.yml` manifest file. This method is ideal for creating/managing multiple packages within existing projects.
|
|
96
102
|
```bash title="Terminal"
|
|
97
103
|
opkg add <package> <path-to-dir-or-file>
|
|
98
104
|
```
|
|
99
|
-
|
|
105
|
+
Use the `add` command to add files from the workspace to a package. You can also directly create/update the package files in `.openpackage/packages/<package>/` (see Package Structure below for details).
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
#### In a dedicated codebase for the package
|
|
109
|
+
```bash title="Terminal"
|
|
110
|
+
opkg init
|
|
111
|
+
```
|
|
112
|
+
Initializes a package at cwd and generates the package's `package.yml` manifest file. Use this to dedicate the codebase to the package itself (see Package Structure below for details on structuring a package).
|
|
113
|
+
|
|
100
114
|
|
|
101
115
|
### Save a package
|
|
102
116
|
```bash title="Terminal"
|
|
103
|
-
opkg save
|
|
117
|
+
opkg save [package]
|
|
104
118
|
```
|
|
105
|
-
Save the set of dirs and files as a package for reuse and cross-platform sync (prerelease).
|
|
119
|
+
Save the set of dirs and files as a package for reuse and cross-platform sync (prerelease).
|
|
120
|
+
Also performs sync of universal subdir content across detected AI coding platform dirs.
|
|
106
121
|
|
|
107
122
|
### Finalize/pack a package
|
|
108
123
|
```bash title="Terminal"
|
|
109
|
-
opkg pack
|
|
124
|
+
opkg pack [package]
|
|
110
125
|
```
|
|
111
126
|
Save the package as a stable non-prerelease version ready for push (upload).
|
|
112
127
|
|
|
@@ -149,13 +164,39 @@ Use the `pull` command to download a package from the [official OpenPackage regi
|
|
|
149
164
|
> [!TIP]
|
|
150
165
|
> Learn more by heading over to the [official docs](https://openpackage.dev/docs).
|
|
151
166
|
|
|
167
|
+
## Package Structure
|
|
168
|
+
|
|
169
|
+
Packages are composed using the following directory structure:
|
|
170
|
+
|
|
171
|
+
```txt title="Structure"
|
|
172
|
+
<package>
|
|
173
|
+
├── .openpackage
|
|
174
|
+
│ ├── package.yml # The OpenPackage manifest, required
|
|
175
|
+
│ ├── rules/
|
|
176
|
+
│ │ └── # Rule files
|
|
177
|
+
│ ├── commands/
|
|
178
|
+
│ │ └── # Command files (slash commands)
|
|
179
|
+
│ ├── agents/
|
|
180
|
+
│ │ └── # Agent files (subagents)
|
|
181
|
+
│ └── skills/
|
|
182
|
+
│ └── # Skill files (Claude Code skills)
|
|
183
|
+
├── <dirs-or-files>
|
|
184
|
+
│ └── # Any other root dirs or files (Ex: specs/, docs/, tests/, etc.)
|
|
185
|
+
├── README.md # Metadata files (LICENSE.md, CONTRIBUTING.md, etc.)
|
|
186
|
+
└── AGENTS.md # Platform root file
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
There are two ways to compose packages:
|
|
190
|
+
- In a project workspace: `opkg init <package>` will create a package in `.openpackage/packages/<packages>/`
|
|
191
|
+
- In a dedicated package codebase: `opkg init` will create a package at cwd (similar to npm, pypi, etc.)
|
|
192
|
+
|
|
152
193
|
## Supported Platforms
|
|
153
194
|
|
|
154
195
|
OpenPackage performs installation and platform sync of files for supported AI coding platforms outlined by the table below.
|
|
155
|
-
Files and paths will be automatically converted to platform specific designations during `save` and `install`.
|
|
196
|
+
Files and paths will be automatically converted to platform specific designations during `save` and `install`. The `platforms.jsonc` file includes the specifications for all supported platforms.
|
|
156
197
|
|
|
157
198
|
> [!NOTE]
|
|
158
|
-
> OpenPackage
|
|
199
|
+
> OpenPackage searches and includes markdown files under supported platform directories as well as any other workspace directories.
|
|
159
200
|
|
|
160
201
|
| Platform | Directory | Root file | Rules | Commands | Agents | Skills |
|
|
161
202
|
| --- | --- | --- | --- | --- | --- | --- |
|
package/dist/commands/add.js
CHANGED
|
@@ -1,286 +1,21 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { getAllPlatforms, getDetectedPlatforms, getPlatformDefinition } from '../core/platforms.js';
|
|
4
|
-
import { withErrorHandling, UserCancellationError } from '../utils/errors.js';
|
|
5
|
-
import { ensureDir, exists, isDirectory, isFile, readTextFile, writeTextFile, walkFiles } from '../utils/fs.js';
|
|
6
|
-
import { getLocalPackageDir, getLocalOpenPackageDir } from '../utils/paths.js';
|
|
7
|
-
import { parsePackageYml, writePackageYml } from '../utils/package-yml.js';
|
|
8
|
-
import { normalizePackageName, validatePackageName } from '../utils/package-name.js';
|
|
9
|
-
import { promptPackageDetailsForNamed, safePrompts } from '../utils/prompts.js';
|
|
10
|
-
import { mapPlatformFileToUniversal } from '../utils/platform-mapper.js';
|
|
11
|
-
import { normalizePathForProcessing } from '../utils/path-normalization.js';
|
|
12
|
-
import { suffixFileBasename, suffixFirstContentDir } from '../utils/platform-specific-paths.js';
|
|
13
|
-
import { logger } from '../utils/logger.js';
|
|
14
|
-
import { buildMappingAndWriteIndex } from '../core/add/package-index-updater.js';
|
|
15
|
-
import { readLocalPackageFilesForIndex } from '../utils/package-local-files.js';
|
|
16
|
-
const PLATFORM_ROOT_FILES = buildPlatformRootFiles();
|
|
1
|
+
import { withErrorHandling } from '../utils/errors.js';
|
|
2
|
+
import { runAddPipeline } from '../core/add/add-pipeline.js';
|
|
17
3
|
export function setupAddCommand(program) {
|
|
18
4
|
program
|
|
19
5
|
.command('add')
|
|
20
|
-
.argument('
|
|
21
|
-
.argument('
|
|
6
|
+
.argument('[package-or-path]', 'package name, or path when omitting package name')
|
|
7
|
+
.argument('[path]', 'file or directory to add (when first arg is a package name)')
|
|
22
8
|
.description('Copy supported workspace files or directories into a local package directory.\n' +
|
|
23
9
|
'Usage examples:\n' +
|
|
24
10
|
' opkg add my-package .cursor/rules/example.md\n' +
|
|
25
|
-
' opkg add my-package ai/helpers/\n'
|
|
11
|
+
' opkg add my-package ai/helpers/\n' +
|
|
12
|
+
' opkg add ai/helpers/\n')
|
|
26
13
|
.option('--platform-specific', 'Save platform-specific variants for platform subdir inputs')
|
|
27
|
-
.action(withErrorHandling(async (
|
|
28
|
-
await
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
async function runAddCommand(packageName, inputPath, options = {}) {
|
|
32
|
-
const cwd = process.cwd();
|
|
33
|
-
// Validate and inspect the input path first
|
|
34
|
-
const resolvedInputPath = resolve(cwd, inputPath);
|
|
35
|
-
await validateSourcePath(resolvedInputPath, cwd);
|
|
36
|
-
const inputIsDirectory = await isDirectory(resolvedInputPath);
|
|
37
|
-
const inputIsFile = !inputIsDirectory && await isFile(resolvedInputPath);
|
|
38
|
-
let entries = await collectSourceEntries(resolvedInputPath, cwd);
|
|
39
|
-
if (entries.length === 0) {
|
|
40
|
-
throw new Error(`No supported files found in ${inputPath}`);
|
|
41
|
-
}
|
|
42
|
-
if (options.platformSpecific) {
|
|
43
|
-
entries = applyPlatformSpecificPaths(cwd, entries, resolvedInputPath, {
|
|
44
|
-
inputIsDirectory,
|
|
45
|
-
inputIsFile
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
// Only now ensure/create the package & package.yml
|
|
49
|
-
const ensuredPackage = await ensurePackageExists(cwd, packageName);
|
|
50
|
-
const changedFiles = await copyWithConflictResolution(ensuredPackage, entries);
|
|
51
|
-
// Always update index using all candidate entries (even if nothing changed on disk)
|
|
52
|
-
// Directory collapsing is now universally applied
|
|
53
|
-
await updatePackageIndex(cwd, ensuredPackage);
|
|
54
|
-
if (changedFiles.length > 0) {
|
|
55
|
-
logger.info(`Added ${changedFiles.length} file(s) to package '${ensuredPackage.normalizedName}'.`);
|
|
56
|
-
}
|
|
57
|
-
else {
|
|
58
|
-
logger.info('No files were added or modified.');
|
|
59
|
-
}
|
|
60
|
-
return { success: true };
|
|
61
|
-
}
|
|
62
|
-
async function ensurePackageExists(cwd, packageName) {
|
|
63
|
-
validatePackageName(packageName);
|
|
64
|
-
const normalizedName = normalizePackageName(packageName);
|
|
65
|
-
const packageDir = getLocalPackageDir(cwd, normalizedName);
|
|
66
|
-
const packageYmlPath = join(packageDir, FILE_PATTERNS.PACKAGE_YML);
|
|
67
|
-
await ensureDir(packageDir);
|
|
68
|
-
let packageConfig;
|
|
69
|
-
if (await exists(packageYmlPath)) {
|
|
70
|
-
packageConfig = await parsePackageYml(packageYmlPath);
|
|
71
|
-
}
|
|
72
|
-
else {
|
|
73
|
-
packageConfig = await promptPackageDetailsForNamed(normalizedName);
|
|
74
|
-
await writePackageYml(packageYmlPath, packageConfig);
|
|
75
|
-
logger.info(`Created new package '${packageConfig.name}@${packageConfig.version}' at ${relative(cwd, packageDir)}`);
|
|
76
|
-
}
|
|
77
|
-
return {
|
|
78
|
-
normalizedName,
|
|
79
|
-
packageDir,
|
|
80
|
-
packageConfig
|
|
81
|
-
};
|
|
82
|
-
}
|
|
83
|
-
async function validateSourcePath(resolvedPath, cwd) {
|
|
84
|
-
if (!(await exists(resolvedPath))) {
|
|
85
|
-
throw new Error(`Path not found: ${relative(cwd, resolvedPath) || resolvedPath}`);
|
|
86
|
-
}
|
|
87
|
-
if (!isWithinDirectory(cwd, resolvedPath)) {
|
|
88
|
-
throw new Error('Path must be within the current working directory.');
|
|
89
|
-
}
|
|
90
|
-
const openpackageDir = getLocalOpenPackageDir(cwd);
|
|
91
|
-
if (isWithinDirectory(openpackageDir, resolvedPath)) {
|
|
92
|
-
throw new Error('Cannot add files from the .openpackage directory.');
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
async function collectSourceEntries(resolvedPath, cwd) {
|
|
96
|
-
const entries = [];
|
|
97
|
-
if (await isDirectory(resolvedPath)) {
|
|
98
|
-
for await (const filePath of walkFiles(resolvedPath)) {
|
|
99
|
-
const entry = deriveSourceEntry(filePath, cwd);
|
|
100
|
-
if (!entry) {
|
|
101
|
-
throw new Error(`Unsupported file inside directory: ${relative(cwd, filePath)}`);
|
|
102
|
-
}
|
|
103
|
-
entries.push(entry);
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
else if (await isFile(resolvedPath)) {
|
|
107
|
-
const entry = deriveSourceEntry(resolvedPath, cwd);
|
|
108
|
-
if (!entry) {
|
|
109
|
-
throw new Error(`Unsupported file: ${relative(cwd, resolvedPath)}`);
|
|
110
|
-
}
|
|
111
|
-
entries.push(entry);
|
|
112
|
-
}
|
|
113
|
-
else {
|
|
114
|
-
throw new Error(`Unsupported path type: ${resolvedPath}`);
|
|
115
|
-
}
|
|
116
|
-
return entries;
|
|
117
|
-
}
|
|
118
|
-
function deriveSourceEntry(absFilePath, cwd) {
|
|
119
|
-
const relativePath = relative(cwd, absFilePath);
|
|
120
|
-
const normalizedRelPath = normalizePathForProcessing(relativePath);
|
|
121
|
-
if (normalizedRelPath.startsWith(`${PLATFORM_DIRS.AI}/`)) {
|
|
122
|
-
return {
|
|
123
|
-
sourcePath: absFilePath,
|
|
124
|
-
registryPath: normalizedRelPath
|
|
125
|
-
};
|
|
126
|
-
}
|
|
127
|
-
const mapping = mapPlatformFileToUniversal(absFilePath);
|
|
128
|
-
if (mapping) {
|
|
129
|
-
return {
|
|
130
|
-
sourcePath: absFilePath,
|
|
131
|
-
registryPath: joinPathSegments(mapping.subdir, mapping.relPath)
|
|
132
|
-
};
|
|
133
|
-
}
|
|
134
|
-
const fileName = normalizedRelPath.split('/').pop();
|
|
135
|
-
if (fileName && isPlatformRootFile(fileName) && !normalizedRelPath.includes('/')) {
|
|
136
|
-
return {
|
|
137
|
-
sourcePath: absFilePath,
|
|
138
|
-
registryPath: fileName
|
|
139
|
-
};
|
|
140
|
-
}
|
|
141
|
-
return null;
|
|
142
|
-
}
|
|
143
|
-
function joinPathSegments(...parts) {
|
|
144
|
-
return parts
|
|
145
|
-
.filter(Boolean)
|
|
146
|
-
.join('/')
|
|
147
|
-
.replace(/\/{2,}/g, '/');
|
|
148
|
-
}
|
|
149
|
-
function applyPlatformSpecificPaths(cwd, entries, resolvedInputPath, options) {
|
|
150
|
-
const normalizedInput = resolve(resolvedInputPath);
|
|
151
|
-
for (const entry of entries) {
|
|
152
|
-
const { registryPath, sourcePath } = entry;
|
|
153
|
-
if (isAiRegistryPath(registryPath)) {
|
|
154
|
-
continue;
|
|
155
|
-
}
|
|
156
|
-
const fileName = registryPath.split('/').pop();
|
|
157
|
-
if (fileName && isPlatformRootFile(fileName)) {
|
|
158
|
-
continue;
|
|
159
|
-
}
|
|
160
|
-
const mapping = mapPlatformFileToUniversal(sourcePath);
|
|
161
|
-
if (!mapping) {
|
|
162
|
-
continue;
|
|
163
|
-
}
|
|
164
|
-
const definition = getPlatformDefinition(mapping.platform);
|
|
165
|
-
const subdirDef = definition.subdirs[mapping.subdir];
|
|
166
|
-
if (!subdirDef?.path) {
|
|
167
|
-
continue;
|
|
168
|
-
}
|
|
169
|
-
const subdirAbs = resolve(join(cwd, definition.rootDir, subdirDef.path));
|
|
170
|
-
const sourceAbs = resolve(sourcePath);
|
|
171
|
-
const withinSubdir = sourceAbs === subdirAbs || isWithinDirectory(subdirAbs, sourceAbs);
|
|
172
|
-
if (!withinSubdir) {
|
|
173
|
-
continue;
|
|
14
|
+
.action(withErrorHandling(async (packageOrPath, pathArg, options) => {
|
|
15
|
+
const result = await runAddPipeline(packageOrPath, pathArg, options);
|
|
16
|
+
if (!result.success) {
|
|
17
|
+
throw new Error(result.error || 'Add operation failed');
|
|
174
18
|
}
|
|
175
|
-
|
|
176
|
-
entry.registryPath = suffixFileBasename(registryPath, mapping.platform);
|
|
177
|
-
continue;
|
|
178
|
-
}
|
|
179
|
-
if (!options.inputIsDirectory) {
|
|
180
|
-
continue;
|
|
181
|
-
}
|
|
182
|
-
if (normalizedInput === subdirAbs) {
|
|
183
|
-
entry.registryPath = suffixFileBasename(registryPath, mapping.platform);
|
|
184
|
-
continue;
|
|
185
|
-
}
|
|
186
|
-
if (isWithinDirectory(normalizedInput, sourceAbs)) {
|
|
187
|
-
entry.registryPath = suffixFirstContentDir(registryPath, mapping.platform);
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
return entries;
|
|
191
|
-
}
|
|
192
|
-
function isAiRegistryPath(registryPath) {
|
|
193
|
-
return registryPath === PLATFORM_DIRS.AI || registryPath.startsWith(`${PLATFORM_DIRS.AI}/`);
|
|
194
|
-
}
|
|
195
|
-
// computeDirKeyFromRegistryPath and directory collapsing moved to core/add/package-index-updater.ts
|
|
196
|
-
function buildPlatformRootFiles() {
|
|
197
|
-
const rootFiles = new Set();
|
|
198
|
-
for (const platform of getAllPlatforms()) {
|
|
199
|
-
const def = getPlatformDefinition(platform);
|
|
200
|
-
if (def.rootFile) {
|
|
201
|
-
rootFiles.add(def.rootFile);
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
rootFiles.add(FILE_PATTERNS.AGENTS_MD);
|
|
205
|
-
return rootFiles;
|
|
206
|
-
}
|
|
207
|
-
function isPlatformRootFile(fileName) {
|
|
208
|
-
return PLATFORM_ROOT_FILES.has(fileName);
|
|
209
|
-
}
|
|
210
|
-
function isWithinDirectory(parentDir, targetPath) {
|
|
211
|
-
const resolvedParent = resolve(parentDir);
|
|
212
|
-
const resolvedTarget = resolve(targetPath);
|
|
213
|
-
if (resolvedParent === resolvedTarget) {
|
|
214
|
-
return true;
|
|
215
|
-
}
|
|
216
|
-
const rel = relative(resolvedParent, resolvedTarget);
|
|
217
|
-
return !!rel && !rel.startsWith('..') && !isAbsolute(rel);
|
|
218
|
-
}
|
|
219
|
-
async function copyWithConflictResolution(ensuredPackage, entries) {
|
|
220
|
-
const changedFiles = [];
|
|
221
|
-
const { packageDir, normalizedName } = ensuredPackage;
|
|
222
|
-
for (const entry of entries) {
|
|
223
|
-
const registryPath = entry.registryPath;
|
|
224
|
-
const destination = join(packageDir, ...registryPath.split('/'));
|
|
225
|
-
const sourceContent = await readTextFile(entry.sourcePath);
|
|
226
|
-
const destExists = await exists(destination);
|
|
227
|
-
if (destExists) {
|
|
228
|
-
let existingContent = '';
|
|
229
|
-
try {
|
|
230
|
-
existingContent = await readTextFile(destination);
|
|
231
|
-
}
|
|
232
|
-
catch {
|
|
233
|
-
existingContent = '';
|
|
234
|
-
}
|
|
235
|
-
if (existingContent === sourceContent) {
|
|
236
|
-
logger.debug(`Skipping unchanged file: ${registryPath}`);
|
|
237
|
-
continue;
|
|
238
|
-
}
|
|
239
|
-
const decision = await promptConflictDecision(normalizedName, registryPath);
|
|
240
|
-
if (decision === 'keep-existing') {
|
|
241
|
-
logger.debug(`Kept existing file for ${registryPath}`);
|
|
242
|
-
continue;
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
await ensureDir(dirname(destination));
|
|
246
|
-
await writeTextFile(destination, sourceContent);
|
|
247
|
-
changedFiles.push({
|
|
248
|
-
path: registryPath,
|
|
249
|
-
content: sourceContent,
|
|
250
|
-
encoding: 'utf8'
|
|
251
|
-
});
|
|
252
|
-
}
|
|
253
|
-
return changedFiles;
|
|
254
|
-
}
|
|
255
|
-
async function promptConflictDecision(packageName, registryPath) {
|
|
256
|
-
const response = await safePrompts({
|
|
257
|
-
type: 'select',
|
|
258
|
-
name: 'decision',
|
|
259
|
-
message: `File '${registryPath}' already exists in package '${packageName}'. Choose how to proceed:`,
|
|
260
|
-
choices: [
|
|
261
|
-
{
|
|
262
|
-
title: 'Keep existing file (skip)',
|
|
263
|
-
value: 'keep-existing'
|
|
264
|
-
},
|
|
265
|
-
{
|
|
266
|
-
title: 'Replace with workspace file',
|
|
267
|
-
value: 'overwrite'
|
|
268
|
-
},
|
|
269
|
-
{
|
|
270
|
-
title: 'Cancel operation',
|
|
271
|
-
value: 'cancel'
|
|
272
|
-
}
|
|
273
|
-
]
|
|
274
|
-
});
|
|
275
|
-
if (response.decision === 'cancel') {
|
|
276
|
-
throw new UserCancellationError();
|
|
277
|
-
}
|
|
278
|
-
return response.decision;
|
|
279
|
-
}
|
|
280
|
-
async function updatePackageIndex(cwd, ensuredPackage) {
|
|
281
|
-
const { normalizedName, packageDir } = ensuredPackage;
|
|
282
|
-
const packageFiles = await readLocalPackageFilesForIndex(packageDir);
|
|
283
|
-
const detectedPlatforms = await getDetectedPlatforms(cwd);
|
|
284
|
-
await buildMappingAndWriteIndex(cwd, normalizedName, packageFiles, detectedPlatforms, { preserveExactPaths: true });
|
|
19
|
+
}));
|
|
285
20
|
}
|
|
286
21
|
//# sourceMappingURL=add.js.map
|
package/dist/commands/add.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"add.js","sourceRoot":"","sources":["../../src/commands/add.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"add.js","sourceRoot":"","sources":["../../src/commands/add.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AACvD,OAAO,EAAE,cAAc,EAA2B,MAAM,6BAA6B,CAAC;AAEtF,MAAM,UAAU,eAAe,CAAC,OAAgB;IAC9C,OAAO;SACJ,OAAO,CAAC,KAAK,CAAC;SACd,QAAQ,CAAC,mBAAmB,EAAE,kDAAkD,CAAC;SACjF,QAAQ,CAAC,QAAQ,EAAE,6DAA6D,CAAC;SACjF,WAAW,CACV,iFAAiF;QACjF,mBAAmB;QACnB,kDAAkD;QAClD,qCAAqC;QACrC,0BAA0B,CAC3B;SACA,MAAM,CAAC,qBAAqB,EAAE,4DAA4D,CAAC;SAC3F,MAAM,CACL,iBAAiB,CAAC,KAAK,EAAE,aAAiC,EAAE,OAA2B,EAAE,OAA2B,EAAE,EAAE;QACtH,MAAM,MAAM,GAAG,MAAM,cAAc,CAAC,aAAa,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;QACrE,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;YACpB,MAAM,IAAI,KAAK,CAAC,MAAM,CAAC,KAAK,IAAI,sBAAsB,CAAC,CAAC;QAC1D,CAAC;IACH,CAAC,CAAC,CACH,CAAC;AACN,CAAC"}
|