@useshifu/coding-harness 0.3.10 → 0.3.11
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 +16 -2
- package/bin/shifu-harness.js +133 -27
- package/commands/shifu-sync.md +4 -2
- package/package.json +1 -1
- package/skills/shifu-sync/SKILL.md +12 -4
package/README.md
CHANGED
|
@@ -32,6 +32,8 @@ To disconnect this device, run `npx --yes @useshifu/coding-harness disconnect --
|
|
|
32
32
|
|
|
33
33
|
## Operate
|
|
34
34
|
|
|
35
|
+
Version `0.3.11` adds rolling days-based windows and explicit force replacement of reviewed segments. Force replacement requires backend migration 049 and the matching connector endpoints to be deployed first.
|
|
36
|
+
|
|
35
37
|
```sh
|
|
36
38
|
npx --yes @useshifu/coding-harness status --harness codex
|
|
37
39
|
npx --yes @useshifu/coding-harness sessions --harness codex --hours 24
|
|
@@ -43,6 +45,8 @@ npx --yes @useshifu/coding-harness sync-files --harness codex
|
|
|
43
45
|
|
|
44
46
|
To select by session count instead of a time window, run `sessions --harness codex --count 5`. It selects the five most recently updated eligible sessions, newest first, without an hours cutoff. Current and setup sessions are excluded. `selectedSessionRefs` fixes that selection; `sessions` contains pending segments and `skippedSessions` reports already-synced sessions. Skipped sessions are not replaced with older ones. Review each pending session with `review --harness codex --session-ref <sessionRef> --all`. After an accepted segment, request the next with `sessions --harness codex --session-ref <sessionRef> --all` until that selected session is exhausted. Keep the original references instead of selecting another five.
|
|
45
47
|
|
|
48
|
+
Time-window selection accepts any positive whole number of days or hours. `sessions --harness codex --days 3` uses the same window as `--hours 72`; pass the same window to `review`. `--days 7` also works. Mixed, missing, invalid, or unsupported options fail explicitly. A recently active session with older unsynced turns appears in `blockedSessions`: sync cannot skip those turns. Explicitly select that session with `--session-ref <sessionRef> --all` to backfill in chronological segments of at most 12 turns.
|
|
49
|
+
|
|
46
50
|
Manual session sync runs immediately, independently of the hourly schedule. If a segment fails, report it as failed/pending; a checkpoint advances only after a matching server receipt. Report completed, already-synced, and failed session counts separately.
|
|
47
51
|
|
|
48
52
|
To upgrade an existing installation, run `npx --yes @useshifu/coding-harness@latest install --harness codex` (or `claude_code` / `opencode`). It replaces the local runner and harness instruction while preserving the connection, checkpoints, and schedule. Reconnecting is unnecessary. `status` includes `runnerVersion` so you can verify the installed version.
|
|
@@ -73,6 +77,16 @@ The AI Profile page shows detected categories, model and thinking labels, and Je
|
|
|
73
77
|
|
|
74
78
|
## Recommended package updates
|
|
75
79
|
|
|
76
|
-
The connection endpoint returns `recommendedPackageVersion`, currently pinned to
|
|
80
|
+
The connection endpoint returns `recommendedPackageVersion`, currently pinned to `0.3.10` (publish this release before deploying the recommendation). Before `sync`, `sync-files`, `approve`, or `scheduled-sync`, the runner compares its embedded release version with that property. An older runner installs the exact recommended release through npm and resumes the original command with the updated runner. Equal or newer runners continue unchanged. Explicitly recommended major releases follow the same comparison rule. Missing or invalid recommendations, connection failures, and npm failures do not block sync. The connection, pending work, checkpoints, and schedule are preserved.
|
|
81
|
+
|
|
82
|
+
This update mechanism first ships in `0.3.10`. Runners from earlier releases need a one-time installation of a release containing it (`npx --yes @useshifu/coding-harness@0.3.11 install --harness codex`). Raise the server recommendation only after the target release is published and its backend requirements are deployed.
|
|
83
|
+
|
|
84
|
+
## Replace previously synced work
|
|
85
|
+
|
|
86
|
+
An explicit force request re-reviews the original accepted segments and replaces their current work evidence and claims while retaining history. It does not reset or lower checkpoints, and never changes scheduled sync or AI Profile observations.
|
|
87
|
+
|
|
88
|
+
1. Discover accepted targets with `sessions --harness codex --days 3 --force` (or a requested hours/count selection). Keep that initial target list fixed; new pending turns still use ordinary sync.
|
|
89
|
+
2. Re-review each target with `review --harness codex --session-ref <sessionRef> --days 3 --force --from-turn <fromTurn> --to-turn <toTurn> --supersedes-sync-id <supersedesSyncId>`. The original local turns must exist. Explicit backfill/count selections use `--all`.
|
|
90
|
+
3. Prepare and redact the payload again, keeping the exact session reference and turn range and adding its `supersedesSyncId`. Pipe it to `sync --harness codex --force`, following the saved manual/automatic approval policy.
|
|
77
91
|
|
|
78
|
-
|
|
92
|
+
A changed target is rejected so newer work cannot be overwritten accidentally. Re-discover and re-review before attempting that replacement again. Identical retries are safe. Existing conversations retain their context; start a new chat in Shifu to use the latest context.
|
package/bin/shifu-harness.js
CHANGED
|
@@ -25,7 +25,7 @@ const CREDENTIAL_ASSIGNMENT_PATTERN = /\b(?:token|secret|password|api[_-]?key)\s
|
|
|
25
25
|
const CLOUD_CREDENTIAL_PATTERN = /\bAKIA[0-9A-Z]{16}\b|AIza[0-9A-Za-z_-]{20,}/;
|
|
26
26
|
const EVIDENCE_KINDS = new Set(["implementation", "decision", "activity"]);
|
|
27
27
|
const EVIDENCE_FIELDS = new Set(["kind", "title", "statement", "scope", "area", "itemRef", "verificationRefs"]);
|
|
28
|
-
const SYNC_FIELDS = new Set(["harness", "sessionRef", "fromTurn", "toTurn", "title", "summary", "evidence", "verification", "decisions", "redactionVersion"]);
|
|
28
|
+
const SYNC_FIELDS = new Set(["harness", "sessionRef", "fromTurn", "toTurn", "title", "summary", "evidence", "verification", "decisions", "redactionVersion", "supersedesSyncId"]);
|
|
29
29
|
const AI_PROFILE_FIELDS = new Set(["harness", "sessionRef", "fromTurn", "toTurn", "category", "model", "thinking", "evidence"]);
|
|
30
30
|
const AI_PROFILE_EVIDENCE_FIELDS = new Set(["dimension", "statement", "signal", "turn"]);
|
|
31
31
|
const AI_PROFILE_DIMENSIONS = new Set(["task_selection", "goal_clarity", "context_sharing", "constraint_setting", "work_decomposition", "iterative_steering", "critical_judgment", "verification", "application", "responsible_use"]);
|
|
@@ -39,7 +39,7 @@ const MAX_TURNS_PER_SEGMENT = 12;
|
|
|
39
39
|
const MAX_TITLE_LENGTH = 160;
|
|
40
40
|
const MAX_WORK_DETAIL_LENGTH = 600;
|
|
41
41
|
const CONFIG_VERSION = 2;
|
|
42
|
-
const RUNNER_VERSION = "0.3.
|
|
42
|
+
const RUNNER_VERSION = "0.3.11";
|
|
43
43
|
const REDACTION_VERSION = 4;
|
|
44
44
|
const DEFAULT_INTERVAL_HOURS = 1;
|
|
45
45
|
const LEGACY_INTERVAL_HOURS = 4;
|
|
@@ -178,6 +178,43 @@ function hasFlag(name) {
|
|
|
178
178
|
return process.argv.includes(name);
|
|
179
179
|
}
|
|
180
180
|
|
|
181
|
+
function validateSyncOptions(command, start = 3) {
|
|
182
|
+
const common = ["--harness", "--config-root"];
|
|
183
|
+
const options = {
|
|
184
|
+
sessions: [...common, "--hours", "--days", "--count", "--turns", "--session-ref"],
|
|
185
|
+
review: [...common, "--hours", "--days", "--turns", "--session-ref", "--from-turn", "--to-turn", "--supersedes-sync-id"],
|
|
186
|
+
sync: common,
|
|
187
|
+
"sync-files": common,
|
|
188
|
+
"scheduled-sync": common,
|
|
189
|
+
pending: common,
|
|
190
|
+
approve: common,
|
|
191
|
+
};
|
|
192
|
+
const flags = {
|
|
193
|
+
sessions: ["--all", "--force"], review: ["--all", "--force"], sync: ["--approved", "--force"], approve: ["--approved"],
|
|
194
|
+
};
|
|
195
|
+
if (!options[command]) return;
|
|
196
|
+
const seen = new Set();
|
|
197
|
+
for (let index = start; index < process.argv.length; index += 1) {
|
|
198
|
+
const argument = process.argv[index];
|
|
199
|
+
if (seen.has(argument)) throw new Error(`Provide ${argument} only once.`);
|
|
200
|
+
seen.add(argument);
|
|
201
|
+
if ((flags[command] || []).includes(argument)) continue;
|
|
202
|
+
if (!options[command].includes(argument)) throw new Error(`Unsupported option ${argument} for ${command}.`);
|
|
203
|
+
const value = process.argv[++index];
|
|
204
|
+
if (value === undefined || value.startsWith("--")) throw new Error(`Provide a value for ${argument}.`);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
function syncWindowHours() {
|
|
209
|
+
if (hasFlag("--days") && hasFlag("--hours")) throw new Error("Use either --days or --hours, not both.");
|
|
210
|
+
const name = hasFlag("--days") ? "--days" : "--hours";
|
|
211
|
+
const value = numberOption(name, 24);
|
|
212
|
+
if (!Number.isSafeInteger(value) || value < 1) throw new Error(`Choose a positive whole number for ${name}.`);
|
|
213
|
+
const hours = name === "--days" ? value * 24 : value;
|
|
214
|
+
if (!Number.isSafeInteger(hours) || hours * 3_600_000 > 8_640_000_000_000_000) throw new Error("The requested sync window is too large.");
|
|
215
|
+
return hours;
|
|
216
|
+
}
|
|
217
|
+
|
|
181
218
|
function readJSON(file, fallback) {
|
|
182
219
|
try {
|
|
183
220
|
return JSON.parse(fs.readFileSync(file, "utf8"));
|
|
@@ -892,7 +929,7 @@ function validateGeneratedProfile(profile, harness) {
|
|
|
892
929
|
}
|
|
893
930
|
|
|
894
931
|
function selectedSessionSegments(harness, { hours = 24, turns = MAX_TURNS_PER_SEGMENT, selectedRef, includeOlder = false, count } = {}) {
|
|
895
|
-
if (count === undefined && !
|
|
932
|
+
if (count === undefined && (!Number.isSafeInteger(hours) || hours < 1)) throw new Error("Choose a positive whole number for --hours.");
|
|
896
933
|
if (count !== undefined && (!Number.isSafeInteger(count) || count < 1)) throw new Error("Choose a positive whole number for --count.");
|
|
897
934
|
if (!Number.isInteger(turns) || turns < 1 || turns > MAX_TURNS_PER_SEGMENT) throw new Error("Choose --turns between 1 and 12.");
|
|
898
935
|
const since = Date.now() - hours * 3_600_000;
|
|
@@ -1292,6 +1329,7 @@ function sessionRefIsSafe(value) {
|
|
|
1292
1329
|
function validateSync(input, harness) {
|
|
1293
1330
|
if (!input || Object.keys(input).some((field) => !SYNC_FIELDS.has(field))) throw new Error("Remove unsupported fields from the reviewed sync payload.");
|
|
1294
1331
|
if (!input || input.harness !== harness || !sessionRefIsSafe(input.sessionRef)) throw new Error("Add the current opaque sessionRef before syncing.");
|
|
1332
|
+
if (Object.hasOwn(input, "supersedesSyncId") && (!Number.isSafeInteger(input.supersedesSyncId) || input.supersedesSyncId < 1)) throw new Error("Use the positive supersedesSyncId returned by force discovery.");
|
|
1295
1333
|
if (!Number.isInteger(input.fromTurn) || !Number.isInteger(input.toTurn) || input.fromTurn < 1 || input.toTurn < input.fromTurn || input.toTurn > 1_000_000 || input.toTurn - input.fromTurn >= MAX_TURNS_PER_SEGMENT) throw new Error("Use a valid incremental range of at most 12 turns.");
|
|
1296
1334
|
if (input.redactionVersion >= 3 && !textIsSafe(input.title, MAX_TITLE_LENGTH)) throw new Error("Add a concise, redacted title for this reviewed sync.");
|
|
1297
1335
|
if (!textIsSafe(input.summary, 1200)) throw new Error("The summary is empty, too long, or contains sensitive content. Redact it before syncing.");
|
|
@@ -1335,8 +1373,8 @@ function validateAIProfileObservation(input, harness) {
|
|
|
1335
1373
|
}
|
|
1336
1374
|
|
|
1337
1375
|
function validSyncReceipt(receipt, input) {
|
|
1338
|
-
return receipt?.sessionRef === input.sessionRef && receipt.acceptedToTurn === input.toTurn && Number.isInteger(receipt.lastSyncedTurn) &&
|
|
1339
|
-
(receipt.duplicate ? receipt.lastSyncedTurn >= input.toTurn : receipt.lastSyncedTurn === input.toTurn);
|
|
1376
|
+
return receipt?.sessionRef === input.sessionRef && receipt.acceptedToTurn === input.toTurn && Number.isInteger(receipt.lastSyncedTurn) && receipt.lastSyncedTurn <= 1_000_000 &&
|
|
1377
|
+
(receipt.duplicate || input.supersedesSyncId ? receipt.lastSyncedTurn >= input.toTurn : receipt.lastSyncedTurn === input.toTurn);
|
|
1340
1378
|
}
|
|
1341
1379
|
|
|
1342
1380
|
function sleep(milliseconds) {
|
|
@@ -1582,18 +1620,21 @@ async function sendSync(harness, input, config = readConfig(harness)) {
|
|
|
1582
1620
|
const state = readState(harness);
|
|
1583
1621
|
const checkpoint = state.sessions[input.sessionRef];
|
|
1584
1622
|
const expected = (checkpoint?.lastSyncedTurn || 0) + 1;
|
|
1585
|
-
if (input.fromTurn !== expected) throw new Error(`This local checkpoint expects turn ${expected}. Review the pending segment before retrying.`);
|
|
1586
|
-
|
|
1623
|
+
if (!input.supersedesSyncId && input.fromTurn !== expected) throw new Error(`This local checkpoint expects turn ${expected}. Review the pending segment before retrying.`);
|
|
1624
|
+
if (input.supersedesSyncId && reviewSegment(harness, input.sessionRef, input.fromTurn, input.toTurn).turnCount < input.toTurn) throw new Error("The original local turns must still exist before replacing this sync.");
|
|
1625
|
+
const profile = input.supersedesSyncId ? undefined : profileForSegment(harness, input);
|
|
1587
1626
|
const receipt = await postSync(config, input);
|
|
1588
1627
|
if (!validSyncReceipt(receipt, input)) {
|
|
1589
1628
|
throw new Error("Shifu returned a checkpoint that does not match this reviewed segment. Local state was not advanced.");
|
|
1590
1629
|
}
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1630
|
+
if (profile) {
|
|
1631
|
+
state.profilePending ||= {};
|
|
1632
|
+
state.profilePending[`${profile.sessionRef}:${profile.fromTurn}:${profile.toTurn}`] = profile;
|
|
1633
|
+
}
|
|
1634
|
+
state.sessions[input.sessionRef] = { turnsSinceSync: 0, lastSyncedAt: Date.now(), lastSyncedTurn: Math.max(checkpoint?.lastSyncedTurn || 0, receipt.lastSyncedTurn), syncDue: false };
|
|
1594
1635
|
saveState(harness, state);
|
|
1595
|
-
await flushPendingProfiles(harness, config);
|
|
1596
|
-
console.error(receipt.duplicate ? "Shifu already had this exact segment. Local checkpoint recovered." : `Synced through turn ${receipt.lastSyncedTurn}.`);
|
|
1636
|
+
if (profile) await flushPendingProfiles(harness, config);
|
|
1637
|
+
console.error(receipt.duplicate ? "Shifu already had this exact segment. Local checkpoint recovered." : input.supersedesSyncId ? `Replaced the reviewed sync for turns ${input.fromTurn}–${input.toTurn}.` : `Synced through turn ${receipt.lastSyncedTurn}.`);
|
|
1597
1638
|
return receipt;
|
|
1598
1639
|
}
|
|
1599
1640
|
|
|
@@ -1631,6 +1672,7 @@ async function sync(harness) {
|
|
|
1631
1672
|
const config = readConfig(harness);
|
|
1632
1673
|
const input = readJSON(0, undefined);
|
|
1633
1674
|
validateSync(input, harness);
|
|
1675
|
+
if (hasFlag("--force") !== Boolean(input.supersedesSyncId)) throw new Error("Force replacement requires both --force and the reviewed payload's supersedesSyncId. Use ordinary sync for new segments.");
|
|
1634
1676
|
const policy = normalizedPolicy(config);
|
|
1635
1677
|
if (policy.approvalMode === "manual" && !hasFlag("--approved")) {
|
|
1636
1678
|
console.error(`\nThis exact redacted segment will be sent to Shifu:\n${JSON.stringify(input, null, 2)}`);
|
|
@@ -1836,23 +1878,75 @@ async function syncFilesNow(harness) {
|
|
|
1836
1878
|
if (result.failures) throw new Error("Some input files need retry. They will be checked on the next sync.");
|
|
1837
1879
|
}
|
|
1838
1880
|
|
|
1839
|
-
function
|
|
1840
|
-
|
|
1881
|
+
async function acceptedSegments(config, sessionRef) {
|
|
1882
|
+
const segments = [];
|
|
1883
|
+
let cursor = 0;
|
|
1884
|
+
do {
|
|
1885
|
+
const url = new URL(`${config.apiUrl}/v1/connectors/coding-sessions/syncs`);
|
|
1886
|
+
url.searchParams.set("sessionRef", sessionRef);
|
|
1887
|
+
if (cursor) url.searchParams.set("cursor", String(cursor));
|
|
1888
|
+
const response = await fetch(url, { headers: { Authorization: `Bearer ${config.token}` }, signal: AbortSignal.timeout(30_000) });
|
|
1889
|
+
const payload = await response.json().catch(() => undefined);
|
|
1890
|
+
if (!response.ok) throw new Error(payload?.error?.message || `Could not inspect accepted sync segments (${response.status}).`);
|
|
1891
|
+
const page = payload?.data;
|
|
1892
|
+
if (!Array.isArray(page?.segments) || page.segments.length > 100 || page.segments.some((segment, index) =>
|
|
1893
|
+
!Number.isSafeInteger(segment.id) || segment.id < 1 || segment.sessionRef !== sessionRef ||
|
|
1894
|
+
!Number.isInteger(segment.fromTurn) || !Number.isInteger(segment.toTurn) || segment.fromTurn < 1 ||
|
|
1895
|
+
segment.toTurn < segment.fromTurn || segment.toTurn - segment.fromTurn >= MAX_TURNS_PER_SEGMENT ||
|
|
1896
|
+
segment.toTurn > 1_000_000 || segment.fromTurn <= (index ? page.segments[index - 1].toTurn : cursor))) {
|
|
1897
|
+
throw new Error("Shifu returned invalid accepted sync segments. No replacement was sent.");
|
|
1898
|
+
}
|
|
1899
|
+
segments.push(...page.segments);
|
|
1900
|
+
const next = page.nextCursor;
|
|
1901
|
+
if (next === undefined || next === null || next === "") return segments;
|
|
1902
|
+
const nextTurn = Number(next);
|
|
1903
|
+
if (typeof next !== "string" || !/^[1-9]\d*$/.test(next) || !Number.isInteger(nextTurn) || nextTurn <= cursor || nextTurn !== page.segments.at(-1)?.toTurn) throw new Error("Shifu returned an invalid sync-segment cursor.");
|
|
1904
|
+
cursor = nextTurn;
|
|
1905
|
+
} while (cursor < 1_000_000);
|
|
1906
|
+
throw new Error("Shifu returned an invalid sync-segment cursor.");
|
|
1907
|
+
}
|
|
1908
|
+
|
|
1909
|
+
async function sessions(harness) {
|
|
1910
|
+
const config = readConfig(harness);
|
|
1841
1911
|
const count = option("--count");
|
|
1842
1912
|
if (hasFlag("--count") && count === undefined) throw new Error("Provide a value for --count.");
|
|
1843
|
-
if (count !== undefined &&
|
|
1844
|
-
const hours =
|
|
1913
|
+
if (count !== undefined && (hasFlag("--hours") || hasFlag("--days"))) throw new Error("Use --count without --hours or --days.");
|
|
1914
|
+
const hours = syncWindowHours();
|
|
1845
1915
|
const turns = numberOption("--turns", MAX_TURNS_PER_SEGMENT);
|
|
1846
1916
|
const sessionRef = option("--session-ref");
|
|
1847
1917
|
const all = hasFlag("--all");
|
|
1848
1918
|
if (count !== undefined && (sessionRef || all)) throw new Error("Use --count without --session-ref or --all.");
|
|
1849
1919
|
if (all && !sessionRef) throw new Error("Use --all only with an explicitly selected --session-ref.");
|
|
1850
1920
|
const countValue = count === undefined ? undefined : Number(count);
|
|
1921
|
+
if (hasFlag("--force")) {
|
|
1922
|
+
if (hasFlag("--turns")) throw new Error("Force replacement uses the original stored ranges; do not provide --turns.");
|
|
1923
|
+
const selected = selectedSessionSegments(harness, { hours, selectedRef: sessionRef, includeOlder: true, count: countValue });
|
|
1924
|
+
const replacements = [];
|
|
1925
|
+
const unavailable = [];
|
|
1926
|
+
const since = Date.now() - hours * 3_600_000;
|
|
1927
|
+
const metadataByRef = new Map();
|
|
1928
|
+
for (const metadata of localSessions(harness)) {
|
|
1929
|
+
if (metadata.turnCount >= (metadataByRef.get(metadata.sessionRef)?.turnCount || 0)) metadataByRef.set(metadata.sessionRef, metadata);
|
|
1930
|
+
}
|
|
1931
|
+
for (const session of selected) {
|
|
1932
|
+
const metadata = metadataByRef.get(session.sessionRef);
|
|
1933
|
+
for (const segment of await acceptedSegments(config, session.sessionRef)) {
|
|
1934
|
+
if (segment.toTurn > session.turnCount) {
|
|
1935
|
+
unavailable.push({ sessionRef: session.sessionRef, supersedesSyncId: segment.id, reason: "local_turns_missing" });
|
|
1936
|
+
continue;
|
|
1937
|
+
}
|
|
1938
|
+
if (!all && count === undefined && !(Date.parse(metadata.turnTimes[segment.fromTurn - 1]) >= since)) continue;
|
|
1939
|
+
replacements.push({ sessionRef: session.sessionRef, fromTurn: segment.fromTurn, toTurn: segment.toTurn, supersedesSyncId: segment.id });
|
|
1940
|
+
}
|
|
1941
|
+
}
|
|
1942
|
+
console.log(JSON.stringify({ harness, ...(count === undefined ? { hours } : { count: countValue, selectedSessionRefs: selected.map((item) => item.sessionRef) }), force: true, sessions: replacements, unavailableSegments: unavailable }, null, 2));
|
|
1943
|
+
return;
|
|
1944
|
+
}
|
|
1851
1945
|
const selected = selectedSessionSegments(harness, { hours, turns, selectedRef: sessionRef, includeOlder: all, count: countValue });
|
|
1852
1946
|
const pending = selected.filter((session) => session.fromTurn <= session.toTurn);
|
|
1853
1947
|
const blocked = all || count !== undefined ? [] : unsyncedCodexSessions(harness, { hours, turns, selectedRef: sessionRef, includeOlder: true })
|
|
1854
1948
|
.filter((session) => !pending.some((item) => item.sessionRef === session.sessionRef))
|
|
1855
|
-
.map(({ sessionRef, oldestUnsyncedAt }) => ({ sessionRef, oldestUnsyncedAt }));
|
|
1949
|
+
.map(({ sessionRef, oldestUnsyncedAt }) => ({ sessionRef, oldestUnsyncedAt, reason: "older_unsynced_turns", nextStep: "Select this session explicitly with --session-ref and --all to backfill in order." }));
|
|
1856
1950
|
console.log(JSON.stringify(count === undefined
|
|
1857
1951
|
? { harness, hours, turns, sessions: pending, blockedSessions: blocked }
|
|
1858
1952
|
: {
|
|
@@ -1864,32 +1958,43 @@ function sessions(harness) {
|
|
|
1864
1958
|
}, null, 2));
|
|
1865
1959
|
}
|
|
1866
1960
|
|
|
1867
|
-
function review(harness) {
|
|
1868
|
-
readConfig(harness);
|
|
1961
|
+
async function review(harness) {
|
|
1962
|
+
const config = readConfig(harness);
|
|
1869
1963
|
const sessionRef = option("--session-ref");
|
|
1870
1964
|
if (typeof sessionRef !== "string" || sessionRef.length < 8) throw new Error(`Provide an opaque ${HARNESS_NAMES[harness]} --session-ref from the sessions command.`);
|
|
1871
1965
|
const state = readState(harness);
|
|
1872
|
-
|
|
1966
|
+
let fromTurn = (state.sessions[sessionRef]?.lastSyncedTurn || 0) + 1;
|
|
1873
1967
|
const selected = localSessions(harness).filter((session) => session.sessionRef === sessionRef)
|
|
1874
1968
|
.sort((left, right) => right.turnCount - left.turnCount || right.updatedAt.localeCompare(left.updatedAt))[0];
|
|
1875
1969
|
if (!selected) throw new Error(`No local ${HARNESS_NAMES[harness]} session matches this reference.`);
|
|
1876
|
-
const hours =
|
|
1877
|
-
if (![24, 48, 72].includes(hours)) throw new Error("Choose --hours 24, 48, or 72.");
|
|
1878
|
-
if (!hasFlag("--all") && !(Date.parse(selected.turnTimes[fromTurn - 1]) >= Date.now() - hours * 3_600_000)) {
|
|
1879
|
-
throw new Error("This session's next unsynced turn predates the selected window. Ask for this specific session and use --all to review its backlog.");
|
|
1880
|
-
}
|
|
1970
|
+
const hours = syncWindowHours();
|
|
1881
1971
|
const turns = numberOption("--turns", MAX_TURNS_PER_SEGMENT);
|
|
1882
1972
|
if (!Number.isInteger(turns) || turns < 1 || turns > MAX_TURNS_PER_SEGMENT) throw new Error("Choose --turns between 1 and 12.");
|
|
1883
|
-
|
|
1973
|
+
let toTurn = Math.min(selected.turnCount, fromTurn + turns - 1);
|
|
1974
|
+
let supersedesSyncId;
|
|
1975
|
+
if (hasFlag("--force")) {
|
|
1976
|
+
if (hasFlag("--turns")) throw new Error("Force review uses the original stored range; do not provide --turns.");
|
|
1977
|
+
fromTurn = numberOption("--from-turn");
|
|
1978
|
+
toTurn = numberOption("--to-turn");
|
|
1979
|
+
supersedesSyncId = numberOption("--supersedes-sync-id");
|
|
1980
|
+
const target = (await acceptedSegments(config, sessionRef)).find((segment) => segment.id === supersedesSyncId && segment.fromTurn === fromTurn && segment.toTurn === toTurn);
|
|
1981
|
+
if (!target || toTurn > selected.turnCount) throw new Error("Use the exact current segment and supersedesSyncId from sessions --force; the original local turns must still exist.");
|
|
1982
|
+
} else if (["--from-turn", "--to-turn", "--supersedes-sync-id"].some(hasFlag)) {
|
|
1983
|
+
throw new Error("Explicit replacement boundaries require --force.");
|
|
1984
|
+
}
|
|
1884
1985
|
if (fromTurn > toTurn) throw new Error(`This ${HARNESS_NAMES[harness]} session has no unsynced turns to review.`);
|
|
1986
|
+
if (!hasFlag("--all") && !(Date.parse(selected.turnTimes[fromTurn - 1]) >= Date.now() - hours * 3_600_000)) {
|
|
1987
|
+
throw new Error("This session's selected turn predates the selected window. Ask for this specific session and use --all to review its backlog.");
|
|
1988
|
+
}
|
|
1885
1989
|
const { notes } = reviewSegment(harness, sessionRef, fromTurn, toTurn);
|
|
1886
1990
|
const candidates = reviewCandidates(notes);
|
|
1887
1991
|
console.log(JSON.stringify({
|
|
1888
1992
|
sessionRef,
|
|
1889
1993
|
fromTurn,
|
|
1890
1994
|
toTurn,
|
|
1995
|
+
...(supersedesSyncId ? { supersedesSyncId } : {}),
|
|
1891
1996
|
oldestUnsyncedAt: selected.turnTimes[fromTurn - 1] || null,
|
|
1892
|
-
source: "Local assistant final notes for
|
|
1997
|
+
source: "Local assistant final notes for the selected user turns. Candidates are suggestions, not verified or guaranteed redacted; inspect them before constructing a Shifu payload.",
|
|
1893
1998
|
notes,
|
|
1894
1999
|
candidates,
|
|
1895
2000
|
draft: { title: null, summary: null, evidence: candidates.map((candidate) => ({ ...candidate, title: null })) },
|
|
@@ -1935,6 +2040,7 @@ async function main() {
|
|
|
1935
2040
|
if (option("--config-root")) process.env.SHIFU_CONFIG_ROOT = path.resolve(option("--config-root"));
|
|
1936
2041
|
const command = process.argv[2];
|
|
1937
2042
|
const subCommand = process.argv[3];
|
|
2043
|
+
validateSyncOptions(command === "discover" || command === "session" ? "sessions" : command, command === "session" && ["discover", "list"].includes(subCommand) ? 4 : 3);
|
|
1938
2044
|
const harness = requireHarness(option("--harness"));
|
|
1939
2045
|
if (["sync", "sync-files", "scheduled-sync", "approve"].includes(command) && process.env.SHIFU_UPDATE_CHECKED !== "1" && await updateRecommendedPackage(harness)) {
|
|
1940
2046
|
const child = spawn(process.execPath, [installedRunnerPath(), ...process.argv.slice(2)], {
|
package/commands/shifu-sync.md
CHANGED
|
@@ -12,11 +12,13 @@ If manual approval has queued scheduled work, run `pending --harness opencode`,
|
|
|
12
12
|
|
|
13
13
|
For an explicit sync-now request:
|
|
14
14
|
|
|
15
|
-
1. For a time-window request, run `sessions --harness opencode --hours 24`, using
|
|
16
|
-
2. Review each returned segment with `review --harness opencode --session-ref <sessionRef> --hours <hours>`. For count-based selection, use `review --harness opencode --session-ref <sessionRef> --all` so older sessions are allowed.
|
|
15
|
+
1. For a time-window request, run `sessions --harness opencode --hours 24`, using the positive whole number of hours requested. A day request uses `--days N`; `--days 3` and `--hours 72` are identical. Never combine the two flags. For a request by number of recent sessions, run `sessions --harness opencode --count <count>`; this ignores the hours window and returns the most recently updated sessions first.
|
|
16
|
+
2. Report `blockedSessions` when older unsynced turns prevent the requested window from syncing; user-selected backfill uses `--session-ref <sessionRef> --all` and keeps chronological 12-turn segments. Review each returned segment with `review --harness opencode --session-ref <sessionRef> --hours <hours>`. Use the same hours or days value for discovery and review. For count-based selection, use `review --harness opencode --session-ref <sessionRef> --all` so older sessions are allowed.
|
|
17
17
|
3. Prepare a redaction-version-four payload from final assistant notes only. Use `activity` evidence for writing, feedback, research, planning, product work, and any work that is not clearly an engineering implementation or decision. Activity evidence has no technical scope. Preserve the supported action, feature or project purpose, specific problem, approach, technologies and design patterns used, and verified result. Synthesize a descriptive project label (such as "payment reconciliation service") from its purpose; never copy a raw label that could identify a company or person. Keep distinct contributions separate, including different fixes within one feature. An empty evidence list advances the checkpoint without creating a claim.
|
|
18
18
|
4. In automatic mode, pipe the payload to `sync --harness opencode` without asking again. In manual mode, show the exact payload, ask once, and then use `sync --approved --harness opencode`.
|
|
19
19
|
5. Keep the returned session reference and turn range unchanged. Never upload prompts, raw transcripts, tool output, code, paths, commands, URLs, credentials, company or person names, customer details, or proprietary identifiers.
|
|
20
20
|
6. For a count-based sync, keep `selectedSessionRefs` from the first discovery and review only pending `sessions`. `skippedSessions` reports already-synced selections; do not replace them with older sessions. If one has remaining turns, request its next segment with `sessions --harness opencode --session-ref <sessionRef> --all`. Stop after those selected sessions are exhausted. Report completed, already-synced, and failed/pending sessions separately. Manual sync runs immediately, independently of the hourly schedule.
|
|
21
21
|
|
|
22
22
|
To connect or replace a key, run `npx --yes @useshifu/coding-harness connect --harness opencode`. Connect asks for a key with a normal visible terminal prompt and verifies it with Shifu before reporting success. Do not ask the user to paste the key into chat. If this tool terminal cannot run the command or accept input, ask the user to run it in their own interactive terminal and report the output; do not claim the connection succeeded. To disconnect locally, run `npx --yes @useshifu/coding-harness disconnect --harness opencode`. New connections use one-hour automatic sync and `~/Desktop/Shifu` on macOS by default. To change the interval, approval policy, or folder later, run `config update --harness opencode` with the desired flags (for example, `--input-folder <existing-readable-folder>`).
|
|
23
|
+
|
|
24
|
+
For an explicit user force-sync request, use `sessions --harness opencode --force` with the requested window/count. Keep its initial targets fixed. Each accepted segment includes `supersedesSyncId` and exact original boundaries. Re-review with `review --harness opencode --session-ref <sessionRef> --force --from-turn <fromTurn> --to-turn <toTurn> --supersedes-sync-id <supersedesSyncId>` using the same window or explicit `--all`. Redact the final notes again and add the returned `supersedesSyncId` to the prepared payload; send with `sync --harness opencode --force`, following the saved approval policy. New pending turns use ordinary sync. Never guess boundaries, replace a changed target, or force scheduled/file sync. Checkpoints and history are preserved; identical retries are safe. Work replacements leave AI Profile observations unchanged. Start a new chat in Shifu to use the latest work context.
|
package/package.json
CHANGED
|
@@ -55,11 +55,11 @@ Show the returned list and ask for one approval for the whole list. After approv
|
|
|
55
55
|
|
|
56
56
|
## Sync now
|
|
57
57
|
|
|
58
|
-
For an explicit sync request, first read `status` to determine the saved approval mode. Manual sync runs immediately and does not wait for the hourly schedule. Use the time window the user names; otherwise use 24 hours.
|
|
58
|
+
For an explicit sync request, first read `status` to determine the saved approval mode. Manual sync runs immediately and does not wait for the hourly schedule. Use the time window the user names; otherwise use 24 hours. Use `--days N` for a positive whole number of days or `--hours N` for a positive whole number of hours. Days use exactly the same selection and review rules as hours (`--days 3` equals `--hours 72`). Never combine them or silently substitute the default window. If the user specifies a number of recent sessions, use count-based selection instead; it has no hours cutoff and orders sessions from latest to earliest. It selects the latest eligible sessions, excluding current/setup sessions, and reports already-synced selections in `skippedSessions` without replacing them with older sessions.
|
|
59
59
|
|
|
60
|
-
1. For a time-window sync, run `npx --yes @useshifu/coding-harness sessions --harness codex --hours <
|
|
61
|
-
2.
|
|
62
|
-
3. For each returned segment, run `npx --yes @useshifu/coding-harness review --harness codex --session-ref <sessionRef> --hours <
|
|
60
|
+
1. For a time-window sync, run `npx --yes @useshifu/coding-harness sessions --harness codex --hours <hours>`. For a count-based sync, run `npx --yes @useshifu/coding-harness sessions --harness codex --count <count>`; do not add `--hours` or `--days`.
|
|
61
|
+
2. Report `blockedSessions` honestly: these recently active sessions have older unsynced turns and cannot skip ahead. Explain that explicit backfill is needed. For a user-selected older backlog, add `--session-ref <sessionRef> --all`; process its original turns chronologically in segments of at most 12.
|
|
62
|
+
3. For each returned segment, run `npx --yes @useshifu/coding-harness review --harness codex --session-ref <sessionRef> --hours <hours>`. Use the same `--days` or `--hours` value for discovery and review. For count-based selection, use `--all` so the review has no time cutoff.
|
|
63
63
|
4. Prepare a version-four payload from the returned final-assistant notes. Keep the returned `sessionRef`, `fromTurn`, and `toTurn` unchanged.
|
|
64
64
|
5. In automatic mode, send it without another approval. In manual mode, show the exact payload and ask once; after approval, pass `--approved` to the sync command.
|
|
65
65
|
6. For a time-window sync, repeat discovery after accepted segments until the selected window is exhausted. For a count-based sync, keep `selectedSessionRefs` from the first discovery and review only pending `sessions`. If a selected session has remaining turns, request its next segment with `sessions --harness codex --session-ref <sessionRef> --all`; stop after those selected sessions are exhausted. Report completed, already-synced, and failed/pending sessions separately. A failed session does not count as completed.
|
|
@@ -96,3 +96,11 @@ printf '%s' '<redacted JSON>' | npx --yes @useshifu/coding-harness sync --approv
|
|
|
96
96
|
```
|
|
97
97
|
|
|
98
98
|
If a transport or server error remains after the runner's retries, report that the checkpoint was not advanced. Do not alter the segment or skip ahead.
|
|
99
|
+
|
|
100
|
+
## Explicit force replacement
|
|
101
|
+
|
|
102
|
+
Only when the user explicitly asks to force-sync or replace previously synced work, add `--force` to `sessions` with their requested window or count. It returns current server segments with `supersedesSyncId` and their original `fromTurn`/`toTurn`; never guess replacement ranges from local checkpoints. Force discovery lists accepted segments only. New pending turns still use ordinary sync. Keep the initial returned targets fixed rather than repeating force discovery after each replacement.
|
|
103
|
+
|
|
104
|
+
Re-review each returned target with `review --harness codex --session-ref <sessionRef> --force --from-turn <fromTurn> --to-turn <toTurn> --supersedes-sync-id <supersedesSyncId>` and the same window (or `--all` for explicitly selected backfill/count selection). The original local turns must still exist. Inspect and redact the final notes again, preserving supported work detail. Add that exact `supersedesSyncId` to the prepared payload and send with `sync --harness codex --force` (plus `--approved` only after manual approval). Preserve the original reference and turn range. If another replacement already changed the target, stop and re-discover/re-review; do not silently force over newer work.
|
|
105
|
+
|
|
106
|
+
Force replacement preserves sync history and never lowers checkpoints. Identical retries are safe. It replaces work evidence and claims for that segment; existing AI Profile observations stay unchanged. Do not add force to scheduled sync, approval queues, or file sync. Existing conversations keep their context; start a new chat in Shifu to use the latest work context.
|