mancode 0.4.0 → 0.4.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/dist/cli.js CHANGED
@@ -111,7 +111,7 @@ import {
111
111
  workflowMetadataDigest,
112
112
  writeOperationReservation,
113
113
  writeProjectFacts
114
- } from "./chunk-S3BAOJPP.js";
114
+ } from "./chunk-3FOBYCF4.js";
115
115
  import {
116
116
  DEFAULT_MANCODE_END_MARKER,
117
117
  DEFAULT_MANCODE_START_MARKER,
@@ -134,7 +134,7 @@ import {
134
134
  stageV3AdapterUpgradeFiles,
135
135
  v3AdapterTargetPath,
136
136
  v3AdapterVersionsFromStatuses
137
- } from "./chunk-K3MYY47M.js";
137
+ } from "./chunk-LYRYNJHW.js";
138
138
 
139
139
  // src/cli.ts
140
140
  import { Option, program } from "commander";
@@ -164,8 +164,6 @@ var CompatibilityGateError = class extends Error {
164
164
  this.details = details;
165
165
  this.name = "CompatibilityGateError";
166
166
  }
167
- code;
168
- details;
169
167
  };
170
168
  function evaluateCompatibilityGate(input) {
171
169
  const failures = [];
@@ -5185,8 +5183,31 @@ async function commitTaskOperation(context, previous) {
5185
5183
  { canAbort: false }
5186
5184
  );
5187
5185
  throwIfOperationCrashInjected(previous.type, "commit");
5186
+ await refreshActiveSessionRevision(context);
5188
5187
  return next;
5189
5188
  }
