From within an Observable notebook (ie the code that you write), I don’t think there’s a way to access a “list” of cells that are in scope.
But the runtime itself does store that, since the runtime handles cell evaluation and the computation tree. If you had direct access to the “module” of a notebook, you could do something like:
const main = runtime.module();
main.variable().define("c", ["a", "b"], (a, b) => a + b);
console.log(Array.from(main._scope.keys())) // ["a", "b", "c"]
Here’s this in action.
But, you don’t have access to a notebook’s runtime from within the notebook itself. The autocomplete works in observablehq.com because the notebook editor has access to the runtime (I assume), but your code that you write does not. If you embed the notebook elsewhere, then you have more control, but not in the typical notebook at observablehq.com.
Overall I recommend How Observable Runs to learn more about how the runtime/notebook cells work!