Files
msd-core/sdk/src/sdk-package-compatibility.ts
Tom Boucher 334a64168e chore(npm): rebrand packages to @opengsd scope (#127)
* chore(npm): rebrand packages to @opengsd scope

Rename:
- get-shit-done-redux → @opengsd/get-shit-done-redux
- @gsd-redux/sdk → @opengsd/gsd-sdk

Add publishConfig.access=public for first-time scoped publish.
CLI binary names (get-shit-done-redux, gsd-sdk, gsd-tools) unchanged.

Sweeps install commands, npx invocations, CI publish/version-check
workflows, tests, docs, READMEs (all translations), and the
PACKAGE_NAME constant in check-latest-version.

Bumps qs 6.15.1 → 6.15.2 to clear a moderate advisory surfaced by
the audit-clean test (GHSA-q8mj-m7cp-5q26).

Closes #126

* chore: pin 2.0.0 release + remove canary workflow

- Bump both packages 1.50.0-canary.0 → 2.0.0 for first @opengsd publish
- Remove .github/workflows/canary.yml and canary dist-tag handling in
  release.yml / release-sdk.yml
- Drop canary section from VERSIONING.md

Refs #126

* chore: address review findings + harden tarball-smoke timeout

- .changeset/opengsd-org-rename.md: match project's custom
  parse.cjs frontmatter (type: Changed / pr: 127); the scoped
  @changesets/cli keys were silently rejected.
- CONTEXT.md: drop two canary-stream policy lines and a dangling
  DEFECT.CANARY-VERSION-LEAK.cross-ref now that canary.yml is gone.
- tests/release-tarball-smoke.install.test.cjs: pass
  timeout: 600_000 for npm pack + global install; the 3-minute
  runNpm default was timing out on slower Docker hosts (cartographer).

Refs #126

* fix(sdk): add missing type/runtime devDependencies for build

prepublishOnly invokes tsc which couldn't resolve @types/node,
@types/ws, or synckit. They had been hoisted from root but were
not declared in sdk/'s own package.json — first publish from a
clean SDK tree failed.

Refs #126

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* fix(ci): use npm pack stdout instead of glob to find tarball

`npm pack --silent` for a scoped package (@opengsd/get-shit-done-redux)
produces `opengsd-get-shit-done-redux-*.tgz`, not `get-shit-done-redux-*.tgz`.
Capture the filename from stdout instead of a hardcoded glob so the step
works regardless of package name format.

Fixes smoke (ubuntu-latest, 22, false) CI failure.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* ci: treat workflow-file changes as test-skip eligible

`.github/workflows/install-smoke.yml` (and other workflow files)
were in neither `test.yml` paths nor `test-skip.yml` paths-ignore,
so neither workflow ran on a workflow-only commit — leaving the
required test-skip check perpetually missing.

Refs #126

* chore: reset version to 1.0.0 for first @opengsd publish

Nothing has been published yet under the @opengsd scope, so the
inaugural release uses 1.0.0 rather than 2.0.0. The "major bump"
in the changeset reflects the breaking install-command change for
users migrating from the prior unscoped `get-shit-done-redux`, not
a numeric continuation from a 1.x line under the new identity.

Refs #126

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

---------

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-22 16:22:41 -04:00

142 lines
4.6 KiB
TypeScript

import { existsSync } from 'node:fs';
import { createRequire } from 'node:module';
import { homedir } from 'node:os';
import { join } from 'node:path';
import { fileURLToPath } from 'node:url';
import { GSDError, ErrorClassification } from './errors.js';
export type LegacySdkAsset = 'gsd-tools' | 'core-cjs';
export interface LegacySdkAssetResolution {
asset: LegacySdkAsset;
path: string | null;
fallbackPath: string;
probes: string[];
}
interface LegacySdkCompatibilityDeps {
existsSync?: (path: string) => boolean;
homeDir?: string;
createRequire?: typeof createRequire;
}
export const BUNDLED_GSD_TOOLS_PATH = fileURLToPath(
new URL('../../get-shit-done/bin/gsd-tools.cjs', import.meta.url),
);
export const BUNDLED_CORE_CJS_PATH = fileURLToPath(
new URL('../../get-shit-done/bin/lib/core.cjs', import.meta.url),
);
export const BUNDLED_GSD_TEMPLATES_DIR = fileURLToPath(
new URL('../../get-shit-done/templates', import.meta.url),
);
export const BUNDLED_GSD_AGENTS_DIR = fileURLToPath(
new URL('../../agents', import.meta.url),
);
const LEGACY_ASSET_SUBPATH: Record<LegacySdkAsset, string> = {
'gsd-tools': 'gsd-tools.cjs',
'core-cjs': join('lib', 'core.cjs'),
};
const BUNDLED_LEGACY_ASSET_PATH: Record<LegacySdkAsset, string> = {
'gsd-tools': BUNDLED_GSD_TOOLS_PATH,
'core-cjs': BUNDLED_CORE_CJS_PATH,
};
export function resolveLegacyInstallDir(homeDir: string = homedir()): string {
return join(homeDir, '.claude', 'get-shit-done');
}
export function resolveLegacyTemplatesDir(homeDir: string = homedir()): string {
return join(resolveLegacyInstallDir(homeDir), 'templates');
}
export function resolveLegacyWorkflowsDir(homeDir: string = homedir()): string {
return join(resolveLegacyInstallDir(homeDir), 'workflows');
}
export function resolveLegacyUserProfilePath(homeDir: string = homedir()): string {
return join(resolveLegacyInstallDir(homeDir), 'USER-PROFILE.md');
}
export function resolveLegacySkillsDir(homeDir: string = homedir()): string {
return join(resolveLegacyInstallDir(homeDir), 'skills');
}
export function resolveBundledTemplatesDir(): string {
return BUNDLED_GSD_TEMPLATES_DIR;
}
export function resolveBundledAgentsDir(): string {
return BUNDLED_GSD_AGENTS_DIR;
}
function legacyAssetProbes(asset: LegacySdkAsset, projectDir: string, homeDir: string): string[] {
const suffix = LEGACY_ASSET_SUBPATH[asset];
return [
BUNDLED_LEGACY_ASSET_PATH[asset],
join(projectDir, '.claude', 'get-shit-done', 'bin', suffix),
join(homeDir, '.claude', 'get-shit-done', 'bin', suffix),
];
}
export function probeLegacySdkAsset(
asset: LegacySdkAsset,
projectDir: string,
deps: LegacySdkCompatibilityDeps = {},
): LegacySdkAssetResolution {
const pathExists = deps.existsSync ?? existsSync;
const probes = legacyAssetProbes(asset, projectDir, deps.homeDir ?? homedir());
return {
asset,
path: probes.find(candidate => pathExists(candidate)) ?? null,
fallbackPath: probes[probes.length - 1]!,
probes,
};
}
/**
* Resolve the legacy `gsd-tools.cjs` executable path through the SDK Package Seam Module.
*
* Preserves historical behavior: if no probe exists, return the final fallback path so
* downstream subprocess errors still show a concrete location.
*/
export function resolveGsdToolsPath(projectDir: string, deps: LegacySdkCompatibilityDeps = {}): string {
const resolution = probeLegacySdkAsset('gsd-tools', projectDir, deps);
return resolution.path ?? resolution.fallbackPath;
}
function missingLegacyCoreMessage(resolution: LegacySdkAssetResolution): string {
return [
'state load: get-shit-done/bin/lib/core.cjs not found.',
`Checked: ${resolution.probes.join(', ')}`,
'Install GSD (e.g. npm i -g @opengsd/get-shit-done-redux) or clone with get-shit-done next to the SDK.',
].join(' ');
}
/**
* Load `loadConfig(cwd)` from the legacy CJS install through one compatibility seam.
*/
export function loadLegacyCoreConfig(projectDir: string, deps: LegacySdkCompatibilityDeps = {}): Record<string, unknown> {
const resolution = probeLegacySdkAsset('core-cjs', projectDir, deps);
if (!resolution.path) {
throw new GSDError(
missingLegacyCoreMessage(resolution),
ErrorClassification.Blocked,
);
}
const req = (deps.createRequire ?? createRequire)(import.meta.url);
const mod = req(resolution.path) as Partial<{ loadConfig: (cwd: string) => Record<string, unknown> }>;
if (typeof mod.loadConfig !== 'function') {
throw new GSDError(
`state load: invalid core.cjs at ${resolution.path} (missing loadConfig(cwd)).`,
ErrorClassification.Blocked,
);
}
return mod.loadConfig(projectDir);
}