5189
+ async function refreshActiveSessionRevision(context) {
5190
+ try {
5191
+ const session = await readSession(
5192
+ context.projectRoot,
5193
+ context.session.sessionId
5194
+ );
5195
+ if (session === null || session.status !== "active" || session.activeTaskRef === null || !sameTaskRef(session.activeTaskRef, context.taskRef)) {
5196
+ return;
5197
+ }
5198
+ const task = await context.store.readTaskSnapshot(context.taskRef);
5199
+ if (task.metadata.status !== "in_progress" && task.metadata.status !== "blocked") {
5200
+ return;
5201
+ }
5202
+ await resumeSession(context.projectRoot, session.sessionId, {
5203
+ taskRef: context.taskRef,
5204
+ workflowMode: task.metadata.workflowMode,
5205
+ taskRevision: task.metadata.revision,
5206
+ now: context.now
5207
+ });
5208
+ } catch {
5209
+ }
5210
+ }
5190
5211
  async function handleTaskOperationFailure(context, journal) {
5191
5212
  if (journal.state === "committed" || journal.state === "aborted") return;
5192
5213
  if (hasBusinessWriteIntent(journal)) {
@@ -6835,8 +6856,8 @@ import { getEncoding } from "js-tiktoken";
6835
6856
  var CONTEXT_PACK_TOKENIZER_ID = "cl100k_base@tiktoken-0.7.0";
6836
6857
  var CONTEXT_PACK_BUDGET_ALGORITHM_VERSION = "complete-section-v1";
6837
6858
  var CONTEXT_PACK_DEFAULT_BUDGETS = {
6838
- bootstrap: 400,
6839
- task: 1200
6859
+ bootstrap: 1600,
6860
+ task: 5e3
6840
6861
  };
6841
6862
  var fixedTokenizer = getEncoding("cl100k_base");
6842
6863
  var FIXED_CONTEXT_PACK_TOKEN_COUNTER = {
@@ -9597,7 +9618,7 @@ async function activateLegacyMigration(input) {
9597
9618
  if (session === null || session.status !== "active") {
9598
9619
  throw new Error("MANCODE_SESSION_NOT_FOUND");
9599
9620
  }
9600
- const store = new (await import("./store-LD5VRGON.js")).V3ContextStore(root);
9621
+ const store = new (await import("./store-GCLUP5IO.js")).V3ContextStore(root);
9601
9622
  const project = await store.readProjectSnapshot();
9602
9623
  const stage = await readMigrationStage(root, input.stageId);
9603
9624
  if (stage.state !== "staged" || stage.revision !== input.expectedStageRevision) {
@@ -9860,7 +9881,7 @@ async function activateLegacyMigration(input) {
9860
9881
  for (const action of payload.actions.filter(
9861
9882
  (action2) => action2.kind === "v3_adapter_file"
9862
9883
  )) {
9863
- const { applyV3AdapterFilePlan: applyV3AdapterFilePlan2 } = await import("./v3-adapter-URAKH6BV.js");
9884
+ const { applyV3AdapterFilePlan: applyV3AdapterFilePlan2 } = await import("./v3-adapter-E6VEEDCF.js");
9864
9885
  await applyV3AdapterFilePlan2(root, action);
9865
9886
  }
9866
9887
  journal = await completeActivationStep(
@@ -13716,7 +13737,7 @@ async function upgradeV3Adapters(input) {
13716
13737
  if (unfinished.length > 0) {
13717
13738
  throw new Error("MANCODE_ADAPTER_UPGRADE_OPERATION_PENDING");
13718
13739
  }
13719
- const actualVersions = await import("./v3-adapter-URAKH6BV.js").then(
13740
+ const actualVersions = await import("./v3-adapter-E6VEEDCF.js").then(
13720
13741
  ({ inspectV3AdapterVersions: inspectV3AdapterVersions2 }) => inspectV3AdapterVersions2(
13721
13742
  root,
13722
13743
  managedAdapterNames(project.manifest.managedAdapters)
@@ -13845,6 +13866,7 @@ async function upgradeV3Adapters(input) {
13845
13866
  async (platform) => [platform, await inspectV3Adapter(root, platform)]
13846
13867
  )
13847
13868
  );
13869
+ await removeAdapterUpgradePreview(root, operationId);
13848
13870
  return {
13849
13871
  ...resultBase,
13850
13872
  state: "committed",
@@ -14175,6 +14197,22 @@ function adapterUpgradePreviewPath(root, operationId) {
14175
14197
  "preview.json"
14176
14198
  );
14177
14199
  }
14200
+ async function removeAdapterUpgradePreview(root, operationId) {
14201
+ const upgradeRoot = path24.join(
14202
+ path24.resolve(root),
14203
+ ".mancode",
14204
+ "staging",
14205
+ "adapters",
14206
+ "upgrade"
14207
+ );
14208
+ const operationRoot = path24.dirname(
14209
+ adapterUpgradePreviewPath(root, operationId)
14210
+ );
14211
+ if (path24.dirname(operationRoot) !== upgradeRoot) {
14212
+ throw new Error("MANCODE_ADAPTER_UPGRADE_STAGING_INVALID");
14213
+ }
14214
+ await rm9(operationRoot, { recursive: true, force: true });
14215
+ }
14178
14216
  async function readAdapterUpgradePreview(root, operationId) {
14179
14217
  const target = adapterUpgradePreviewPath(root, operationId);
14180
14218
  try {
@@ -19040,7 +19078,6 @@ var ContextResolver = class {
19040
19078
  this.store = options.store ?? new V3ContextStore(options.projectRoot);
19041
19079
  this.now = options.now ?? (() => /* @__PURE__ */ new Date());
19042
19080
  }
19043
- options;
19044
19081
  store;
19045
19082
  now;
19046
19083
  async resolve(request) {
@@ -19332,7 +19369,7 @@ function buildStablePack(snapshot, session, request, writeBlockers, now) {
19332
19369
  [task.fingerprint, coordination.fingerprint, project.fingerprint],
19333
19370
  true
19334
19371
  ),
19335
- runtimeSection("/capabilities", capabilities, true),
19372
+ runtimeSection("/capabilities", capabilitiesProjection(capabilities), true),
19336
19373
  runtimeSection(
19337
19374
  "/transportFreshness",
19338
19375
  transportFreshnessProjection(capabilities),
@@ -19427,7 +19464,11 @@ function buildRepairPack(snapshot, session, request, repair, now) {
19427
19464
  true
19428
19465
  ),
19429
19466
  derivedSection("/conflicts", repair.issues, [snapshot.fingerprint], true),
19430
- runtimeSection("/capabilities", capabilities, true),
19467
+ runtimeSection(
19468
+ "/capabilities",
19469
+ capabilitiesProjection(capabilities),
19470
+ true
19471
+ ),
19431
19472
  runtimeSection(
19432
19473
  "/transportFreshness",
19433
19474
  transportFreshnessProjection(capabilities),
@@ -19467,6 +19508,7 @@ function sessionProjection(session) {
19467
19508
  };
19468
19509
  }
19469
19510
  function activeTaskProjection(task) {
19511
+ const governance = task.metadata.governance;
19470
19512
  return {
19471
19513
  taskRef: task.metadata.taskRef,
19472
19514
  workflowMode: task.metadata.workflowMode,
@@ -19477,7 +19519,14 @@ function activeTaskProjection(task) {
19477
19519
  currentStep: task.metadata.currentStep,
19478
19520
  ownerActorId: task.metadata.ownerActorId,
19479
19521
  implementationScope: task.metadata.implementationScope,
19480
- governance: task.metadata.governance,
19522
+ governance: {
19523
+ requirementsStatus: governance.requirementsStatus,
19524
+ planVersion: governance.planVersion,
19525
+ planDecision: governance.planDecision,
19526
+ policyVersions: governance.policyVersions,
19527
+ reviewStatus: governance.reviewStatus,
19528
+ verificationStatus: governance.verificationStatus
19529
+ },
19481
19530
  plan: task.plan?.artifactRef ?? null,
19482
19531
  latestCheckpointRef: task.metadata.latestCheckpointRef
19483
19532
  };
@@ -19531,7 +19580,6 @@ function projectProjection(project) {
19531
19580
  teamPolicy: project.policy.policy,
19532
19581
  defaultVisibility: project.policy.defaultVisibility,
19533
19582
  schemaEpoch: project.manifest.epoch,
19534
- activationState: project.manifest.activationState,
19535
19583
  facts: project.projectFacts,
19536
19584
  confirmedDecisions: project.confirmedDecisions
19537
19585
  };
@@ -19597,6 +19645,13 @@ function transportFreshnessProjection(capabilities) {
19597
19645
  remoteRevision: capabilities.remoteRevision
19598
19646
  };
19599
19647
  }
19648
+ function capabilitiesProjection(capabilities) {
19649
+ return {
19650
+ claimAcquisition: capabilities.claimAcquisition,
19651
+ writeGuard: capabilities.writeGuard,
19652
+ transport: capabilities.transport
19653
+ };
19654
+ }
19600
19655
  function parentFreshnessSection(snapshot) {
19601
19656
  if (snapshot.task.metadata.parent === null) return null;
19602
19657
  const value = snapshot.parentReadError !== null ? { state: "unavailable", reasons: ["parent_unavailable"] } : {
@@ -32698,7 +32753,7 @@ function openMutationContext(manifest, input) {
32698
32753
  }
32699
32754
  function prepareOwnershipFence(context, taskBundle, expectedPredecessorBundleDigest) {
32700
32755
  const metadata = metadataFromBundle2(taskBundle);
32701
- assertRemoteTaskEligible(metadata);
32756
+ assertRemoteTaskCoordination(metadata);
32702
32757
  assertTaskBundleIdentity(taskBundle, context.taskRef);
32703
32758
  if (metadata.ownerActorId === null) {
32704
32759
  throw new Error("MANCODE_TASK_OWNER_REQUIRED");
@@ -32707,6 +32762,7 @@ function prepareOwnershipFence(context, taskBundle, expectedPredecessorBundleDig
32707
32762
  throw new Error("MANCODE_TASK_BUNDLE_DIVERGED");
32708
32763
  }
32709
32764
  if (context.fence === null) {
32765
+ assertRemoteTaskEligible(metadata);
32710
32766
  if (metadata.ownerActorId !== context.input.actorId || metadata.ownershipEpoch !== 0 || taskBundle.ownershipEpoch !== 0) {
32711
32767
  throw new Error("MANCODE_TASK_OWNER_REQUIRED");
32712
32768
  }
@@ -32719,6 +32775,7 @@ function prepareOwnershipFence(context, taskBundle, expectedPredecessorBundleDig
32719
32775
  throw new Error("MANCODE_TASK_REVISION_CONFLICT");
32720
32776
  }
32721
32777
  if (taskBundle.taskRevision === context.fence.taskRevision) {
32778
+ assertRemoteTaskRebindEligible(metadata);
32722
32779
  if (taskBundle.aggregateDigest !== context.fence.aggregateDigest) {
32723
32780
  throw new Error("MANCODE_SPLIT_BRAIN");
32724
32781
  }
@@ -32733,6 +32790,7 @@ function prepareOwnershipFence(context, taskBundle, expectedPredecessorBundleDig
32733
32790
  taskBundle
32734
32791
  );
32735
32792
  }
32793
+ assertRemoteTaskEligible(metadata);
32736
32794
  }
32737
32795
  const codeHeadChanged = context.taskBundle !== null && (taskBundle.codeRef.branch !== context.taskBundle.codeRef.branch || taskBundle.codeRef.head !== context.taskBundle.codeRef.head);
32738
32796
  const fence = buildFence(context, taskBundle, metadata.ownerActorId);
@@ -33331,7 +33389,19 @@ function metadataFromBundle2(taskBundle) {
33331
33389
  return metadata;
33332
33390
  }
33333
33391
  function assertRemoteTaskEligible(metadata) {
33334
- if (metadata.workflowMode !== "manteam" || metadata.coordination !== "team" || metadata.status !== "in_progress") {
33392
+ assertRemoteTaskCoordination(metadata);
33393
+ if (metadata.status !== "in_progress") {
33394
+ throw new Error("MANCODE_REMOTE_COORDINATION_TASK_INVALID");
33395
+ }
33396
+ }
33397
+ function assertRemoteTaskRebindEligible(metadata) {
33398
+ assertRemoteTaskCoordination(metadata);
33399
+ if (metadata.status !== "in_progress" && metadata.status !== "blocked") {
33400
+ throw new Error("MANCODE_REMOTE_COORDINATION_TASK_INVALID");
33401
+ }
33402
+ }
33403
+ function assertRemoteTaskCoordination(metadata) {
33404
+ if (metadata.workflowMode !== "manteam" || metadata.coordination !== "team") {
33335
33405
  throw new Error("MANCODE_REMOTE_COORDINATION_TASK_INVALID");
33336
33406
  }
33337
33407
  }
@@ -34907,7 +34977,7 @@ async function assertCleanGitWorktree(projectRoot, materializedTaskRef) {
34907
34977
  cwd: projectRoot,
34908
34978
  windowsHide: true
34909
34979
  });
34910
- if (stdout2.trim()) throw new Error("MANCODE_HANDOFF_DIRTY_WORKTREE");
34980
+ if (stdout2.trim()) throw new Error("MANCODE_GIT_REF_DIRTY_WORKTREE");
34911
34981
  }
34912
34982
  async function hasCommittedHandoffCheckpoint(context) {
34913
34983
  const checkpoint = context.task.latestCheckpoint;
@@ -37054,7 +37124,6 @@ var FileSystemTransportMigrationConfigAdapter = class {
37054
37124
  this.coordinationStore = coordinationStore;
37055
37125
  this.projectRoot = path61.resolve(projectRoot);
37056
37126
  }
37057
- coordinationStore;
37058
37127
  projectRoot;
37059
37128
  async read() {
37060
37129
  return readProjectConfigFile(this.projectRoot);
@@ -37095,9 +37164,6 @@ var LocalTransportMigrationSourceAdapter = class {
37095
37164
  this.authorityId = authorityId;
37096
37165
  this.coordinationDomainId = coordinationDomainId2;
37097
37166
  }
37098
- context;
37099
- authorityId;
37100
- coordinationDomainId;
37101
37167
  mode = "local";
37102
37168
  remote = null;
37103
37169
  async freeze(input) {
@@ -37304,9 +37370,6 @@ var GitRefTransportMigrationSourceAdapter = class {
37304
37370
  this.store = store;
37305
37371
  this.remote = requireRemote(context.sourceConfig.transport.remote);
37306
37372
  }
37307
- context;
37308
- authorityId;
37309
- store;
37310
37373
  mode = "git-ref";
37311
37374
  remote;
37312
37375
  async freeze(input) {
@@ -37434,9 +37497,6 @@ var FileStagedTransportTarget = class {
37434
37497
  this.authorityId = authorityId;
37435
37498
  this.coordinationDomainId = coordinationDomainId2;
37436
37499
  }
37437
- context;
37438
- authorityId;
37439
- coordinationDomainId;
37440
37500
  async stage(manifestValue) {
37441
37501
  const manifest = parseTransportMigrationManifest(manifestValue);
37442
37502
  this.assertManifestTarget(manifest);
@@ -44531,6 +44591,7 @@ async function publishTaskMutation(input) {
44531
44591
  if (recovery.state !== "committed" || recovery.materialization === null) {
44532
44592
  throw new Error("MANCODE_REMOTE_RECEIPT_MISMATCH");
44533
44593
  }
44594
+ await refreshGitRefSessionProjection(input);
44534
44595
  return {
44535
44596
  remoteRevision: mutation.remoteRevision,
44536
44597
  ownershipEpoch: mutation.ownershipEpoch,
@@ -44557,6 +44618,38 @@ async function publishTaskMutation(input) {
44557
44618
  throw error;
44558
44619
  }
44559
44620
  }
44621
+ async function refreshGitRefSessionProjection(input) {
44622
+ try {
44623
+ const session = await readSession(
44624
+ input.context.projectRoot,
44625
+ input.context.session.sessionId
44626
+ );
44627
+ if (session === null || session.status !== "active" || session.activeTaskRef === null || !sameTaskRef(session.activeTaskRef, input.context.taskRef)) {
44628
+ return;
44629
+ }
44630
+ const task = await input.context.store.readTaskSnapshot(
44631
+ input.context.taskRef
44632
+ );
44633
+ if (task.metadata.status === "in_progress" || task.metadata.status === "blocked") {
44634
+ await resumeSession(input.context.projectRoot, session.sessionId, {
44635
+ taskRef: input.context.taskRef,
44636
+ workflowMode: task.metadata.workflowMode,
44637
+ taskRevision: task.metadata.revision,
44638
+ now: input.now
44639
+ });
44640
+ return;
44641
+ }
44642
+ await clearSessionTaskPointer(
44643
+ input.context.projectRoot,
44644
+ session.sessionId,
44645
+ {
44646
+ expectedTaskRef: input.context.taskRef,
44647
+ now: input.now
44648
+ }
44649
+ );
44650
+ } catch {
44651
+ }
44652
+ }
44560
44653
  function assertScopeChangeEligible2(context, fence, scope) {
44561
44654
  const metadata = context.task.metadata;
44562
44655
  if (metadata.workflowMode !== "manteam" || metadata.status !== "in_progress" || metadata.ownerActorId !== context.session.actorId || fence.ownerActorId !== context.session.actorId) {
@@ -45718,10 +45811,16 @@ async function workflowVerifyV3(rootDir, args, options) {
45718
45811
  }
45719
45812
  try {
45720
45813
  const project = await readV3CommandProject(rootDir);
45814
+ const taskRef = parseTaskRef(task);
45815
+ assertDeferredGitRefSyncOption(
45816
+ project.project.config.transport.mode,
45817
+ taskRef.namespace === "shared",
45818
+ options.sync
45819
+ );
45721
45820
  const session = await resolveV3CommandSession(project, options);
45722
45821
  const result2 = await recordV3Verification({
45723
45822
  projectRoot: project.projectRoot,
45724
- taskRef: parseTaskRef(task),
45823
+ taskRef,
45725
45824
  sessionId: session.sessionId,
45726
45825
  expectedTaskRevision,
45727
45826
  verification: await readWorkflowJsonInputFile(
@@ -45768,10 +45867,16 @@ async function workflowReviewV3(rootDir, args, options) {
45768
45867
  }
45769
45868
  try {
45770
45869
  const project = await readV3CommandProject(rootDir);
45870
+ const taskRef = parseTaskRef(task);
45871
+ assertDeferredGitRefSyncOption(
45872
+ project.project.config.transport.mode,
45873
+ taskRef.namespace === "shared",
45874
+ options.sync
45875
+ );
45771
45876
  const session = await resolveV3CommandSession(project, options);
45772
45877
  const result2 = await applyV3ReviewLedger({
45773
45878
  projectRoot: project.projectRoot,
45774
- taskRef: parseTaskRef(task),
45879
+ taskRef,
45775
45880
  sessionId: session.sessionId,
45776
45881
  expectedTaskRevision,
45777
45882
  review: await readWorkflowJsonInputFile(
@@ -45835,8 +45940,13 @@ async function workflowPlanV3(rootDir, args, options) {
45835
45940
  }
45836
45941
  try {
45837
45942
  const project = await readV3CommandProject(rootDir);
45838
- const session = await resolveV3CommandSession(project, options);
45839
45943
  const taskRef = parseTaskRef(task);
45944
+ assertDeferredGitRefSyncOption(
45945
+ project.project.config.transport.mode,
45946
+ taskRef.namespace === "shared",
45947
+ options.sync
45948
+ );
45949
+ const session = await resolveV3CommandSession(project, options);
45840
45950
  const plan = action === "revise" ? await readWorkflowInputFile(
45841
45951
  project.projectRoot,
45842
45952
  options.file
@@ -45893,8 +46003,13 @@ async function workflowRequirementsV3(rootDir, args, options) {
45893
46003
  }
45894
46004
  try {
45895
46005
  const project = await readV3CommandProject(rootDir);
45896
- const session = await resolveV3CommandSession(project, options);
45897
46006
  const taskRef = parseTaskRef(task);
46007
+ assertDeferredGitRefSyncOption(
46008
+ project.project.config.transport.mode,
46009
+ taskRef.namespace === "shared",
46010
+ options.sync
46011
+ );
46012
+ const session = await resolveV3CommandSession(project, options);
45898
46013
  const requirementsInput = await readWorkflowJsonInputFile(
45899
46014
  project.projectRoot,
45900
46015
  options.file
@@ -45935,6 +46050,15 @@ async function workflowRequirementsV3(rootDir, args, options) {
45935
46050
  function parseExpectedTaskRevision(options) {
45936
46051
  return options.expectedRevision === void 0 ? null : parseExactPositiveInteger(options.expectedRevision);
45937
46052
  }
46053
+ function assertDeferredGitRefSyncOption(transportMode, sharedTask, sync) {
46054
+ if (sync !== true) return;
46055
+ if (transportMode === "git-ref" && sharedTask) {
46056
+ throw new Error(
46057
+ "MANCODE_GIT_REF_DEFERRED_SYNC_REQUIRED: run this mutation without --sync, commit the resulting .mancode/shared authority changes with the matching code head, then run mancode team sync push <shared:ULID> --expected-task-revision <n>."
46058
+ );
46059
+ }
46060
+ throw new Error("MANCODE_GIT_REF_SYNC_UNAVAILABLE");
46061
+ }
45938
46062
  function parseV3PlanDecision(value) {
45939
46063
  if (value === void 0) return void 0;
45940
46064
  if (value === "plan_only" || value === "governed_execution") return value;
@@ -45981,6 +46105,12 @@ async function workflowCreateV3(rootDir, args, options) {
45981
46105
  }
45982
46106
  try {
45983
46107
  const project = await readV3CommandProject(rootDir);
46108
+ const parsedWorkflowMode = parseV3WorkflowMode(workflowMode);
46109
+ assertDeferredGitRefSyncOption(
46110
+ project.project.config.transport.mode,
46111
+ parsedWorkflowMode === "manteam",
46112
+ options.sync
46113
+ );
45984
46114
  const session = await resolveV3CommandSession(project, options);
45985
46115
  const parentOption = options.parent ?? options.parentTask;
45986
46116
  if (options.parentTask !== void 0 && options.parent === void 0) {
@@ -45999,7 +46129,7 @@ async function workflowCreateV3(rootDir, args, options) {
45999
46129
  const result2 = await createV3Workflow({
46000
46130
  projectRoot: project.projectRoot,
46001
46131
  task,
46002
- workflowMode: parseV3WorkflowMode(workflowMode),
46132
+ workflowMode: parsedWorkflowMode,
46003
46133
  sessionId: session.sessionId,
46004
46134
  client: commandClient(options.client),
46005
46135
  parentTaskRef: parentOption === void 0 ? null : parseTaskRef(parentOption),