devworkspace 0.5.0 → 0.5.2
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/CHANGELOG.md +44 -0
- package/README.md +57 -509
- package/dist/agents/claude/adapter.js +0 -1
- package/dist/agents/claude/content.js +0 -1
- package/dist/agents/codex/adapter.js +0 -1
- package/dist/agents/copilot/adapter.js +0 -1
- package/dist/agents/cursor/adapter.js +0 -1
- package/dist/agents/index.js +0 -1
- package/dist/agents/shared.js +0 -1
- package/dist/agents/types.js +0 -1
- package/dist/cli/args.d.ts +16 -0
- package/dist/cli/args.js +5 -1
- package/dist/cli/help.js +59 -17
- package/dist/cli/main.js +0 -1
- package/dist/cli/prompt.d.ts +15 -0
- package/dist/cli/prompt.js +113 -0
- package/dist/cli/render.d.ts +10 -0
- package/dist/cli/render.js +174 -4
- package/dist/cli/run.d.ts +3 -0
- package/dist/cli/run.js +366 -17
- package/dist/config/feature-gate.d.ts +15 -0
- package/dist/config/feature-gate.js +77 -0
- package/dist/config/feature-registry.d.ts +49 -0
- package/dist/config/feature-registry.js +451 -0
- package/dist/config/schemas.js +0 -1
- package/dist/config/settings.d.ts +54 -0
- package/dist/config/settings.js +293 -0
- package/dist/config/validate.js +0 -1
- package/dist/core/artifacts.js +0 -1
- package/dist/core/contracts.js +0 -1
- package/dist/core/migrations.js +0 -1
- package/dist/core/version.js +0 -1
- package/dist/core/versioned.js +0 -1
- package/dist/core/workspace.d.ts +1 -0
- package/dist/core/workspace.js +1 -1
- package/dist/decisions/decision.js +0 -1
- package/dist/discovery/cache.js +0 -1
- package/dist/discovery/commands.js +0 -1
- package/dist/discovery/detect.js +0 -1
- package/dist/discovery/docs.js +0 -1
- package/dist/discovery/entrypoints.js +0 -1
- package/dist/discovery/ignore.js +0 -1
- package/dist/discovery/scan.js +0 -1
- package/dist/discovery/types.js +0 -1
- package/dist/dx/dashboard.js +2 -1
- package/dist/dx/guidance.js +0 -1
- package/dist/dx/guided-setup.d.ts +102 -0
- package/dist/dx/guided-setup.js +508 -0
- package/dist/dx/index.js +0 -1
- package/dist/dx/onboarding.js +0 -1
- package/dist/dx/types.js +0 -1
- package/dist/errors/index.js +0 -1
- package/dist/features/schema.js +0 -1
- package/dist/features/types.js +0 -1
- package/dist/features/validate.js +0 -1
- package/dist/git/git.js +0 -1
- package/dist/index.d.ts +15 -5
- package/dist/index.js +10 -2
- package/dist/integrations/adapters/agent-skills.js +0 -1
- package/dist/integrations/adapters/claudePlugin.js +0 -1
- package/dist/integrations/adapters/graphify.js +0 -1
- package/dist/integrations/adapters/omniroute.js +0 -1
- package/dist/integrations/adapters/pluginSkill.js +0 -1
- package/dist/integrations/adapters/ponytail.js +0 -1
- package/dist/integrations/exec.js +0 -1
- package/dist/integrations/index.js +0 -1
- package/dist/integrations/manager.d.ts +2 -1
- package/dist/integrations/manager.js +22 -3
- package/dist/integrations/notices.js +0 -1
- package/dist/integrations/persistentPath.js +0 -1
- package/dist/integrations/protect.js +0 -1
- package/dist/integrations/state.js +0 -1
- package/dist/integrations/types.d.ts +1 -1
- package/dist/integrations/types.js +1 -1
- package/dist/intelligence/agents/profiles.js +0 -1
- package/dist/intelligence/agents/registry.js +0 -1
- package/dist/intelligence/agents/types.js +0 -1
- package/dist/intelligence/observability/tracer.js +0 -1
- package/dist/intelligence/observability/types.js +0 -1
- package/dist/intelligence/orchestration/engine.d.ts +21 -3
- package/dist/intelligence/orchestration/engine.js +486 -48
- package/dist/intelligence/orchestration/lock-manager.js +0 -1
- package/dist/intelligence/orchestration/store.js +0 -1
- package/dist/intelligence/orchestration/types.d.ts +40 -2
- package/dist/intelligence/orchestration/types.js +2 -3
- package/dist/intelligence/routing/matcher.js +0 -1
- package/dist/intelligence/routing/router.js +0 -1
- package/dist/intelligence/routing/types.js +0 -1
- package/dist/intelligence/runtime/adk/adapter.js +21 -33
- package/dist/intelligence/runtime/adk/detector.js +0 -1
- package/dist/intelligence/runtime/auth-provider.d.ts +63 -0
- package/dist/intelligence/runtime/auth-provider.js +201 -0
- package/dist/intelligence/runtime/boundary.d.ts +142 -0
- package/dist/intelligence/runtime/boundary.js +845 -0
- package/dist/intelligence/runtime/changes.d.ts +59 -0
- package/dist/intelligence/runtime/changes.js +362 -0
- package/dist/intelligence/runtime/external.d.ts +1 -0
- package/dist/intelligence/runtime/external.js +38 -61
- package/dist/intelligence/runtime/native.js +23 -56
- package/dist/intelligence/runtime/types.d.ts +91 -1
- package/dist/intelligence/runtime/types.js +11 -2
- package/dist/intelligence/security/audit.js +8 -2
- package/dist/intelligence/security/policy.js +0 -1
- package/dist/intelligence/security/types.d.ts +8 -0
- package/dist/intelligence/security/types.js +0 -1
- package/dist/intelligence/skills/builtins.js +0 -1
- package/dist/intelligence/skills/loader.js +0 -1
- package/dist/intelligence/skills/registry.js +0 -1
- package/dist/intelligence/skills/types.js +0 -1
- package/dist/intelligence/verification/engine.d.ts +30 -8
- package/dist/intelligence/verification/engine.js +126 -21
- package/dist/intelligence/verification/reviewer.d.ts +18 -2
- package/dist/intelligence/verification/reviewer.js +356 -4
- package/dist/intelligence/verification/types.d.ts +71 -0
- package/dist/intelligence/verification/types.js +0 -1
- package/dist/knowledge/facts.js +0 -1
- package/dist/mcp/protocol.js +0 -1
- package/dist/mcp/server.js +38 -2
- package/dist/mcp/setup.js +5 -2
- package/dist/mcp/tools.js +0 -1
- package/dist/mcp/types.js +0 -1
- package/dist/mcp/verify.js +0 -1
- package/dist/portability/bundle.js +0 -1
- package/dist/prompts/onboarding.js +0 -1
- package/dist/prompts/refresh.js +0 -1
- package/dist/prompts/requirements.js +0 -1
- package/dist/security/files.js +0 -1
- package/dist/security/redact.js +0 -1
- package/dist/services/agent.js +2 -1
- package/dist/services/analysis.js +0 -1
- package/dist/services/common.js +0 -1
- package/dist/services/doctor.js +13 -2
- package/dist/services/drift.js +0 -1
- package/dist/services/features.js +5 -1
- package/dist/services/graph.js +4 -1
- package/dist/services/init.js +0 -1
- package/dist/services/integrations.d.ts +2 -1
- package/dist/services/integrations.js +29 -6
- package/dist/services/intelligence.d.ts +2 -2
- package/dist/services/intelligence.js +38 -36
- package/dist/services/knowledge.js +0 -1
- package/dist/services/migrate.js +0 -1
- package/dist/services/modules.d.ts +85 -0
- package/dist/services/modules.js +313 -0
- package/dist/services/portability.js +0 -1
- package/dist/services/records.js +5 -1
- package/dist/services/refresh.js +0 -1
- package/dist/services/reset.js +0 -1
- package/dist/services/settings.d.ts +36 -0
- package/dist/services/settings.js +102 -0
- package/dist/services/setup.d.ts +4 -5
- package/dist/services/setup.js +40 -28
- package/dist/services/standards.js +10 -1
- package/dist/services/status.js +0 -1
- package/dist/services/taskContext.js +0 -1
- package/dist/services/tasks.js +9 -1
- package/dist/services/verify.js +7 -2
- package/dist/sessions/session.js +0 -1
- package/dist/standards/acquisition/ingest.js +0 -1
- package/dist/standards/applicability/engine.js +0 -1
- package/dist/standards/builtin/code-quality.js +0 -1
- package/dist/standards/builtin/database-safety.js +0 -1
- package/dist/standards/builtin/index.js +0 -1
- package/dist/standards/builtin/security-baseline.js +0 -1
- package/dist/standards/builtin/testing-contracts.js +0 -1
- package/dist/standards/builtin/undo-kit.js +0 -1
- package/dist/standards/config/config.js +0 -1
- package/dist/standards/distribution/cache.d.ts +1 -0
- package/dist/standards/distribution/cache.js +199 -186
- package/dist/standards/distribution/index.js +0 -1
- package/dist/standards/distribution/keys.js +0 -1
- package/dist/standards/distribution/package.js +6 -1
- package/dist/standards/distribution/server.js +0 -1
- package/dist/standards/distribution/sync.d.ts +7 -2
- package/dist/standards/distribution/sync.js +41 -9
- package/dist/standards/distribution/types.js +0 -1
- package/dist/standards/engine/compliance.js +0 -1
- package/dist/standards/engine/engine.js +0 -1
- package/dist/standards/engine/reporter.js +0 -1
- package/dist/standards/index.js +0 -1
- package/dist/standards/registry/registry.js +0 -1
- package/dist/standards/schema/types.js +0 -1
- package/dist/standards/schema/validate.js +0 -1
- package/dist/standards/templates/index.js +0 -1
- package/dist/standards/validators/database.js +0 -1
- package/dist/standards/validators/quality.js +0 -1
- package/dist/standards/validators/registry.js +0 -1
- package/dist/standards/validators/security.js +0 -1
- package/dist/standards/validators/testing.js +0 -1
- package/dist/standards/validators/types.js +0 -1
- package/dist/standards/validators/undo-kit.js +0 -1
- package/dist/tasks/routing.js +0 -1
- package/dist/tasks/task.js +0 -1
- package/dist/utils/cleanup.js +0 -1
- package/dist/utils/fs.js +0 -1
- package/dist/utils/lock.js +92 -49
- package/dist/utils/logger.js +0 -1
- package/dist/utils/paths.js +0 -1
- package/dist/utils/proc.d.ts +12 -0
- package/dist/utils/proc.js +106 -44
- package/dist/verification/safety.js +0 -1
- package/dist/verification/scope.js +0 -1
- package/docs/agents.md +15 -0
- package/docs/architecture/global-standards-architecture.md +287 -0
- package/docs/archive/global-standards/GLOBAL_STANDARDS_AUDIT.md +99 -0
- package/docs/archive/global-standards/GLOBAL_STANDARDS_FINAL_STATUS.md +138 -0
- package/docs/archive/global-standards/GLOBAL_STANDARDS_IMPLEMENTATION_PLAN.md +100 -0
- package/docs/archive/global-standards/GLOBAL_STANDARDS_INDEPENDENT_AUDIT.md +219 -0
- package/docs/archive/global-standards/GLOBAL_STANDARDS_SECURITY_REPORT.md +184 -0
- package/docs/configuration.md +67 -0
- package/docs/contributing.md +15 -5
- package/docs/development/EXECUTION_STATE.md +50 -0
- package/docs/features.md +80 -0
- package/docs/getting-started.md +69 -111
- package/docs/guides/global-standards-migration.md +100 -0
- package/docs/integrations.md +7 -0
- package/docs/mcp.md +13 -0
- package/docs/security/THIRD_PARTY_LICENSES.md +41 -0
- package/docs/security.md +8 -2
- package/docs/testing/FINAL_CORRECTION_AND_CLEANUP_REPORT.md +92 -0
- package/docs/testing/global-standards-real-project-tests.md +218 -0
- package/docs/testing/global-standards-test-report.md +89 -0
- package/docs/testing/global-standards-verification-matrix.md +174 -0
- package/docs/troubleshooting.md +3 -0
- package/package.json +1 -1
- package/dist/agents/claude/adapter.js.map +0 -1
- package/dist/agents/claude/content.js.map +0 -1
- package/dist/agents/codex/adapter.js.map +0 -1
- package/dist/agents/copilot/adapter.js.map +0 -1
- package/dist/agents/cursor/adapter.js.map +0 -1
- package/dist/agents/index.js.map +0 -1
- package/dist/agents/shared.js.map +0 -1
- package/dist/agents/types.js.map +0 -1
- package/dist/cli/args.js.map +0 -1
- package/dist/cli/help.js.map +0 -1
- package/dist/cli/main.js.map +0 -1
- package/dist/cli/render.js.map +0 -1
- package/dist/cli/run.js.map +0 -1
- package/dist/config/schemas.js.map +0 -1
- package/dist/config/validate.js.map +0 -1
- package/dist/core/artifacts.js.map +0 -1
- package/dist/core/contracts.js.map +0 -1
- package/dist/core/migrations.js.map +0 -1
- package/dist/core/version.js.map +0 -1
- package/dist/core/versioned.js.map +0 -1
- package/dist/core/workspace.js.map +0 -1
- package/dist/decisions/decision.js.map +0 -1
- package/dist/discovery/cache.js.map +0 -1
- package/dist/discovery/commands.js.map +0 -1
- package/dist/discovery/detect.js.map +0 -1
- package/dist/discovery/docs.js.map +0 -1
- package/dist/discovery/entrypoints.js.map +0 -1
- package/dist/discovery/ignore.js.map +0 -1
- package/dist/discovery/scan.js.map +0 -1
- package/dist/discovery/types.js.map +0 -1
- package/dist/dx/dashboard.js.map +0 -1
- package/dist/dx/guidance.js.map +0 -1
- package/dist/dx/index.js.map +0 -1
- package/dist/dx/onboarding.js.map +0 -1
- package/dist/dx/types.js.map +0 -1
- package/dist/errors/index.js.map +0 -1
- package/dist/features/schema.js.map +0 -1
- package/dist/features/types.js.map +0 -1
- package/dist/features/validate.js.map +0 -1
- package/dist/git/git.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/integrations/adapters/agent-skills.js.map +0 -1
- package/dist/integrations/adapters/claudePlugin.js.map +0 -1
- package/dist/integrations/adapters/graphify.js.map +0 -1
- package/dist/integrations/adapters/omniroute.js.map +0 -1
- package/dist/integrations/adapters/pluginSkill.js.map +0 -1
- package/dist/integrations/adapters/ponytail.js.map +0 -1
- package/dist/integrations/exec.js.map +0 -1
- package/dist/integrations/index.js.map +0 -1
- package/dist/integrations/manager.js.map +0 -1
- package/dist/integrations/notices.js.map +0 -1
- package/dist/integrations/persistentPath.js.map +0 -1
- package/dist/integrations/protect.js.map +0 -1
- package/dist/integrations/state.js.map +0 -1
- package/dist/integrations/types.js.map +0 -1
- package/dist/intelligence/agents/profiles.js.map +0 -1
- package/dist/intelligence/agents/registry.js.map +0 -1
- package/dist/intelligence/agents/types.js.map +0 -1
- package/dist/intelligence/observability/tracer.js.map +0 -1
- package/dist/intelligence/observability/types.js.map +0 -1
- package/dist/intelligence/orchestration/engine.js.map +0 -1
- package/dist/intelligence/orchestration/lock-manager.js.map +0 -1
- package/dist/intelligence/orchestration/store.js.map +0 -1
- package/dist/intelligence/orchestration/types.js.map +0 -1
- package/dist/intelligence/routing/matcher.js.map +0 -1
- package/dist/intelligence/routing/router.js.map +0 -1
- package/dist/intelligence/routing/types.js.map +0 -1
- package/dist/intelligence/runtime/adk/adapter.js.map +0 -1
- package/dist/intelligence/runtime/adk/detector.js.map +0 -1
- package/dist/intelligence/runtime/external.js.map +0 -1
- package/dist/intelligence/runtime/native.js.map +0 -1
- package/dist/intelligence/runtime/types.js.map +0 -1
- package/dist/intelligence/security/audit.js.map +0 -1
- package/dist/intelligence/security/policy.js.map +0 -1
- package/dist/intelligence/security/types.js.map +0 -1
- package/dist/intelligence/skills/builtins.js.map +0 -1
- package/dist/intelligence/skills/loader.js.map +0 -1
- package/dist/intelligence/skills/registry.js.map +0 -1
- package/dist/intelligence/skills/types.js.map +0 -1
- package/dist/intelligence/verification/engine.js.map +0 -1
- package/dist/intelligence/verification/reviewer.js.map +0 -1
- package/dist/intelligence/verification/types.js.map +0 -1
- package/dist/knowledge/facts.js.map +0 -1
- package/dist/mcp/protocol.js.map +0 -1
- package/dist/mcp/server.js.map +0 -1
- package/dist/mcp/setup.js.map +0 -1
- package/dist/mcp/tools.js.map +0 -1
- package/dist/mcp/types.js.map +0 -1
- package/dist/mcp/verify.js.map +0 -1
- package/dist/portability/bundle.js.map +0 -1
- package/dist/prompts/onboarding.js.map +0 -1
- package/dist/prompts/refresh.js.map +0 -1
- package/dist/prompts/requirements.js.map +0 -1
- package/dist/security/files.js.map +0 -1
- package/dist/security/redact.js.map +0 -1
- package/dist/services/agent.js.map +0 -1
- package/dist/services/analysis.js.map +0 -1
- package/dist/services/common.js.map +0 -1
- package/dist/services/doctor.js.map +0 -1
- package/dist/services/drift.js.map +0 -1
- package/dist/services/features.js.map +0 -1
- package/dist/services/graph.js.map +0 -1
- package/dist/services/init.js.map +0 -1
- package/dist/services/integrations.js.map +0 -1
- package/dist/services/intelligence.js.map +0 -1
- package/dist/services/knowledge.js.map +0 -1
- package/dist/services/migrate.js.map +0 -1
- package/dist/services/portability.js.map +0 -1
- package/dist/services/records.js.map +0 -1
- package/dist/services/refresh.js.map +0 -1
- package/dist/services/reset.js.map +0 -1
- package/dist/services/setup.js.map +0 -1
- package/dist/services/standards.js.map +0 -1
- package/dist/services/status.js.map +0 -1
- package/dist/services/taskContext.js.map +0 -1
- package/dist/services/tasks.js.map +0 -1
- package/dist/services/verify.js.map +0 -1
- package/dist/sessions/session.js.map +0 -1
- package/dist/standards/acquisition/ingest.js.map +0 -1
- package/dist/standards/applicability/engine.js.map +0 -1
- package/dist/standards/builtin/code-quality.js.map +0 -1
- package/dist/standards/builtin/database-safety.js.map +0 -1
- package/dist/standards/builtin/index.js.map +0 -1
- package/dist/standards/builtin/security-baseline.js.map +0 -1
- package/dist/standards/builtin/testing-contracts.js.map +0 -1
- package/dist/standards/builtin/undo-kit.js.map +0 -1
- package/dist/standards/config/config.js.map +0 -1
- package/dist/standards/distribution/cache.js.map +0 -1
- package/dist/standards/distribution/index.js.map +0 -1
- package/dist/standards/distribution/keys.js.map +0 -1
- package/dist/standards/distribution/package.js.map +0 -1
- package/dist/standards/distribution/server.js.map +0 -1
- package/dist/standards/distribution/sync.js.map +0 -1
- package/dist/standards/distribution/types.js.map +0 -1
- package/dist/standards/engine/compliance.js.map +0 -1
- package/dist/standards/engine/engine.js.map +0 -1
- package/dist/standards/engine/reporter.js.map +0 -1
- package/dist/standards/index.js.map +0 -1
- package/dist/standards/registry/registry.js.map +0 -1
- package/dist/standards/schema/types.js.map +0 -1
- package/dist/standards/schema/validate.js.map +0 -1
- package/dist/standards/templates/index.js.map +0 -1
- package/dist/standards/validators/database.js.map +0 -1
- package/dist/standards/validators/quality.js.map +0 -1
- package/dist/standards/validators/registry.js.map +0 -1
- package/dist/standards/validators/security.js.map +0 -1
- package/dist/standards/validators/testing.js.map +0 -1
- package/dist/standards/validators/types.js.map +0 -1
- package/dist/standards/validators/undo-kit.js.map +0 -1
- package/dist/tasks/routing.js.map +0 -1
- package/dist/tasks/task.js.map +0 -1
- package/dist/utils/cleanup.js.map +0 -1
- package/dist/utils/fs.js.map +0 -1
- package/dist/utils/lock.js.map +0 -1
- package/dist/utils/logger.js.map +0 -1
- package/dist/utils/paths.js.map +0 -1
- package/dist/utils/proc.js.map +0 -1
- package/dist/verification/safety.js.map +0 -1
- package/dist/verification/scope.js.map +0 -1
|
@@ -3,6 +3,7 @@ import os from 'node:os';
|
|
|
3
3
|
import path from 'node:path';
|
|
4
4
|
import { DevWorkspaceError } from '../../errors/index.js';
|
|
5
5
|
import { atomicWriteJson, ensureDir, pathExists, readJsonFile } from '../../utils/fs.js';
|
|
6
|
+
import { withLock } from '../../utils/lock.js';
|
|
6
7
|
import { computePackageDigest, verifyPackageIntegrityAndSignature } from './keys.js';
|
|
7
8
|
import { checkCompatibility, parseAndValidateKnowledgePackage } from './package.js';
|
|
8
9
|
import { KNOWLEDGE_PACKAGE_SCHEMA_VERSION, } from './types.js';
|
|
@@ -140,19 +141,26 @@ export class LocalPackageCache {
|
|
|
140
141
|
const state = await this.loadState();
|
|
141
142
|
return Object.values(state.active).sort((a, b) => a.packageId.localeCompare(b.packageId));
|
|
142
143
|
}
|
|
144
|
+
async withCacheLock(fn) {
|
|
145
|
+
return withLock(this.cacheDir, fn, { name: 'cache.lock', timeoutMs: 10_000 });
|
|
146
|
+
}
|
|
143
147
|
async pin(packageId, version) {
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
148
|
+
return this.withCacheLock(async () => {
|
|
149
|
+
const state = await this.loadState();
|
|
150
|
+
const pkgExists = await pathExists(this.packageFilePath(packageId, version));
|
|
151
|
+
if (!pkgExists) {
|
|
152
|
+
throw new DevWorkspaceError('NOT_FOUND', `Cannot pin "${packageId}@${version}": version is not in local cache.`);
|
|
153
|
+
}
|
|
154
|
+
state.pinned[packageId] = version;
|
|
155
|
+
await this.saveState(state);
|
|
156
|
+
});
|
|
151
157
|
}
|
|
152
158
|
async unpin(packageId) {
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
159
|
+
return this.withCacheLock(async () => {
|
|
160
|
+
const state = await this.loadState();
|
|
161
|
+
delete state.pinned[packageId];
|
|
162
|
+
await this.saveState(state);
|
|
163
|
+
});
|
|
156
164
|
}
|
|
157
165
|
async getPinnedVersion(packageId) {
|
|
158
166
|
const state = await this.loadState();
|
|
@@ -208,204 +216,209 @@ export class LocalPackageCache {
|
|
|
208
216
|
* Guarantee: Any validation, trust, signature, pin, or review failure leaves prior active package untouched.
|
|
209
217
|
*/
|
|
210
218
|
async stageAndInstall(rawOrPkg, trustStore, options = {}) {
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
// 3. Stage payload atomically into temporary staging location first
|
|
220
|
-
const pkgStageDir = path.join(this.stagingDir, m.packageId, m.version);
|
|
221
|
-
await ensureDir(pkgStageDir);
|
|
222
|
-
const stagedPkgFile = path.join(pkgStageDir, 'package.json');
|
|
223
|
-
const stagedManifestFile = path.join(pkgStageDir, 'manifest.json');
|
|
224
|
-
try {
|
|
225
|
-
await atomicWriteJson(stagedManifestFile, pkg.manifest);
|
|
226
|
-
await atomicWriteJson(stagedPkgFile, pkg);
|
|
227
|
-
const state = await this.loadState();
|
|
228
|
-
const pinnedVer = state.pinned[m.packageId];
|
|
229
|
-
if (pinnedVer && pinnedVer !== m.version && !options.force) {
|
|
230
|
-
throw new DevWorkspaceError('CONFLICT', `Package "${m.packageId}" is pinned to version "${pinnedVer}". Unpin or pass force to install "${m.version}".`);
|
|
219
|
+
return this.withCacheLock(async () => {
|
|
220
|
+
// 1. Parse and enforce size, file count, path, archive, schema, and compatibility limits
|
|
221
|
+
const pkg = parseAndValidateKnowledgePackage(rawOrPkg);
|
|
222
|
+
const m = pkg.manifest;
|
|
223
|
+
// 2. Cryptographic signature, digest, expiry, and key trust/revocation check
|
|
224
|
+
const verification = verifyPackageIntegrityAndSignature(pkg, trustStore, options.now);
|
|
225
|
+
if (!verification.valid) {
|
|
226
|
+
throw new DevWorkspaceError('SECURITY', `Package verification failed for "${m.packageId}@${m.version}": ${verification.reason}`);
|
|
231
227
|
}
|
|
232
|
-
//
|
|
233
|
-
const
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
228
|
+
// 3. Stage payload atomically into temporary staging location first
|
|
229
|
+
const pkgStageDir = path.join(this.stagingDir, m.packageId, m.version);
|
|
230
|
+
await ensureDir(pkgStageDir);
|
|
231
|
+
const stagedPkgFile = path.join(pkgStageDir, 'package.json');
|
|
232
|
+
const stagedManifestFile = path.join(pkgStageDir, 'manifest.json');
|
|
233
|
+
try {
|
|
234
|
+
await atomicWriteJson(stagedManifestFile, pkg.manifest);
|
|
235
|
+
await atomicWriteJson(stagedPkgFile, pkg);
|
|
236
|
+
const state = await this.loadState();
|
|
237
|
+
const pinnedVer = state.pinned[m.packageId];
|
|
238
|
+
if (pinnedVer && pinnedVer !== m.version && !options.force) {
|
|
239
|
+
throw new DevWorkspaceError('CONFLICT', `Package "${m.packageId}" is pinned to version "${pinnedVer}". Unpin or pass force to install "${m.version}".`);
|
|
240
|
+
}
|
|
241
|
+
// 4. Knowledge review/approval check
|
|
242
|
+
const reviewKey = `${m.packageId}@${m.version}`;
|
|
243
|
+
const locallyApproved = state.localReviews?.[reviewKey]?.status === 'APPROVED';
|
|
244
|
+
if (m.provenance.reviewStatus !== 'APPROVED' && !locallyApproved && !options.allowUnreviewed) {
|
|
245
|
+
// Keep staged copy for review, do NOT activate!
|
|
246
|
+
const prior = state.active[m.packageId]?.version ?? null;
|
|
247
|
+
return {
|
|
248
|
+
installed: {
|
|
249
|
+
packageId: m.packageId,
|
|
250
|
+
version: m.version,
|
|
251
|
+
digest: m.digest,
|
|
252
|
+
keyId: m.keyId,
|
|
253
|
+
installedAt: new Date().toISOString(),
|
|
254
|
+
license: m.license,
|
|
255
|
+
provenance: m.provenance,
|
|
256
|
+
},
|
|
257
|
+
previousVersion: prior,
|
|
258
|
+
stagedOnly: true,
|
|
259
|
+
};
|
|
260
|
+
}
|
|
261
|
+
// 5. Commit package into immutable cached version directory
|
|
262
|
+
const targetDir = path.join(this.packagesDir, m.packageId, m.version);
|
|
263
|
+
await ensureDir(targetDir);
|
|
264
|
+
await atomicWriteJson(path.join(targetDir, 'manifest.json'), pkg.manifest);
|
|
265
|
+
await atomicWriteJson(path.join(targetDir, 'package.json'), pkg);
|
|
266
|
+
const priorActive = state.active[m.packageId] ?? null;
|
|
267
|
+
const now = new Date().toISOString();
|
|
268
|
+
if (priorActive) {
|
|
269
|
+
state.history.push({
|
|
270
|
+
packageId: priorActive.packageId,
|
|
271
|
+
version: priorActive.version,
|
|
272
|
+
digest: priorActive.digest,
|
|
273
|
+
replacedAt: now,
|
|
274
|
+
reason: 'update',
|
|
275
|
+
});
|
|
276
|
+
}
|
|
277
|
+
const record = {
|
|
278
|
+
packageId: m.packageId,
|
|
279
|
+
version: m.version,
|
|
280
|
+
digest: m.digest,
|
|
281
|
+
keyId: m.keyId,
|
|
282
|
+
installedAt: now,
|
|
283
|
+
license: m.license,
|
|
284
|
+
provenance: m.provenance,
|
|
285
|
+
};
|
|
286
|
+
state.active[m.packageId] = record;
|
|
287
|
+
await this.saveState(state);
|
|
288
|
+
// Clean up staging copy upon successful activation
|
|
289
|
+
await fs.rm(pkgStageDir, { recursive: true, force: true });
|
|
238
290
|
return {
|
|
239
|
-
installed:
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
digest: m.digest,
|
|
243
|
-
keyId: m.keyId,
|
|
244
|
-
installedAt: new Date().toISOString(),
|
|
245
|
-
license: m.license,
|
|
246
|
-
provenance: m.provenance,
|
|
247
|
-
},
|
|
248
|
-
previousVersion: prior,
|
|
249
|
-
stagedOnly: true,
|
|
291
|
+
installed: record,
|
|
292
|
+
previousVersion: priorActive?.version ?? null,
|
|
293
|
+
stagedOnly: false,
|
|
250
294
|
};
|
|
251
295
|
}
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
packageId: priorActive.packageId,
|
|
262
|
-
version: priorActive.version,
|
|
263
|
-
digest: priorActive.digest,
|
|
264
|
-
replacedAt: now,
|
|
265
|
-
reason: 'update',
|
|
266
|
-
});
|
|
296
|
+
catch (err) {
|
|
297
|
+
// Ensure failed staging artifacts are cleaned up and prior active state remains intact
|
|
298
|
+
try {
|
|
299
|
+
await fs.rm(pkgStageDir, { recursive: true, force: true });
|
|
300
|
+
}
|
|
301
|
+
catch {
|
|
302
|
+
// ignore cleanup failure
|
|
303
|
+
}
|
|
304
|
+
throw err;
|
|
267
305
|
}
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
306
|
+
});
|
|
307
|
+
}
|
|
308
|
+
/** Records a local review/approval decision without mutating the signed package digest, optionally activating if APPROVED. */
|
|
309
|
+
async reviewStagedPackage(packageId, version, decision) {
|
|
310
|
+
return this.withCacheLock(async () => {
|
|
311
|
+
const stagedFile = path.join(this.stagingDir, packageId, version, 'package.json');
|
|
312
|
+
const cachedFile = this.packageFilePath(packageId, version);
|
|
313
|
+
const sourceFile = (await pathExists(stagedFile)) ? stagedFile : cachedFile;
|
|
314
|
+
if (!(await pathExists(sourceFile))) {
|
|
315
|
+
throw new DevWorkspaceError('NOT_FOUND', `No staged or cached package found for "${packageId}@${version}".`);
|
|
316
|
+
}
|
|
317
|
+
const pkg = await readJsonFile(sourceFile);
|
|
318
|
+
const now = new Date().toISOString();
|
|
319
|
+
const state = await this.loadState();
|
|
320
|
+
state.localReviews = state.localReviews ?? {};
|
|
321
|
+
state.localReviews[`${packageId}@${version}`] = {
|
|
322
|
+
packageId,
|
|
323
|
+
version,
|
|
324
|
+
status: decision.status,
|
|
325
|
+
reviewer: decision.reviewer,
|
|
326
|
+
reviewedAt: now,
|
|
327
|
+
reason: decision.reason,
|
|
276
328
|
};
|
|
277
|
-
|
|
329
|
+
if (decision.status === 'APPROVED' && decision.activate) {
|
|
330
|
+
if (decision.trustStore) {
|
|
331
|
+
const ver = verifyPackageIntegrityAndSignature(pkg, decision.trustStore);
|
|
332
|
+
if (!ver.valid) {
|
|
333
|
+
throw new DevWorkspaceError('SECURITY', `Cannot activate "${packageId}@${version}": ${ver.reason}`);
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
const targetDir = path.join(this.packagesDir, packageId, version);
|
|
337
|
+
await ensureDir(targetDir);
|
|
338
|
+
await atomicWriteJson(path.join(targetDir, 'manifest.json'), pkg.manifest);
|
|
339
|
+
await atomicWriteJson(path.join(targetDir, 'package.json'), pkg);
|
|
340
|
+
const priorActive = state.active[packageId];
|
|
341
|
+
if (priorActive) {
|
|
342
|
+
state.history.push({
|
|
343
|
+
packageId: priorActive.packageId,
|
|
344
|
+
version: priorActive.version,
|
|
345
|
+
digest: priorActive.digest,
|
|
346
|
+
replacedAt: now,
|
|
347
|
+
reason: 'install',
|
|
348
|
+
});
|
|
349
|
+
}
|
|
350
|
+
state.active[packageId] = {
|
|
351
|
+
packageId,
|
|
352
|
+
version,
|
|
353
|
+
digest: pkg.manifest.digest,
|
|
354
|
+
keyId: pkg.manifest.keyId,
|
|
355
|
+
installedAt: now,
|
|
356
|
+
license: pkg.manifest.license,
|
|
357
|
+
provenance: pkg.manifest.provenance,
|
|
358
|
+
};
|
|
359
|
+
if (await pathExists(stagedFile)) {
|
|
360
|
+
await fs.rm(path.join(this.stagingDir, packageId, version), { recursive: true, force: true });
|
|
361
|
+
}
|
|
362
|
+
}
|
|
278
363
|
await this.saveState(state);
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
364
|
+
return pkg;
|
|
365
|
+
});
|
|
366
|
+
}
|
|
367
|
+
/**
|
|
368
|
+
* Rolls back a cached package to a previous version in history (or explicit `targetVersion`).
|
|
369
|
+
* Re-verifies digest and optionally signature against `trustStore` before reactivating.
|
|
370
|
+
*/
|
|
371
|
+
async rollback(packageId, targetVersion, trustStore) {
|
|
372
|
+
return this.withCacheLock(async () => {
|
|
373
|
+
const state = await this.loadState();
|
|
374
|
+
const current = state.active[packageId];
|
|
375
|
+
let chosenVersion = targetVersion;
|
|
376
|
+
if (!chosenVersion) {
|
|
377
|
+
// Pick most recent distinct version from history
|
|
378
|
+
const candidates = state.history
|
|
379
|
+
.filter((h) => h.packageId === packageId && h.version !== current?.version)
|
|
380
|
+
.reverse();
|
|
381
|
+
chosenVersion = candidates[0]?.version;
|
|
291
382
|
}
|
|
292
|
-
|
|
293
|
-
|
|
383
|
+
if (!chosenVersion) {
|
|
384
|
+
throw new DevWorkspaceError('NOT_FOUND', `No previous version found in rollback history for "${packageId}".`);
|
|
294
385
|
}
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
}
|
|
306
|
-
const pkg = await readJsonFile(sourceFile);
|
|
307
|
-
const now = new Date().toISOString();
|
|
308
|
-
const state = await this.loadState();
|
|
309
|
-
state.localReviews = state.localReviews ?? {};
|
|
310
|
-
state.localReviews[`${packageId}@${version}`] = {
|
|
311
|
-
packageId,
|
|
312
|
-
version,
|
|
313
|
-
status: decision.status,
|
|
314
|
-
reviewer: decision.reviewer,
|
|
315
|
-
reviewedAt: now,
|
|
316
|
-
reason: decision.reason,
|
|
317
|
-
};
|
|
318
|
-
if (decision.status === 'APPROVED' && decision.activate) {
|
|
319
|
-
if (decision.trustStore) {
|
|
320
|
-
const ver = verifyPackageIntegrityAndSignature(pkg, decision.trustStore);
|
|
386
|
+
const pkg = await this.getInstalledPackage(packageId, chosenVersion);
|
|
387
|
+
if (!pkg) {
|
|
388
|
+
throw new DevWorkspaceError('NOT_FOUND', `Rollback target "${packageId}@${chosenVersion}" is missing from local cache.`);
|
|
389
|
+
}
|
|
390
|
+
const computedDigest = computePackageDigest(pkg);
|
|
391
|
+
if (computedDigest !== pkg.manifest.digest) {
|
|
392
|
+
throw new DevWorkspaceError('SECURITY', `Cached rollback package "${packageId}@${chosenVersion}" failed integrity digest check.`);
|
|
393
|
+
}
|
|
394
|
+
if (trustStore) {
|
|
395
|
+
const ver = verifyPackageIntegrityAndSignature(pkg, trustStore);
|
|
321
396
|
if (!ver.valid) {
|
|
322
|
-
throw new DevWorkspaceError('SECURITY', `Cannot
|
|
397
|
+
throw new DevWorkspaceError('SECURITY', `Cannot rollback to "${packageId}@${chosenVersion}": ${ver.reason}`);
|
|
323
398
|
}
|
|
324
399
|
}
|
|
325
|
-
const
|
|
326
|
-
|
|
327
|
-
await atomicWriteJson(path.join(targetDir, 'manifest.json'), pkg.manifest);
|
|
328
|
-
await atomicWriteJson(path.join(targetDir, 'package.json'), pkg);
|
|
329
|
-
const priorActive = state.active[packageId];
|
|
330
|
-
if (priorActive) {
|
|
400
|
+
const now = new Date().toISOString();
|
|
401
|
+
if (current) {
|
|
331
402
|
state.history.push({
|
|
332
|
-
packageId:
|
|
333
|
-
version:
|
|
334
|
-
digest:
|
|
403
|
+
packageId: current.packageId,
|
|
404
|
+
version: current.version,
|
|
405
|
+
digest: current.digest,
|
|
335
406
|
replacedAt: now,
|
|
336
|
-
reason: '
|
|
407
|
+
reason: 'rollback',
|
|
337
408
|
});
|
|
338
409
|
}
|
|
339
|
-
|
|
410
|
+
const record = {
|
|
340
411
|
packageId,
|
|
341
|
-
version,
|
|
412
|
+
version: chosenVersion,
|
|
342
413
|
digest: pkg.manifest.digest,
|
|
343
414
|
keyId: pkg.manifest.keyId,
|
|
344
415
|
installedAt: now,
|
|
345
416
|
license: pkg.manifest.license,
|
|
346
417
|
provenance: pkg.manifest.provenance,
|
|
347
418
|
};
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
}
|
|
352
|
-
await this.saveState(state);
|
|
353
|
-
return pkg;
|
|
354
|
-
}
|
|
355
|
-
/**
|
|
356
|
-
* Rolls back a cached package to a previous version in history (or explicit `targetVersion`).
|
|
357
|
-
* Re-verifies digest and optionally signature against `trustStore` before reactivating.
|
|
358
|
-
*/
|
|
359
|
-
async rollback(packageId, targetVersion, trustStore) {
|
|
360
|
-
const state = await this.loadState();
|
|
361
|
-
const current = state.active[packageId];
|
|
362
|
-
let chosenVersion = targetVersion;
|
|
363
|
-
if (!chosenVersion) {
|
|
364
|
-
// Pick most recent distinct version from history
|
|
365
|
-
const candidates = state.history
|
|
366
|
-
.filter((h) => h.packageId === packageId && h.version !== current?.version)
|
|
367
|
-
.reverse();
|
|
368
|
-
chosenVersion = candidates[0]?.version;
|
|
369
|
-
}
|
|
370
|
-
if (!chosenVersion) {
|
|
371
|
-
throw new DevWorkspaceError('NOT_FOUND', `No previous version found in rollback history for "${packageId}".`);
|
|
372
|
-
}
|
|
373
|
-
const pkg = await this.getInstalledPackage(packageId, chosenVersion);
|
|
374
|
-
if (!pkg) {
|
|
375
|
-
throw new DevWorkspaceError('NOT_FOUND', `Rollback target "${packageId}@${chosenVersion}" is missing from local cache.`);
|
|
376
|
-
}
|
|
377
|
-
const computedDigest = computePackageDigest(pkg);
|
|
378
|
-
if (computedDigest !== pkg.manifest.digest) {
|
|
379
|
-
throw new DevWorkspaceError('SECURITY', `Cached rollback package "${packageId}@${chosenVersion}" failed integrity digest check.`);
|
|
380
|
-
}
|
|
381
|
-
if (trustStore) {
|
|
382
|
-
const ver = verifyPackageIntegrityAndSignature(pkg, trustStore);
|
|
383
|
-
if (!ver.valid) {
|
|
384
|
-
throw new DevWorkspaceError('SECURITY', `Cannot rollback to "${packageId}@${chosenVersion}": ${ver.reason}`);
|
|
385
|
-
}
|
|
386
|
-
}
|
|
387
|
-
const now = new Date().toISOString();
|
|
388
|
-
if (current) {
|
|
389
|
-
state.history.push({
|
|
390
|
-
packageId: current.packageId,
|
|
391
|
-
version: current.version,
|
|
392
|
-
digest: current.digest,
|
|
393
|
-
replacedAt: now,
|
|
394
|
-
reason: 'rollback',
|
|
395
|
-
});
|
|
396
|
-
}
|
|
397
|
-
const record = {
|
|
398
|
-
packageId,
|
|
399
|
-
version: chosenVersion,
|
|
400
|
-
digest: pkg.manifest.digest,
|
|
401
|
-
keyId: pkg.manifest.keyId,
|
|
402
|
-
installedAt: now,
|
|
403
|
-
license: pkg.manifest.license,
|
|
404
|
-
provenance: pkg.manifest.provenance,
|
|
405
|
-
};
|
|
406
|
-
state.active[packageId] = record;
|
|
407
|
-
await this.saveState(state);
|
|
408
|
-
return record;
|
|
419
|
+
state.active[packageId] = record;
|
|
420
|
+
await this.saveState(state);
|
|
421
|
+
return record;
|
|
422
|
+
});
|
|
409
423
|
}
|
|
410
424
|
}
|
|
411
|
-
//# sourceMappingURL=cache.js.map
|
|
@@ -178,6 +178,7 @@ export function parseAndValidateKnowledgePackage(rawOrObj, currentDevWorkspaceVe
|
|
|
178
178
|
if (manifest.files.length > MAX_PACKAGE_FILES) {
|
|
179
179
|
throw new DevWorkspaceError('SECURITY', `Knowledge package file count (${manifest.files.length}) exceeds limit (${MAX_PACKAGE_FILES}).`);
|
|
180
180
|
}
|
|
181
|
+
const seenPaths = new Set();
|
|
181
182
|
for (const entry of manifest.files) {
|
|
182
183
|
if (!entry || typeof entry !== 'object') {
|
|
183
184
|
throw new DevWorkspaceError('SCHEMA', 'Invalid entry in manifest.files.');
|
|
@@ -186,6 +187,11 @@ export function parseAndValidateKnowledgePackage(rawOrObj, currentDevWorkspaceVe
|
|
|
186
187
|
if (typeof f.path !== 'string' || typeof f.sha256 !== 'string' || typeof f.sizeBytes !== 'number') {
|
|
187
188
|
throw new DevWorkspaceError('SCHEMA', 'Manifest file entry missing path, sha256, or sizeBytes.');
|
|
188
189
|
}
|
|
190
|
+
const normKey = f.path.toLowerCase();
|
|
191
|
+
if (seenPaths.has(normKey)) {
|
|
192
|
+
throw new DevWorkspaceError('SECURITY', `Duplicate or conflicting package file path "${f.path}".`);
|
|
193
|
+
}
|
|
194
|
+
seenPaths.add(normKey);
|
|
189
195
|
// Path traversal / archive zip-slip / sensitive file checks
|
|
190
196
|
if (f.path.includes('..') || f.path.startsWith('/') || f.path.startsWith('\\') || /^[A-Za-z]:/.test(f.path)) {
|
|
191
197
|
throw new DevWorkspaceError('SECURITY', `Unsafe archive/file path detected: "${f.path}".`);
|
|
@@ -245,4 +251,3 @@ export function parseAndValidateKnowledgePackage(rawOrObj, currentDevWorkspaceVe
|
|
|
245
251
|
}
|
|
246
252
|
return data;
|
|
247
253
|
}
|
|
248
|
-
//# sourceMappingURL=package.js.map
|
|
@@ -12,8 +12,13 @@ export interface SyncTransport {
|
|
|
12
12
|
export declare function validateSyncRequest(input: Record<string, unknown>): GenericPackageSyncRequest;
|
|
13
13
|
/** Creates an in-process transport backed by a StaticKnowledgeDistributor (home server handler). */
|
|
14
14
|
export declare function createDistributorTransport(distributor: StaticKnowledgeDistributor): SyncTransport;
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
export interface HttpSyncTransportOptions {
|
|
16
|
+
timeoutMs?: number;
|
|
17
|
+
/** Allow plain HTTP for non-loopback hosts (default: false; HTTPS required for remote hosts). */
|
|
18
|
+
allowInsecureHttp?: boolean;
|
|
19
|
+
}
|
|
20
|
+
/** Creates an explicit HTTPS transport using Web Fetch API, blocking untrusted redirects and oversized payloads. */
|
|
21
|
+
export declare function createHttpSyncTransport(baseUrl: string, timeoutMsOrOpts?: number | HttpSyncTransportOptions): SyncTransport;
|
|
17
22
|
export interface SyncPackageResult {
|
|
18
23
|
package: KnowledgePackage;
|
|
19
24
|
installed?: InstalledPackageRecord;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { DevWorkspaceError } from '../../errors/index.js';
|
|
2
2
|
import { parseAndValidateKnowledgePackage } from './package.js';
|
|
3
|
-
import { FORBIDDEN_SYNC_FIELDS, KNOWLEDGE_PACKAGE_SCHEMA_VERSION, } from './types.js';
|
|
3
|
+
import { FORBIDDEN_SYNC_FIELDS, KNOWLEDGE_PACKAGE_SCHEMA_VERSION, MAX_PACKAGE_BYTES, } from './types.js';
|
|
4
4
|
const ALLOWED_SYNC_KEYS = new Set(['packageId', 'version', 'schemaVersion', 'targetPlatform']);
|
|
5
5
|
const FORBIDDEN_SET = new Set(FORBIDDEN_SYNC_FIELDS.map((f) => f.toLowerCase()));
|
|
6
6
|
/**
|
|
@@ -48,24 +48,57 @@ export function createDistributorTransport(distributor) {
|
|
|
48
48
|
},
|
|
49
49
|
};
|
|
50
50
|
}
|
|
51
|
-
|
|
52
|
-
|
|
51
|
+
const LOOPBACK_HOSTS = new Set(['localhost', '127.0.0.1', '[::1]', '::1']);
|
|
52
|
+
/** Creates an explicit HTTPS transport using Web Fetch API, blocking untrusted redirects and oversized payloads. */
|
|
53
|
+
export function createHttpSyncTransport(baseUrl, timeoutMsOrOpts = 15_000) {
|
|
54
|
+
const opts = typeof timeoutMsOrOpts === 'number' ? { timeoutMs: timeoutMsOrOpts } : timeoutMsOrOpts;
|
|
55
|
+
const timeoutMs = opts.timeoutMs ?? 15_000;
|
|
56
|
+
const parsedBase = new URL(baseUrl);
|
|
57
|
+
const isLoopback = LOOPBACK_HOSTS.has(parsedBase.hostname.toLowerCase());
|
|
58
|
+
if (parsedBase.protocol !== 'https:' && !(parsedBase.protocol === 'http:' && (isLoopback || opts.allowInsecureHttp))) {
|
|
59
|
+
throw new DevWorkspaceError('SECURITY', `Refusing insecure home server URL protocol "${parsedBase.protocol}"; HTTPS is required for remote hosts.`);
|
|
60
|
+
}
|
|
53
61
|
const normalizedBase = baseUrl.replace(/\/+$/, '');
|
|
54
62
|
return {
|
|
55
63
|
async get(reqPath, query) {
|
|
56
64
|
const url = new URL(`${normalizedBase}${reqPath}`);
|
|
65
|
+
if (url.origin !== parsedBase.origin) {
|
|
66
|
+
throw new DevWorkspaceError('SECURITY', `Rejected cross-origin request target "${url.origin}".`);
|
|
67
|
+
}
|
|
57
68
|
if (query) {
|
|
58
69
|
for (const [k, v] of Object.entries(query)) {
|
|
59
70
|
if (v !== undefined)
|
|
60
71
|
url.searchParams.set(k, v);
|
|
61
72
|
}
|
|
62
73
|
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
74
|
+
let res;
|
|
75
|
+
try {
|
|
76
|
+
res = await fetch(url.toString(), {
|
|
77
|
+
method: 'GET',
|
|
78
|
+
headers: { accept: 'application/json' },
|
|
79
|
+
redirect: 'manual',
|
|
80
|
+
signal: AbortSignal.timeout(timeoutMs),
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
catch (err) {
|
|
84
|
+
const msg = err.message || String(err);
|
|
85
|
+
if (/cert|tls|ssl|self[- ]signed|unable to verify/i.test(msg)) {
|
|
86
|
+
throw new DevWorkspaceError('SECURITY', `TLS/certificate validation failed for "${parsedBase.origin}": ${msg}`);
|
|
87
|
+
}
|
|
88
|
+
throw err;
|
|
89
|
+
}
|
|
90
|
+
if (res.status >= 300 && res.status < 400) {
|
|
91
|
+
const location = res.headers.get('location') ?? 'unknown';
|
|
92
|
+
throw new DevWorkspaceError('SECURITY', `Rejected HTTP redirect (${res.status}) to "${location}"; redirects to untrusted hosts are disallowed.`);
|
|
93
|
+
}
|
|
94
|
+
const contentLen = Number(res.headers.get('content-length') ?? '0');
|
|
95
|
+
if (Number.isFinite(contentLen) && contentLen > MAX_PACKAGE_BYTES) {
|
|
96
|
+
throw new DevWorkspaceError('SECURITY', `Remote response (${contentLen} bytes) exceeds max limit (${MAX_PACKAGE_BYTES}).`);
|
|
97
|
+
}
|
|
68
98
|
const body = await res.text();
|
|
99
|
+
if (Buffer.byteLength(body, 'utf8') > MAX_PACKAGE_BYTES) {
|
|
100
|
+
throw new DevWorkspaceError('SECURITY', `Remote payload exceeds max limit (${MAX_PACKAGE_BYTES} bytes).`);
|
|
101
|
+
}
|
|
69
102
|
const headers = {};
|
|
70
103
|
res.headers.forEach((value, key) => {
|
|
71
104
|
headers[key.toLowerCase()] = value;
|
|
@@ -209,4 +242,3 @@ export class KnowledgeSyncClient {
|
|
|
209
242
|
}
|
|
210
243
|
}
|
|
211
244
|
}
|
|
212
|
-
//# sourceMappingURL=sync.js.map
|
package/dist/standards/index.js
CHANGED