diff --git a/packages/cli/src/commands/kill.js b/packages/cli/src/commands/kill.js index 1de03a9781..a47dc6fbaf 100644 --- a/packages/cli/src/commands/kill.js +++ b/packages/cli/src/commands/kill.js @@ -2,8 +2,9 @@ import os from 'os'; import { E } from '@endo/far'; import { withEndoParty } from '../context.js'; +import { parsePetNamePath } from '../pet-name.js'; export const killCommand = async ({ name, partyNames }) => withEndoParty(partyNames, { os, process }, async ({ party }) => { - await E(party).terminate(name); + await E(party).terminate(parsePetNamePath(name)); }); diff --git a/packages/daemon/src/mail.js b/packages/daemon/src/mail.js index e21ba71730..00cad19772 100644 --- a/packages/daemon/src/mail.js +++ b/packages/daemon/src/mail.js @@ -4,7 +4,7 @@ import { E } from '@endo/far'; import { makePromiseKit } from '@endo/promise-kit'; import { makeChangeTopic } from './pubsub.js'; import { makeIteratorRef } from './reader-ref.js'; -import { assertPetName } from './pet-name.js'; +import { assertPetName, petNamePathFrom } from './pet-name.js'; const { quote: q } = assert; @@ -60,11 +60,32 @@ export const makeMailboxMaker = ({ ); }; - const terminate = async petName => { - const formulaIdentifier = lookupFormulaIdentifierForName(petName); - if (formulaIdentifier === undefined) { - throw new TypeError(`Unknown pet name: ${q(petName)}`); + /** + * @param {string | string[]} petNameOrPath - A pet name or a sequence of pet names. + * @returns {Promise} A promise that resolves when the name is terminated. + */ + const terminate = async petNameOrPath => { + const petNamePath = petNamePathFrom(petNameOrPath); + console.log(`trace:terminate1: ${petNamePath.join(', ')}`); + + let formulaIdentifier; + if (petNamePath.length === 1) { + formulaIdentifier = lookupFormulaIdentifierForName(petNamePath[0]); + if (formulaIdentifier === undefined) { + throw new TypeError(`Unknown pet name: ${q(petNamePath[0])}`); + } + } else { + // eslint-disable-next-line no-use-before-define + const { value } = await provideLookupFormula(petNamePath); + // eslint-disable-next-line no-use-before-define + [formulaIdentifier] = await reverseLookup(value); + if (formulaIdentifier === undefined) { + throw new TypeError( + `Value at ${q(petNamePath.join(', '))} cannot be terminated.`, + ); + } } + // Behold, recursion: // eslint-disable-next-line no-use-before-define const controller = await provideControllerForFormulaIdentifier(