@cotal-ai/cli 0.182.0 → 0.183.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/command.d.ts.map +1 -1
- package/dist/command.js +347 -179
- package/dist/command.js.map +1 -1
- package/dist/commands/agents.d.ts.map +1 -1
- package/dist/commands/agents.js +70 -14
- package/dist/commands/agents.js.map +1 -1
- package/dist/commands/app-identity.d.ts +1 -0
- package/dist/commands/app-identity.d.ts.map +1 -1
- package/dist/commands/app-identity.js +1 -1
- package/dist/commands/app-identity.js.map +1 -1
- package/dist/commands/backup-maintenance.d.ts.map +1 -1
- package/dist/commands/backup-maintenance.js +9 -7
- package/dist/commands/backup-maintenance.js.map +1 -1
- package/dist/commands/backup.d.ts.map +1 -1
- package/dist/commands/backup.js +51 -23
- package/dist/commands/backup.js.map +1 -1
- package/dist/commands/clean.d.ts.map +1 -1
- package/dist/commands/clean.js +8 -2
- package/dist/commands/clean.js.map +1 -1
- package/dist/commands/down.d.ts.map +1 -1
- package/dist/commands/down.js +12 -3
- package/dist/commands/down.js.map +1 -1
- package/dist/commands/ext.d.ts +4 -2
- package/dist/commands/ext.d.ts.map +1 -1
- package/dist/commands/ext.js +62 -15
- package/dist/commands/ext.js.map +1 -1
- package/dist/commands/help.js +1 -1
- package/dist/commands/help.js.map +1 -1
- package/dist/commands/history.d.ts.map +1 -1
- package/dist/commands/history.js +5 -1
- package/dist/commands/history.js.map +1 -1
- package/dist/commands/join.js +1 -1
- package/dist/commands/join.js.map +1 -1
- package/dist/commands/meshes.d.ts.map +1 -1
- package/dist/commands/meshes.js +2 -1
- package/dist/commands/meshes.js.map +1 -1
- package/dist/commands/mint.js +27 -26
- package/dist/commands/mint.js.map +1 -1
- package/dist/commands/persona.d.ts +2 -2
- package/dist/commands/persona.d.ts.map +1 -1
- package/dist/commands/persona.js +4 -3
- package/dist/commands/persona.js.map +1 -1
- package/dist/commands/send.d.ts.map +1 -1
- package/dist/commands/send.js +9 -7
- package/dist/commands/send.js.map +1 -1
- package/dist/commands/service-registry.d.ts +1 -1
- package/dist/commands/service-registry.js +1 -1
- package/dist/commands/service-registry.js.map +1 -1
- package/dist/commands/setup-current-connectors.d.ts +7 -0
- package/dist/commands/setup-current-connectors.d.ts.map +1 -0
- package/dist/commands/setup-current-connectors.js +31 -0
- package/dist/commands/setup-current-connectors.js.map +1 -0
- package/dist/commands/setup.d.ts +1 -0
- package/dist/commands/setup.d.ts.map +1 -1
- package/dist/commands/setup.js +43 -14
- package/dist/commands/setup.js.map +1 -1
- package/dist/commands/space-registration.d.ts.map +1 -1
- package/dist/commands/space-registration.js +6 -1
- package/dist/commands/space-registration.js.map +1 -1
- package/dist/commands/spawn-flags.d.ts +1 -1
- package/dist/commands/spawn-flags.d.ts.map +1 -1
- package/dist/commands/spawn-flags.js +11 -3
- package/dist/commands/spawn-flags.js.map +1 -1
- package/dist/commands/spawn-managed-launch.d.ts.map +1 -1
- package/dist/commands/spawn-managed-launch.js +3 -2
- package/dist/commands/spawn-managed-launch.js.map +1 -1
- package/dist/commands/spawn-preview.d.ts.map +1 -1
- package/dist/commands/spawn-preview.js +21 -4
- package/dist/commands/spawn-preview.js.map +1 -1
- package/dist/commands/spawn.d.ts +2 -15
- package/dist/commands/spawn.d.ts.map +1 -1
- package/dist/commands/spawn.js +117 -120
- package/dist/commands/spawn.js.map +1 -1
- package/dist/commands/stack-down.d.ts.map +1 -1
- package/dist/commands/stack-down.js +24 -12
- package/dist/commands/stack-down.js.map +1 -1
- package/dist/commands/stack-lost-records.d.ts +12 -0
- package/dist/commands/stack-lost-records.d.ts.map +1 -1
- package/dist/commands/stack-lost-records.js +31 -10
- package/dist/commands/stack-lost-records.js.map +1 -1
- package/dist/commands/stack-up.d.ts +1 -1
- package/dist/commands/stack-up.d.ts.map +1 -1
- package/dist/commands/stack-up.js +22 -10
- package/dist/commands/stack-up.js.map +1 -1
- package/dist/commands/stack-user-auth.d.ts +2 -2
- package/dist/commands/stack-user-auth.d.ts.map +1 -1
- package/dist/commands/stack-user-auth.js +6 -3
- package/dist/commands/stack-user-auth.js.map +1 -1
- package/dist/commands/status-health.d.ts +4 -1
- package/dist/commands/status-health.d.ts.map +1 -1
- package/dist/commands/status-health.js +4 -1
- package/dist/commands/status-health.js.map +1 -1
- package/dist/commands/status-meshes.d.ts +4 -1
- package/dist/commands/status-meshes.d.ts.map +1 -1
- package/dist/commands/status-meshes.js +8 -3
- package/dist/commands/status-meshes.js.map +1 -1
- package/dist/commands/status.d.ts.map +1 -1
- package/dist/commands/status.js +16 -11
- package/dist/commands/status.js.map +1 -1
- package/dist/commands/sync.d.ts.map +1 -1
- package/dist/commands/sync.js +2 -2
- package/dist/commands/sync.js.map +1 -1
- package/dist/commands/team-boot-controller.d.ts.map +1 -1
- package/dist/commands/team-boot-controller.js +2 -1
- package/dist/commands/team-boot-controller.js.map +1 -1
- package/dist/commands/team.js +6 -6
- package/dist/commands/team.js.map +1 -1
- package/dist/commands/topology.d.ts.map +1 -1
- package/dist/commands/topology.js +3 -2
- package/dist/commands/topology.js.map +1 -1
- package/dist/commands/trust.d.ts +27 -0
- package/dist/commands/trust.d.ts.map +1 -0
- package/dist/commands/trust.js +39 -0
- package/dist/commands/trust.js.map +1 -0
- package/dist/commands/up-detach.d.ts.map +1 -1
- package/dist/commands/up-detach.js +5 -1
- package/dist/commands/up-detach.js.map +1 -1
- package/dist/commands/up-foreground-listener.d.ts +20 -0
- package/dist/commands/up-foreground-listener.d.ts.map +1 -0
- package/dist/commands/up-foreground-listener.js +156 -0
- package/dist/commands/up-foreground-listener.js.map +1 -0
- package/dist/commands/up-manifest.d.ts.map +1 -1
- package/dist/commands/up-manifest.js +4 -5
- package/dist/commands/up-manifest.js.map +1 -1
- package/dist/commands/up-project-trust.d.ts +8 -0
- package/dist/commands/up-project-trust.d.ts.map +1 -0
- package/dist/commands/up-project-trust.js +35 -0
- package/dist/commands/up-project-trust.js.map +1 -0
- package/dist/commands/up-resume.d.ts +1 -1
- package/dist/commands/up-resume.d.ts.map +1 -1
- package/dist/commands/up-resume.js +12 -5
- package/dist/commands/up-resume.js.map +1 -1
- package/dist/commands/up.d.ts.map +1 -1
- package/dist/commands/up.js +30 -150
- package/dist/commands/up.js.map +1 -1
- package/dist/commands/update-continuity.d.ts +4 -0
- package/dist/commands/update-continuity.d.ts.map +1 -1
- package/dist/commands/update-continuity.js +54 -1
- package/dist/commands/update-continuity.js.map +1 -1
- package/dist/commands/update-offline.d.ts +4 -0
- package/dist/commands/update-offline.d.ts.map +1 -0
- package/dist/commands/update-offline.js +39 -0
- package/dist/commands/update-offline.js.map +1 -0
- package/dist/commands/update-process.d.ts.map +1 -1
- package/dist/commands/update-process.js +11 -8
- package/dist/commands/update-process.js.map +1 -1
- package/dist/commands/update.d.ts.map +1 -1
- package/dist/commands/update.js +24 -67
- package/dist/commands/update.js.map +1 -1
- package/dist/console/app.d.ts.map +1 -1
- package/dist/console/app.js +2 -1
- package/dist/console/app.js.map +1 -1
- package/dist/console/mesh.d.ts +1 -1
- package/dist/console/mesh.d.ts.map +1 -1
- package/dist/console/mesh.js +1 -1
- package/dist/console/mesh.js.map +1 -1
- package/dist/console/ui/CommandPalette.d.ts +2 -1
- package/dist/console/ui/CommandPalette.d.ts.map +1 -1
- package/dist/console/ui/CommandPalette.js +4 -4
- package/dist/console/ui/CommandPalette.js.map +1 -1
- package/dist/help.d.ts +1 -6
- package/dist/help.d.ts.map +1 -1
- package/dist/help.js +26 -4
- package/dist/help.js.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +20 -4
- package/dist/index.js.map +1 -1
- package/dist/lib/app-user-identity.d.ts +10 -13
- package/dist/lib/app-user-identity.d.ts.map +1 -1
- package/dist/lib/app-user-identity.js +237 -59
- package/dist/lib/app-user-identity.js.map +1 -1
- package/dist/lib/choose-target.d.ts.map +1 -1
- package/dist/lib/choose-target.js +1 -0
- package/dist/lib/choose-target.js.map +1 -1
- package/dist/lib/command-path.d.ts +6 -0
- package/dist/lib/command-path.d.ts.map +1 -1
- package/dist/lib/command-path.js +3 -0
- package/dist/lib/command-path.js.map +1 -1
- package/dist/lib/completion-scripts.d.ts.map +1 -1
- package/dist/lib/completion-scripts.js +1 -1
- package/dist/lib/completion-scripts.js.map +1 -1
- package/dist/lib/conversation-identity.d.ts +2 -1
- package/dist/lib/conversation-identity.d.ts.map +1 -1
- package/dist/lib/conversation-identity.js +1 -1
- package/dist/lib/conversation-identity.js.map +1 -1
- package/dist/lib/conversation-resume.d.ts +30 -0
- package/dist/lib/conversation-resume.d.ts.map +1 -0
- package/dist/lib/conversation-resume.js +73 -0
- package/dist/lib/conversation-resume.js.map +1 -0
- package/dist/lib/endpoint-errors.d.ts.map +1 -1
- package/dist/lib/endpoint-errors.js +17 -2
- package/dist/lib/endpoint-errors.js.map +1 -1
- package/dist/lib/extension-core-peer.d.ts +2 -0
- package/dist/lib/extension-core-peer.d.ts.map +1 -0
- package/dist/lib/extension-core-peer.js +23 -0
- package/dist/lib/extension-core-peer.js.map +1 -0
- package/dist/lib/extension-stage.d.ts +1 -1
- package/dist/lib/extension-stage.d.ts.map +1 -1
- package/dist/lib/extension-stage.js +20 -8
- package/dist/lib/extension-stage.js.map +1 -1
- package/dist/lib/foreground-hold.d.ts +2 -2
- package/dist/lib/foreground-hold.d.ts.map +1 -1
- package/dist/lib/foreground-hold.js +31 -9
- package/dist/lib/foreground-hold.js.map +1 -1
- package/dist/lib/hermes-windows-host.d.ts +8 -0
- package/dist/lib/hermes-windows-host.d.ts.map +1 -0
- package/dist/lib/hermes-windows-host.js +85 -0
- package/dist/lib/hermes-windows-host.js.map +1 -0
- package/dist/lib/hermes-windows-preload.d.ts +2 -0
- package/dist/lib/hermes-windows-preload.d.ts.map +1 -0
- package/dist/lib/hermes-windows-preload.js +7 -0
- package/dist/lib/hermes-windows-preload.js.map +1 -0
- package/dist/lib/history-command.d.ts +2 -1
- package/dist/lib/history-command.d.ts.map +1 -1
- package/dist/lib/history-command.js +4 -2
- package/dist/lib/history-command.js.map +1 -1
- package/dist/lib/isolated-broker.d.ts.map +1 -1
- package/dist/lib/isolated-broker.js +80 -31
- package/dist/lib/isolated-broker.js.map +1 -1
- package/dist/lib/leading-flags.d.ts +1 -0
- package/dist/lib/leading-flags.d.ts.map +1 -1
- package/dist/lib/leading-flags.js +13 -2
- package/dist/lib/leading-flags.js.map +1 -1
- package/dist/lib/manifest/index.d.ts +1 -1
- package/dist/lib/manifest/index.d.ts.map +1 -1
- package/dist/lib/manifest/index.js +3 -3
- package/dist/lib/manifest/index.js.map +1 -1
- package/dist/lib/manifest/preflight.d.ts +1 -1
- package/dist/lib/manifest/preflight.d.ts.map +1 -1
- package/dist/lib/manifest/preflight.js +14 -4
- package/dist/lib/manifest/preflight.js.map +1 -1
- package/dist/lib/npm-invocation.d.ts +13 -9
- package/dist/lib/npm-invocation.d.ts.map +1 -1
- package/dist/lib/npm-invocation.js +66 -17
- package/dist/lib/npm-invocation.js.map +1 -1
- package/dist/lib/paths.d.ts +1 -1
- package/dist/lib/paths.d.ts.map +1 -1
- package/dist/lib/paths.js +3 -3
- package/dist/lib/paths.js.map +1 -1
- package/dist/lib/persona-files.d.ts.map +1 -1
- package/dist/lib/persona-files.js +17 -1
- package/dist/lib/persona-files.js.map +1 -1
- package/dist/lib/personas.d.ts +3 -4
- package/dist/lib/personas.d.ts.map +1 -1
- package/dist/lib/personas.js +6 -5
- package/dist/lib/personas.js.map +1 -1
- package/dist/lib/restore.d.ts +6 -2
- package/dist/lib/restore.d.ts.map +1 -1
- package/dist/lib/restore.js +29 -15
- package/dist/lib/restore.js.map +1 -1
- package/dist/lib/self-exec.d.ts +4 -2
- package/dist/lib/self-exec.d.ts.map +1 -1
- package/dist/lib/self-exec.js +9 -4
- package/dist/lib/self-exec.js.map +1 -1
- package/dist/lib/service-process.d.ts.map +1 -1
- package/dist/lib/service-process.js +12 -3
- package/dist/lib/service-process.js.map +1 -1
- package/dist/lib/service-start-options.d.ts +1 -0
- package/dist/lib/service-start-options.d.ts.map +1 -1
- package/dist/lib/service-start-options.js +3 -0
- package/dist/lib/service-start-options.js.map +1 -1
- package/dist/lib/stack-journal.d.ts +2 -2
- package/dist/lib/stack-journal.d.ts.map +1 -1
- package/dist/lib/stack-journal.js +22 -8
- package/dist/lib/stack-journal.js.map +1 -1
- package/dist/lib/stdout-owner.d.ts +5 -0
- package/dist/lib/stdout-owner.d.ts.map +1 -1
- package/dist/lib/stdout-owner.js +33 -1
- package/dist/lib/stdout-owner.js.map +1 -1
- package/dist/lib/team-deploy-inspection.js +1 -1
- package/dist/lib/team-deploy-inspection.js.map +1 -1
- package/dist/lib/update-connector-config.d.ts +4 -1
- package/dist/lib/update-connector-config.d.ts.map +1 -1
- package/dist/lib/update-connector-config.js +32 -4
- package/dist/lib/update-connector-config.js.map +1 -1
- package/dist/lib/update-manager-install-linux.d.ts +8 -0
- package/dist/lib/update-manager-install-linux.d.ts.map +1 -0
- package/dist/lib/update-manager-install-linux.js +128 -0
- package/dist/lib/update-manager-install-linux.js.map +1 -0
- package/dist/lib/update-managers.d.ts.map +1 -1
- package/dist/lib/update-managers.js +2 -1
- package/dist/lib/update-managers.js.map +1 -1
- package/dist/lib/update-pending.d.ts +1 -1
- package/dist/lib/update-pending.d.ts.map +1 -1
- package/dist/lib/update-pending.js +1 -1
- package/dist/lib/update-pending.js.map +1 -1
- package/dist/lib/version.js +3 -3
- package/dist/lib/version.js.map +1 -1
- package/dist/seed/reconcile.js +1 -1
- package/dist/seed/reconcile.js.map +1 -1
- package/dist/seed/store.d.ts +3 -7
- package/dist/seed/store.d.ts.map +1 -1
- package/dist/seed/store.js +83 -15
- package/dist/seed/store.js.map +1 -1
- package/dist/seed/verify.d.ts +2 -2
- package/dist/seed/verify.d.ts.map +1 -1
- package/dist/seed/verify.js +8 -4
- package/dist/seed/verify.js.map +1 -1
- package/package.json +5 -4
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type ConversationApprovalRefusal, type ConversationGrant, type ConversationPending, type ConversationSelection } from "@cotal-ai/core";
|
|
2
|
-
import { type MeshTarget } from "@cotal-ai/workspace";
|
|
2
|
+
import { type ConversationSignOut, type MeshTarget } from "@cotal-ai/workspace";
|
|
3
3
|
/** The authority recorded that nothing was issued for this request, and the saved request is gone.
|
|
4
4
|
* `decision` says why in a form a host can act on: the person's denial, the approval's expiry, or
|
|
5
5
|
* a refusal of the proposed selection. */
|
|
@@ -7,12 +7,7 @@ export declare class ConversationRefusal extends Error {
|
|
|
7
7
|
readonly decision: ConversationApprovalRefusal | "refused";
|
|
8
8
|
constructor(decision: ConversationApprovalRefusal | "refused", message: string);
|
|
9
9
|
}
|
|
10
|
-
|
|
11
|
-
* failures, but the saved request and secret remain available for exact recovery. */
|
|
12
|
-
export declare class ConversationRequestError extends Error {
|
|
13
|
-
readonly retryable: boolean;
|
|
14
|
-
constructor(message: string, retryable: boolean);
|
|
15
|
-
}
|
|
10
|
+
export { ConversationRequestError } from "./conversation-resume.js";
|
|
16
11
|
/** A connected conversation identity: its environment, where to retire it, and its exact grant. */
|
|
17
12
|
export interface UserAppConnection {
|
|
18
13
|
env: Record<string, string>;
|
|
@@ -21,18 +16,20 @@ export interface UserAppConnection {
|
|
|
21
16
|
};
|
|
22
17
|
grant: ConversationGrant;
|
|
23
18
|
}
|
|
19
|
+
type UserAppResult = UserAppConnection | {
|
|
20
|
+
pending: ConversationPending;
|
|
21
|
+
reason?: string;
|
|
22
|
+
};
|
|
24
23
|
/** The session key is supplied by the native host, not guessed from a parent pid or an open inbox.
|
|
25
24
|
* A new request waits for a person's approval: until it is decided this returns `pending`, and
|
|
26
25
|
* connecting again replays the same saved request and secret. */
|
|
27
|
-
export declare function provisionUserApp(target: MeshTarget, name: string, session: string | undefined, events: boolean, selection?: ConversationSelection): Promise<
|
|
28
|
-
pending: ConversationPending;
|
|
29
|
-
}>;
|
|
26
|
+
export declare function provisionUserApp(target: MeshTarget, name: string, session: string | undefined, events: boolean, selection?: ConversationSelection): Promise<UserAppResult>;
|
|
30
27
|
export declare function isUserAppDir(dir: string): boolean;
|
|
31
28
|
/** Retain the record and secret until exact cleanup is observed, or preserve an older record
|
|
32
29
|
* separately when its original registration is no longer available. */
|
|
33
30
|
export declare function retireUserApp(dir: string): Promise<void>;
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
*
|
|
31
|
+
export declare const conversationSignOut: ConversationSignOut;
|
|
32
|
+
/** Clean up dead consumers in this mesh. Resumable approvals stay saved unless retirement is
|
|
33
|
+
* underway. A live or unknown consumer keeps its identity and is never locked. */
|
|
37
34
|
export declare function retireDeadUserApps(target: MeshTarget): Promise<void>;
|
|
38
35
|
//# sourceMappingURL=app-user-identity.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"app-user-identity.d.ts","sourceRoot":"","sources":["../../src/lib/app-user-identity.ts"],"names":[],"mappings":"AAGA,OAAO,EAI6B,KAAK,2BAA2B,EAAE,KAAK,iBAAiB,EAAE,KAAK,mBAAmB,EAAE,KAAK,qBAAqB,EACjJ,MAAM,gBAAgB,CAAC;AACxB,OAAO,
|
|
1
|
+
{"version":3,"file":"app-user-identity.d.ts","sourceRoot":"","sources":["../../src/lib/app-user-identity.ts"],"names":[],"mappings":"AAGA,OAAO,EAI6B,KAAK,2BAA2B,EAAE,KAAK,iBAAiB,EAAE,KAAK,mBAAmB,EAAE,KAAK,qBAAqB,EACjJ,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAuM,KAAK,mBAAmB,EAAE,KAAK,UAAU,EAAgC,MAAM,qBAAqB,CAAC;AAoHnT;;2CAE2C;AAC3C,qBAAa,mBAAoB,SAAQ,KAAK;IAChC,QAAQ,CAAC,QAAQ,EAAE,2BAA2B,GAAG,SAAS;gBAAjD,QAAQ,EAAE,2BAA2B,GAAG,SAAS,EAAE,OAAO,EAAE,MAAM;CAIxF;AAED,OAAO,EAAE,wBAAwB,EAAE,MAAM,0BAA0B,CAAC;AAkDpE,mGAAmG;AACnG,MAAM,WAAW,iBAAiB;IAChC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC5B,MAAM,EAAE;QAAE,GAAG,EAAE,MAAM,CAAA;KAAE,CAAC;IACxB,KAAK,EAAE,iBAAiB,CAAC;CAC1B;AAED,KAAK,aAAa,GAAG,iBAAiB,GAAG;IAAE,OAAO,EAAE,mBAAmB,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AAY3F;;kEAEkE;AAClE,wBAAsB,gBAAgB,CACpC,MAAM,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,SAAS,CAAC,EAAE,qBAAqB,GAChH,OAAO,CAAC,aAAa,CAAC,CAuBxB;AAyOD,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAEjD;AAED;wEACwE;AACxE,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAExD;AAOD,eAAO,MAAM,mBAAmB,EAAE,mBA0BjC,CAAC;AAWF;mFACmF;AACnF,wBAAsB,kBAAkB,CAAC,MAAM,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC,CAU1E"}
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { createHash, randomBytes } from "node:crypto";
|
|
2
2
|
import { closeSync, existsSync, fsyncSync, lstatSync, openSync, readFileSync, readdirSync, renameSync, rmdirSync, unlinkSync } from "node:fs";
|
|
3
3
|
import { basename, dirname, join, resolve } from "node:path";
|
|
4
|
-
import { acquireLock, assertLifecycleToken, canonicalJson, checkConversationApprovalPending, checkConversationPendingAnswer, checkConversationSelection, conversationApprovalRefusal, conversationGrant, deprovisionAgent, mintCreds, mkSecretDir, newIdentity, principalKey, provisionAgentDurables, processStartToken, resolveAuthProvider, writeSecretFileAtomic, } from "@cotal-ai/core";
|
|
5
|
-
import { checkDiscoveryDocument, discoveryDocumentUrl, pinnedFetch, getSpaceAuth, homeCotalDir, resolveTargetOrThrow, userAuthStateDir, workspaceSecretStore } from "@cotal-ai/workspace";
|
|
4
|
+
import { acquireLock, assertLifecycleToken, canonicalJson, checkConversationApprovalPending, checkConversationPendingAnswer, checkConversationSelection, conversationApprovalRefusal, conversationGrant, deprovisionAgent, mintCreds, mkSecretDir, newIdentity, principalKey, provisionAgentDurables, processStartToken, registry, resolveAuthProvider, writeSecretFileAtomic, } from "@cotal-ai/core";
|
|
5
|
+
import { checkDiscoveryDocument, checkIdpUrl, discoveryDocumentUrl, pinnedFetch, getSpaceAuth, homeCotalDir, oneLine, resolveTargetOrThrow, userAuthStateDir, workspaceSecretStore } from "@cotal-ai/workspace";
|
|
6
|
+
import { CONVERSATION_RESUME_PREFIX } from "@cotal-ai/workspace/conversation-resume";
|
|
6
7
|
import { agentCapRefusal, checkConversationMaterial, conversationRetirementPhase, discoverConversationAuthority, legacyAgentCapRefusal, legacyNameTakenRefusal, nameTakenRefusal, selectionRefusal, signedInSpace, } from "./conversation-identity.js";
|
|
7
8
|
import { withProvisioner } from "./provisioner.js";
|
|
9
|
+
import { confirmConversationResume, ConversationRequestError, createResumeProof, matchesResumeBinding, resumeToken } from "./conversation-resume.js";
|
|
8
10
|
const RECORD = "identity.json";
|
|
9
11
|
const hash = (text) => createHash("sha256").update(text).digest("hex");
|
|
10
12
|
const identityRoot = () => join(homeCotalDir(), "app-identities");
|
|
@@ -40,12 +42,16 @@ function read(dir) {
|
|
|
40
42
|
const record = JSON.parse(readFileSync(file, "utf8"));
|
|
41
43
|
if (record.v !== 1 || typeof record.space !== "string" || typeof record.root !== "string" ||
|
|
42
44
|
typeof record.session !== "string" || !/^[A-Za-z0-9_-]{22,64}$/.test(record.requestId) ||
|
|
43
|
-
|
|
45
|
+
!(record.proof ? /^[a-f0-9]{64}$/ : /^[A-Za-z0-9_-]{43}$/).test(record.token) || !["creating", "ready", "retiring"].includes(record.state) ||
|
|
44
46
|
!record.consumer || !Number.isInteger(record.consumer.pid) || record.consumer.pid <= 0 ||
|
|
45
47
|
Boolean(record.remote) === Boolean(record.local))
|
|
46
48
|
throw new Error("conversation identity recovery record is invalid; it was retained");
|
|
47
49
|
if (record.retirementTarget && Object.keys(record.retirementTarget).some((key) => !["space", "root", "server", "tlsRequired", "userAuth"].includes(key)))
|
|
48
50
|
throw new Error("conversation retirement pins contain unexpected fields; recovery state was retained");
|
|
51
|
+
if (record.proof && !record.remote)
|
|
52
|
+
throw new Error("conversation resume proof does not name a signed-in identity");
|
|
53
|
+
if (record.accountKey !== undefined && (typeof record.accountKey !== "string" || !/^[a-f0-9]{64}$/.test(record.accountKey)))
|
|
54
|
+
throw new Error("conversation approval account is invalid; the saved record was retained");
|
|
49
55
|
if (record.selection !== undefined)
|
|
50
56
|
checkConversationSelection(record.selection);
|
|
51
57
|
const pending = record.remote?.approval?.pending;
|
|
@@ -67,7 +73,7 @@ function consumerGone(consumer) {
|
|
|
67
73
|
}
|
|
68
74
|
/** The creation body. A replay sends the same one, so its digest names the same request. */
|
|
69
75
|
function creationBody(record) {
|
|
70
|
-
return { v: 1, requestId: record.requestId, tokenHash: hash(record.token), label: record.label,
|
|
76
|
+
return { v: 1, requestId: record.requestId, tokenHash: record.proof ? record.token : hash(record.token), label: record.label,
|
|
71
77
|
...(record.selection ? { selection: record.selection } : {}) };
|
|
72
78
|
}
|
|
73
79
|
/** An issued answer must carry the person's decision on the approval the request saw. Only the exact
|
|
@@ -96,16 +102,7 @@ export class ConversationRefusal extends Error {
|
|
|
96
102
|
this.name = "ConversationRefusal";
|
|
97
103
|
}
|
|
98
104
|
}
|
|
99
|
-
|
|
100
|
-
* failures, but the saved request and secret remain available for exact recovery. */
|
|
101
|
-
export class ConversationRequestError extends Error {
|
|
102
|
-
retryable;
|
|
103
|
-
constructor(message, retryable) {
|
|
104
|
-
super(message);
|
|
105
|
-
this.retryable = retryable;
|
|
106
|
-
this.name = "ConversationRequestError";
|
|
107
|
-
}
|
|
108
|
-
}
|
|
105
|
+
export { ConversationRequestError } from "./conversation-resume.js";
|
|
109
106
|
/** What one creation answer proves. A selection refusal, a recorded denial, expiry or cap refusal,
|
|
110
107
|
* and a pending approval each prove that nothing was issued. Any other answer than an exact issued identity
|
|
111
108
|
* leaves the outcome unknown, so it throws and the request stays saved. */
|
|
@@ -143,6 +140,17 @@ function request(provider) {
|
|
|
143
140
|
throw new Error("the auth provider does not support conversation identity authority");
|
|
144
141
|
return provider.requestConversationIdentity.bind(provider);
|
|
145
142
|
}
|
|
143
|
+
function account(provider = resolveAuthProvider()) {
|
|
144
|
+
return registry.all("conversation-account").find((extension) => extension.name === provider.name);
|
|
145
|
+
}
|
|
146
|
+
function requestForRecord(provider, record) {
|
|
147
|
+
if (!record.accountKey)
|
|
148
|
+
return request(provider);
|
|
149
|
+
const binding = account(provider);
|
|
150
|
+
if (!binding)
|
|
151
|
+
throw new Error("the auth provider cannot check the saved approval's account; nothing was sent");
|
|
152
|
+
return (input) => binding.request(record.accountKey, input);
|
|
153
|
+
}
|
|
146
154
|
/** The refusal for an app that supplies no native session, such as Claude Desktop chat: it names
|
|
147
155
|
* the hosted connector the space advertises, the path such an app joins through. */
|
|
148
156
|
async function noNativeSession(target) {
|
|
@@ -172,6 +180,8 @@ export async function provisionUserApp(target, name, session, events, selection)
|
|
|
172
180
|
const previous = read(dir);
|
|
173
181
|
if (previous.session !== session || previous.space === target.space)
|
|
174
182
|
continue;
|
|
183
|
+
if (previous.proof && !matchesResumeBinding(previous, previous.proof))
|
|
184
|
+
continue;
|
|
175
185
|
if (previous.consumer.pid !== process.ppid && !consumerGone(previous.consumer))
|
|
176
186
|
throw new Error("this native conversation still has a live consumer on another space; disconnect it before choosing another");
|
|
177
187
|
// A pending request or a dead consumer must finish its exact retirement before a new target
|
|
@@ -187,7 +197,18 @@ export async function provisionUserApp(target, name, session, events, selection)
|
|
|
187
197
|
async function provisionOnSpace(target, name, session, events, selection) {
|
|
188
198
|
const store = workspaceSecretStore(target.root);
|
|
189
199
|
const infra = target.userAuth?.remote === true ? undefined : await getSpaceAuth(store, target.space);
|
|
190
|
-
const
|
|
200
|
+
const dir = join(identityRoot(), hash(`${target.space}\0${session}`));
|
|
201
|
+
const saved = existsSync(join(dir, RECORD)) ? read(dir) : undefined;
|
|
202
|
+
if (saved?.proof && saved.session === session && matchesResumeBinding(saved, saved.proof)) {
|
|
203
|
+
requireResumeLogin(saved);
|
|
204
|
+
if (saved.state === "ready" && saved.trust !== trust(target))
|
|
205
|
+
throw new Error(RESUME_UNAVAILABLE);
|
|
206
|
+
}
|
|
207
|
+
const authority = infra ? undefined : await discoverConversationAuthority(target).catch((error) => {
|
|
208
|
+
if (saved?.proof && saved.state === "ready")
|
|
209
|
+
throw new Error(`Conversation identity discovery did not confirm the saved authority. The saved identity was retained. ${oneLine(error.message)}`, { cause: error });
|
|
210
|
+
throw error;
|
|
211
|
+
});
|
|
191
212
|
const policy = authority?.bundle.policy ?? target.policy;
|
|
192
213
|
if (policy?.events === "required" && !events)
|
|
193
214
|
throw new Error("this mesh requires a real native conversation event source; no identity was requested");
|
|
@@ -199,20 +220,7 @@ async function provisionOnSpace(target, name, session, events, selection) {
|
|
|
199
220
|
const root = identityRoot();
|
|
200
221
|
mkSecretDir(root);
|
|
201
222
|
privateDir(root);
|
|
202
|
-
const
|
|
203
|
-
if (existsSync(join(dir, RECORD))) {
|
|
204
|
-
const previous = read(dir);
|
|
205
|
-
const changed = previous.label !== name || canonicalJson(previous.selection ?? null) !== canonicalJson(selection ?? null);
|
|
206
|
-
// Replacing an unissued request needs no approval of the unwanted name or permissions. Resolve
|
|
207
|
-
// the old request through its authority first: if approval raced us, retire that exact identity.
|
|
208
|
-
// The outer session lock keeps a watcher from recreating the old request during replacement.
|
|
209
|
-
if (changed && previous.state === "creating" && previous.remote && !previous.remote.material &&
|
|
210
|
-
previous.session === session && previous.trust === trust(target)) {
|
|
211
|
-
if (previous.consumer.pid !== process.ppid && !consumerGone(previous.consumer))
|
|
212
|
-
throw new Error("this native conversation still has a live inbox consumer; its pending request was not replaced");
|
|
213
|
-
await retireUserApp(dir);
|
|
214
|
-
}
|
|
215
|
-
}
|
|
223
|
+
const { reason, resumed } = await prepareSavedIdentity(dir, { name, session, trust: trust(target), selection }, authority);
|
|
216
224
|
// A reconnect first finishes the previous explicit departure, or preserves an older record
|
|
217
225
|
// whose original registration is unavailable before releasing its session key.
|
|
218
226
|
if (existsSync(join(dir, RECORD)) && read(dir).state === "retiring") {
|
|
@@ -259,20 +267,21 @@ async function provisionOnSpace(target, name, session, events, selection) {
|
|
|
259
267
|
consumer: { pid: process.ppid, start: processStartToken(process.ppid) }, ...(selection ? { selection } : {}),
|
|
260
268
|
remote: { url: authority.url, idpUrl: target.userAuth.idp.url, approval: {} },
|
|
261
269
|
};
|
|
270
|
+
attachResumeProof(record, authority, provider);
|
|
262
271
|
save(dir, record);
|
|
263
272
|
if (process.platform !== "win32") {
|
|
264
273
|
syncFile(root);
|
|
265
274
|
syncFile(dirname(root));
|
|
266
275
|
}
|
|
267
276
|
}
|
|
268
|
-
if (record.remote) {
|
|
277
|
+
if (record.remote && resumed !== record.requestId) {
|
|
269
278
|
if (!authority || record.remote.url !== authority.url || record.remote.idpUrl !== target.userAuth?.idp.url)
|
|
270
279
|
throw new Error("conversation identity authority changed; the saved identity was retained");
|
|
271
280
|
// Only an exact replay of an issued identity may go to an authority without approval.
|
|
272
281
|
if (!record.remote.material && !authority.approval)
|
|
273
282
|
throw new Error("the selected mesh does not advertise connection approval v1; the saved request was retained and not sent");
|
|
274
283
|
markUnderApproval(dir, record);
|
|
275
|
-
const response = await
|
|
284
|
+
const response = await requestForRecord(provider, record)({ url: authority.url, idpUrl: record.remote.idpUrl, method: "POST", body: creationBody(record) });
|
|
276
285
|
const outcome = creationOutcome(record, authority, response, "creation");
|
|
277
286
|
if ("refused" in outcome) {
|
|
278
287
|
discard(dir);
|
|
@@ -281,13 +290,13 @@ async function provisionOnSpace(target, name, session, events, selection) {
|
|
|
281
290
|
if ("pending" in outcome) {
|
|
282
291
|
record.remote.approval = { pending: outcome.pending.approval };
|
|
283
292
|
save(dir, record);
|
|
284
|
-
return { pending: outcome.pending };
|
|
293
|
+
return { pending: outcome.pending, ...(reason ? { reason } : {}) };
|
|
285
294
|
}
|
|
286
295
|
if (record.remote.material && JSON.stringify(record.remote.material) !== JSON.stringify(outcome.material))
|
|
287
296
|
throw new Error("conversation identity replay changed its saved lifecycle or grant");
|
|
288
297
|
record.remote.material = outcome.material;
|
|
289
298
|
}
|
|
290
|
-
else {
|
|
299
|
+
else if (!record.remote) {
|
|
291
300
|
// An identity granted here before connection approval resumes exactly. One without a
|
|
292
301
|
// confirmed grant is not issued now: no human approval exists on this path.
|
|
293
302
|
const local = record.local;
|
|
@@ -300,7 +309,7 @@ async function provisionOnSpace(target, name, session, events, selection) {
|
|
|
300
309
|
save(dir, record);
|
|
301
310
|
const material = record.remote?.material ?? record.local;
|
|
302
311
|
const grant = record.remote?.material?.grant ?? conversationGrant(record.local, record.selection);
|
|
303
|
-
writeSecretFileAtomic(join(dir, "actor.token"), record.token);
|
|
312
|
+
writeSecretFileAtomic(join(dir, "actor.token"), record.proof ? CONVERSATION_RESUME_PREFIX + JSON.stringify(record.proof) : record.token);
|
|
304
313
|
writeSecretFileAtomic(join(dir, "sentinel.creds"), material.sentinelCreds);
|
|
305
314
|
const bearer = [process.execPath, ...process.execArgv, process.argv[1], provider.agentBearerCommand,
|
|
306
315
|
...(record.remote ? ["--exchange-url", record.remote.material.exchangeUrl] : ["--dir", userAuthStateDir(target.root, target.space)]),
|
|
@@ -312,6 +321,7 @@ async function provisionOnSpace(target, name, session, events, selection) {
|
|
|
312
321
|
COTAL_SUBSCRIBE: "", COTAL_ALLOW_SUBSCRIBE: grant.allowSubscribe.join(","), COTAL_ALLOW_PUBLISH: grant.allowPublish.join(","),
|
|
313
322
|
...(grant.role ? { COTAL_ROLE: grant.role } : {}), ...(grant.scope.length ? { COTAL_CAPABILITIES: grant.scope.join(",") } : {}),
|
|
314
323
|
COTAL_WORKSPACE_ROOT: homeCotalDir(), ...(events ? { COTAL_EVENTS: "1" } : {}),
|
|
324
|
+
...(record.proof ? { COTAL_CONVERSATION_APPROVAL: resumed === record.requestId ? "resumed" : "resumable" } : {}),
|
|
315
325
|
...(policy?.events === "required" ? { COTAL_EVENTS_REQUIRED: "1" } : {}),
|
|
316
326
|
}, retire: { dir }, grant };
|
|
317
327
|
}
|
|
@@ -319,6 +329,127 @@ async function provisionOnSpace(target, name, session, events, selection) {
|
|
|
319
329
|
lock.release();
|
|
320
330
|
}
|
|
321
331
|
}
|
|
332
|
+
function attachResumeProof(record, authority, provider) {
|
|
333
|
+
if (!authority.resume)
|
|
334
|
+
return;
|
|
335
|
+
const binding = account(provider);
|
|
336
|
+
let accountKey;
|
|
337
|
+
try {
|
|
338
|
+
accountKey = binding?.key(record.remote.idpUrl);
|
|
339
|
+
}
|
|
340
|
+
catch {
|
|
341
|
+
return;
|
|
342
|
+
} // A legacy login without a subject still uses ordinary approval.
|
|
343
|
+
if (!accountKey)
|
|
344
|
+
return;
|
|
345
|
+
const resume = createResumeProof(record);
|
|
346
|
+
if (resume)
|
|
347
|
+
Object.assign(record, { accountKey, proof: resume.proof, token: resume.tokenHash });
|
|
348
|
+
}
|
|
349
|
+
async function prepareSavedIdentity(dir, expected, authority) {
|
|
350
|
+
if (!existsSync(join(dir, RECORD)))
|
|
351
|
+
return {};
|
|
352
|
+
const previous = read(dir);
|
|
353
|
+
if (previous.state === "retiring")
|
|
354
|
+
return {};
|
|
355
|
+
const changed = previous.label !== expected.name || canonicalJson(previous.selection ?? null) !== canonicalJson(expected.selection ?? null);
|
|
356
|
+
if (previous.proof) {
|
|
357
|
+
if (matchesResumeBinding(previous, previous.proof) && previous.trust !== expected.trust)
|
|
358
|
+
throw new Error(RESUME_UNAVAILABLE);
|
|
359
|
+
if (previous.consumer.pid !== process.ppid && !consumerGone(previous.consumer))
|
|
360
|
+
throw new Error("this native conversation still has a live inbox consumer; no identity was reissued");
|
|
361
|
+
if (previous.session !== expected.session || !matchesResumeBinding(previous, previous.proof)) {
|
|
362
|
+
const lock = acquireLock(`${dir}.lock`, { waitMs: 0 });
|
|
363
|
+
try {
|
|
364
|
+
const current = read(dir);
|
|
365
|
+
if (current.requestId !== previous.requestId || current.state === "retiring")
|
|
366
|
+
return {};
|
|
367
|
+
setAside(dir, current, `-${randomBytes(8).toString("hex")}`);
|
|
368
|
+
}
|
|
369
|
+
finally {
|
|
370
|
+
lock.release();
|
|
371
|
+
}
|
|
372
|
+
return { reason: "The saved approval could not be used on this computer." };
|
|
373
|
+
}
|
|
374
|
+
if (!previous.accountKey) {
|
|
375
|
+
await retireUserApp(dir);
|
|
376
|
+
return { reason: "The saved approval does not identify its approving account. Fresh approval is required." };
|
|
377
|
+
}
|
|
378
|
+
if (previous.state === "ready")
|
|
379
|
+
requireResumeAuthority(previous, authority);
|
|
380
|
+
if (!resumeToken({ ...previous, proof: previous.proof })) {
|
|
381
|
+
try {
|
|
382
|
+
await retireUserApp(dir);
|
|
383
|
+
}
|
|
384
|
+
catch (error) {
|
|
385
|
+
throw new Error(`The saved approval could not be used on this computer, and retirement is not confirmed. ${oneLine(error.message)}`);
|
|
386
|
+
}
|
|
387
|
+
return { reason: "The saved approval could not be used on this computer." };
|
|
388
|
+
}
|
|
389
|
+
if (previous.state === "ready") {
|
|
390
|
+
if (changed) {
|
|
391
|
+
await retireUserApp(dir);
|
|
392
|
+
return { reason: "The saved approval does not cover this name or selection." };
|
|
393
|
+
}
|
|
394
|
+
const lock = acquireLock(`${dir}.lock`, { waitMs: 0 });
|
|
395
|
+
try {
|
|
396
|
+
const current = read(dir);
|
|
397
|
+
if (current.state !== "ready" || current.requestId !== previous.requestId)
|
|
398
|
+
return {};
|
|
399
|
+
if (await resumeSavedIdentity(current, authority))
|
|
400
|
+
return { resumed: current.requestId };
|
|
401
|
+
current.state = "retiring";
|
|
402
|
+
save(dir, current);
|
|
403
|
+
}
|
|
404
|
+
finally {
|
|
405
|
+
lock.release();
|
|
406
|
+
}
|
|
407
|
+
await retireUserApp(dir);
|
|
408
|
+
return { reason: "The authority did not accept the saved approval." };
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
if (previous.session !== expected.session || previous.trust !== expected.trust)
|
|
412
|
+
return {};
|
|
413
|
+
// Resolve the old request before replacing it. If approval raced us, retire the exact identity.
|
|
414
|
+
if (changed && previous.state === "creating" && previous.remote && !previous.remote.material) {
|
|
415
|
+
if (previous.consumer.pid !== process.ppid && !consumerGone(previous.consumer))
|
|
416
|
+
throw new Error("this native conversation still has a live inbox consumer; its pending request was not replaced");
|
|
417
|
+
await retireUserApp(dir);
|
|
418
|
+
}
|
|
419
|
+
return {};
|
|
420
|
+
}
|
|
421
|
+
const RESUME_UNAVAILABLE = "The space does not currently offer resume at the saved authority and trust pins. The saved identity was retained.";
|
|
422
|
+
function requireResumeLogin(record) {
|
|
423
|
+
let key;
|
|
424
|
+
try {
|
|
425
|
+
const binding = account();
|
|
426
|
+
if (!binding)
|
|
427
|
+
throw new Error("login check unavailable");
|
|
428
|
+
key = binding.key(record.remote.idpUrl);
|
|
429
|
+
}
|
|
430
|
+
catch (error) {
|
|
431
|
+
throw new Error("Sign in again with `cotal login` before reconnecting this conversation. The saved identity was retained.", { cause: error });
|
|
432
|
+
}
|
|
433
|
+
if (record.accountKey && record.accountKey !== key)
|
|
434
|
+
throw new Error("This conversation was approved by another account. Sign in with the original account or connect a different conversation for fresh approval. The saved identity was retained.");
|
|
435
|
+
}
|
|
436
|
+
function requireResumeAuthority(record, authority) {
|
|
437
|
+
if (!authority?.resume || record.remote?.url !== authority.url || record.remote.idpUrl !== authority.bundle.userAuth.idp.url)
|
|
438
|
+
throw new Error(RESUME_UNAVAILABLE);
|
|
439
|
+
return authority;
|
|
440
|
+
}
|
|
441
|
+
async function resumeSavedIdentity(record, discovered) {
|
|
442
|
+
if (!record.accountKey)
|
|
443
|
+
throw new Error("The saved approval does not identify its approving account. Fresh approval is required.");
|
|
444
|
+
requireResumeLogin(record);
|
|
445
|
+
const authority = requireResumeAuthority(record, discovered);
|
|
446
|
+
const remote = record.remote;
|
|
447
|
+
if (!remote.material)
|
|
448
|
+
throw new Error("The saved approval has no issued identity. The saved record was retained.");
|
|
449
|
+
const material = checkConversationMaterial(remote.material, authority, record.requestId, record.selection, approvalExpectation(remote));
|
|
450
|
+
const token = record.proof && resumeToken({ ...record, proof: record.proof });
|
|
451
|
+
return !!token && !!material.approval && await confirmConversationResume(material, token);
|
|
452
|
+
}
|
|
322
453
|
/** Remove a creation record the authority refused before writing anything. */
|
|
323
454
|
function discard(dir) {
|
|
324
455
|
if (readdirSync(dir).some((name) => name !== RECORD))
|
|
@@ -336,14 +467,56 @@ export function isUserAppDir(dir) {
|
|
|
336
467
|
export function retireUserApp(dir) {
|
|
337
468
|
return retire(dir);
|
|
338
469
|
}
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
470
|
+
function idpKey(url) {
|
|
471
|
+
const checked = checkIdpUrl(url);
|
|
472
|
+
return checked.ok ? checked.url.origin + checked.url.pathname.replace(/\/+$/, "") : undefined;
|
|
473
|
+
}
|
|
474
|
+
export const conversationSignOut = {
|
|
475
|
+
kind: "conversation-sign-out", name: "native",
|
|
476
|
+
async retire({ dir: home, idp, accountKey }) {
|
|
477
|
+
const root = join(home, "app-identities");
|
|
478
|
+
if (!existsSync(root))
|
|
479
|
+
return [];
|
|
480
|
+
privateDir(root);
|
|
481
|
+
const failures = [];
|
|
482
|
+
for (const entry of readdirSync(root)) {
|
|
483
|
+
const dir = join(root, entry);
|
|
484
|
+
const setAside = isUnconfirmedDirectory(entry);
|
|
485
|
+
if ((!/^[a-f0-9]{64}$/.test(entry) && !setAside) || !existsSync(join(dir, RECORD)))
|
|
486
|
+
continue;
|
|
487
|
+
let failure = {};
|
|
488
|
+
try {
|
|
489
|
+
const matches = (r) => !!r.remote && idpKey(r.remote.idpUrl) === idp &&
|
|
490
|
+
(!r.accountKey || !accountKey || r.accountKey === accountKey) && (setAside ? matchesUnconfirmed(entry, r) : !!r.proof) &&
|
|
491
|
+
(!r.proof || matchesResumeBinding(r, r.proof));
|
|
492
|
+
const record = read(dir);
|
|
493
|
+
if (!matches(record))
|
|
494
|
+
continue;
|
|
495
|
+
failure = { label: oneLine(record.label), space: oneLine(record.space) };
|
|
496
|
+
await retire(dir, matches, home, true);
|
|
497
|
+
}
|
|
498
|
+
catch {
|
|
499
|
+
failures.push(failure);
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
return failures;
|
|
503
|
+
},
|
|
504
|
+
};
|
|
505
|
+
function isUnconfirmedDirectory(entry) {
|
|
506
|
+
return /^unconfirmed-[A-Za-z0-9_-]{22,81}$/.test(entry);
|
|
507
|
+
}
|
|
508
|
+
function matchesUnconfirmed(entry, record) {
|
|
509
|
+
const prefix = `unconfirmed-${record.requestId}`;
|
|
510
|
+
return record.state === "retiring" && (entry === prefix || (entry.startsWith(prefix) && /^-[a-f0-9]{16}$/.test(entry.slice(prefix.length))));
|
|
511
|
+
}
|
|
512
|
+
/** Clean up dead consumers in this mesh. Resumable approvals stay saved unless retirement is
|
|
513
|
+
* underway. A live or unknown consumer keeps its identity and is never locked. */
|
|
342
514
|
export async function retireDeadUserApps(target) {
|
|
343
515
|
const root = identityRoot();
|
|
344
516
|
if (!existsSync(root))
|
|
345
517
|
return;
|
|
346
|
-
const dead = (record) => record.trust === trust(target) && consumerGone(record.consumer)
|
|
518
|
+
const dead = (record) => record.trust === trust(target) && consumerGone(record.consumer) &&
|
|
519
|
+
!(record.proof && record.state === "ready");
|
|
347
520
|
for (const name of readdirSync(root)) {
|
|
348
521
|
const dir = join(root, name);
|
|
349
522
|
try {
|
|
@@ -354,24 +527,24 @@ export async function retireDeadUserApps(target) {
|
|
|
354
527
|
}
|
|
355
528
|
}
|
|
356
529
|
/** Preserve unconfirmed credentials without reserving the conversation's active session key. */
|
|
357
|
-
function setAside(dir, record) {
|
|
530
|
+
function setAside(dir, record, suffix = "") {
|
|
358
531
|
record.state = "retiring";
|
|
359
532
|
save(dir, record);
|
|
360
|
-
renameSync(dir, join(identityRoot(), `unconfirmed-${record.requestId}`));
|
|
533
|
+
renameSync(dir, join(identityRoot(), `unconfirmed-${record.requestId}${suffix}`));
|
|
361
534
|
if (process.platform !== "win32")
|
|
362
535
|
syncFile(identityRoot());
|
|
363
536
|
}
|
|
364
537
|
/** `when` is decided under the record's lock, so a consumer that reissued it in between keeps it. */
|
|
365
|
-
async function retire(dir, when) {
|
|
366
|
-
if (!
|
|
538
|
+
async function retire(dir, when, home = homeCotalDir(), signOut = false) {
|
|
539
|
+
if (dirname(resolve(dir)) !== resolve(home, "app-identities") || !(/^[a-f0-9]{64}$/.test(basename(dir)) || (signOut && isUnconfirmedDirectory(basename(dir)))))
|
|
367
540
|
throw new Error("not a saved conversation identity directory");
|
|
368
541
|
const lock = acquireLock(`${dir}.lock`, { waitMs: 0 });
|
|
369
542
|
try {
|
|
370
543
|
const record = read(dir);
|
|
371
544
|
if (when && !when(record))
|
|
372
545
|
return;
|
|
373
|
-
const current = await resolveTargetOrThrow({ space: record.space });
|
|
374
|
-
let target = record.retirementTarget
|
|
546
|
+
const current = signOut && record.retirementTarget ? undefined : await resolveTargetOrThrow({ space: record.space });
|
|
547
|
+
let target = record.retirementTarget ?? current;
|
|
375
548
|
if (!record.retirementTarget && record.remote?.material && trust(target) !== record.trust) {
|
|
376
549
|
try {
|
|
377
550
|
const address = new URL(record.remote.material.exchangeUrl);
|
|
@@ -380,8 +553,8 @@ async function retire(dir, when) {
|
|
|
380
553
|
const checked = await checkDiscoveryDocument(response);
|
|
381
554
|
if (checked.ok) {
|
|
382
555
|
const { space, server, tlsRequired, userAuth } = checked.value;
|
|
383
|
-
const original = { ...
|
|
384
|
-
userAuth: { ...
|
|
556
|
+
const original = { ...target, root: record.root, space, server, tlsRequired,
|
|
557
|
+
userAuth: { ...target.userAuth, ...userAuth } };
|
|
385
558
|
if (trust(original) === record.trust)
|
|
386
559
|
target = original;
|
|
387
560
|
}
|
|
@@ -392,6 +565,8 @@ async function retire(dir, when) {
|
|
|
392
565
|
if (record.retirementTarget && trust(target) !== record.trust)
|
|
393
566
|
throw new Error("conversation identity retirement pins do not match its saved trust; retirement was not sent");
|
|
394
567
|
if (trust(target) !== record.trust) {
|
|
568
|
+
if (signOut || record.proof)
|
|
569
|
+
throw new Error("the original conversation registration could not be confirmed");
|
|
395
570
|
// Older records could not recover matching original pins. Preserve their recovery state
|
|
396
571
|
// outside the active session key without authenticating at the replacement registration.
|
|
397
572
|
setAside(dir, record);
|
|
@@ -404,7 +579,7 @@ async function retire(dir, when) {
|
|
|
404
579
|
let unavailable = false;
|
|
405
580
|
const originalRequest = async (args) => {
|
|
406
581
|
try {
|
|
407
|
-
const response = await
|
|
582
|
+
const response = await requestForRecord(provider, record)(args);
|
|
408
583
|
if ([401, 403].includes(response.status))
|
|
409
584
|
unavailable = true;
|
|
410
585
|
return response;
|
|
@@ -454,7 +629,7 @@ async function retire(dir, when) {
|
|
|
454
629
|
throw new Error(`conversation identity retirement is pending at phase ${JSON.stringify(phase)}; its saved lifecycle was retained for an exact retry`);
|
|
455
630
|
}
|
|
456
631
|
catch (error) {
|
|
457
|
-
if (!unavailable || trust(current) === record.trust)
|
|
632
|
+
if (signOut || record.proof || !unavailable || !current || trust(current) === record.trust)
|
|
458
633
|
throw error;
|
|
459
634
|
setAside(dir, record);
|
|
460
635
|
return;
|
|
@@ -478,20 +653,23 @@ async function retire(dir, when) {
|
|
|
478
653
|
await deprovisionAgent({ servers: target.server, space: target.space, targetId: principalKey(local.owner, local.actor).key,
|
|
479
654
|
lifecycleUid: local.lifecycleUid, creds });
|
|
480
655
|
}
|
|
481
|
-
|
|
482
|
-
if (readdirSync(dir).some((name) => !files.includes(name)))
|
|
483
|
-
throw new Error("conversation identity directory contains unrecognized files; recovery state was retained");
|
|
484
|
-
for (const file of files) {
|
|
485
|
-
const path = join(dir, file);
|
|
486
|
-
if (existsSync(path))
|
|
487
|
-
unlinkSync(path);
|
|
488
|
-
}
|
|
489
|
-
rmdirSync(dir);
|
|
490
|
-
if (process.platform !== "win32")
|
|
491
|
-
syncFile(identityRoot());
|
|
656
|
+
removeSavedIdentity(dir);
|
|
492
657
|
}
|
|
493
658
|
finally {
|
|
494
659
|
lock.release();
|
|
495
660
|
}
|
|
496
661
|
}
|
|
662
|
+
function removeSavedIdentity(dir) {
|
|
663
|
+
const files = ["actor.token", "sentinel.creds", RECORD];
|
|
664
|
+
if (readdirSync(dir).some((name) => !files.includes(name)))
|
|
665
|
+
throw new Error("conversation identity directory contains unrecognized files; recovery state was retained");
|
|
666
|
+
for (const file of files) {
|
|
667
|
+
const path = join(dir, file);
|
|
668
|
+
if (existsSync(path))
|
|
669
|
+
unlinkSync(path);
|
|
670
|
+
}
|
|
671
|
+
rmdirSync(dir);
|
|
672
|
+
if (process.platform !== "win32")
|
|
673
|
+
syncFile(dirname(dir));
|
|
674
|
+
}
|
|
497
675
|
//# sourceMappingURL=app-user-identity.js.map
|